[英]Google maps not working in release mode but working fine in debug mode
Google maps activity isn't working on release mode but working fine on Debug mode. Google Maps活动在发布模式下不起作用,但在调试模式下工作得很好。
Tried everything on stack overflow related to my query but its not working. 尝试了所有与我的查询相关的堆栈溢出问题,但无法正常工作。
I also copied SHA1 Key from cmd prompt using "keytool -list -v -keystore mystore.keystore" and pasted it in the google console but still its not working. 我还使用“ keytool -list -v -keystore mystore.keystore”从cmd提示符下复制了SHA1 Key,并将其粘贴到了Google控制台中,但仍然无法正常工作。
In debug mode everything is working good.. I have also given run time permission for android marshmallow and above. 在调试模式下,一切正常。.我还为Android棉花糖及更高版本授予了运行时权限。
Point to note: I have used mapView in place of fragments.. I have also tried with map fragments but still the same issue. 需要注意的是:我使用mapView代替了片段。.我也尝试过使用地图片段,但是仍然是同样的问题。
activity_maps.xml activity_maps.xml
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
You can see the difference here: 您可以在这里看到区别:
In debug mode , In release mode 在调试模式下 , 在释放模式下
Gradles: 等级:
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
AndroidManifest.xml AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission android:name="com.example.mapsact.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapsact.permission.MAPS_RECEIVE" />
MapsActivity.java MapsActivity.java
MapView mMapView;
GoogleMap mMap;
LocationManager location;
@Override
public void onResume() {
super.onResume();
try {
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20, 1, (android.location.LocationListener) this);
} catch (SecurityException e) {
e.printStackTrace();
}
mMapView.onResume();
//ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}
@Override
public void onLocationChanged(Location location) {
// Getting latitude of the current location
latitude = location.getLatitude();
// Getting longitude of the current location
longitude = location.getLongitude();
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
//now = mMap.addMarker(new MarkerOptions().position(latLng).title("Location").snippet("Current"));
// Showing the current location in Google Map
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(15.0f));
if(isNetworkConnected()) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("mobile", mobile);
jsonObject.put("lati", latitude);
jsonObject.put("longi", longitude);
SendLoc sendloc = new SendLoc();
sendloc.execute(jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
else {
Toast.makeText(this,"No Internet Connectivity",Toast.LENGTH_LONG).show();
}
}
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.animateCamera(CameraUpdateFactory.zoomTo(15.0f));
mMap.setMyLocationEnabled(true);
}
Just a guess but in release mode I think you need the key defined for maps this is from the manifest 只是一个猜测,但在发布模式下,我认为您需要为清单定义的密钥来自清单
<!--
The API key for Google Maps-based APIs is defined as a
string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key
used to sign the APK.
You need a different API key for each encryption key,
including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release
targets in src/debug/ and src/release/.
-->
I was also facing the same problem since last few days and it took me around 2-3 days to figure out the problem. 自最近几天以来,我还面临着同样的问题,并且花了大约2-3天的时间才弄清问题所在。 You need to add your API key at 2 places one in app/src/debug/res/values/google_maps_api.xml and other in app/src/release/res/values/google_maps_api.xml.
您需要在2个位置添加API密钥,一个在app / src / debug / res / values / google_maps_api.xml中,另一个在app / src / release / res / values / google_maps_api.xml中。
You can find the release/google_maps_api.xml in the project mode not in the Android/application mode. 您可以在项目模式下(而非Android /应用程序模式下)找到release / google_maps_api.xml。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.