Reputation: 141
Google maps activity isn't working on release mode but working fine on Debug mode.
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.
In debug mode everything is working good.. I have also given run time permission for android marshmallow and above.
Point to note: I have used mapView in place of fragments.. I have also tried with map fragments but still the same issue.
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
<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
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);
}
Upvotes: 1
Views: 2177
Reputation: 141
I was also facing the same problem since last few days and it took me around 2-3 days to figure out the problem. 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.
You can find the release/google_maps_api.xml in the project mode not in the Android/application mode.
Upvotes: 8
Reputation: 1255
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/.
-->
Upvotes: 1