After integrating Google Map, everything is normal in debug mode. The map is displayed normally. After signing and packaging, the app runs and finds that the map is not displayed
After a stack overflow, This is the solution
The reason is that the applied Google map API [key] is placed in the debug folder, and there is no corresponding release API [key]
Solution
1. Add manifestPlaceholders field value under build.gradle
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
manifestPlaceholders = [ map_key:"AIzaSyAFhhAGX_9cW87jrdz06uDo96iweddwBl4" ]
}
debug {
manifestPlaceholders = [ map_key:"AIzaSyAFhhAGX_9cW87jrdz06uDo96iweddwBl4" ]
}
}
2. Modify registration file
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${map_key}"/>
Sign again, pack and run, it's OK
Look at the integration process of Google Map carefully. In fact, there are official love guides from Google, but I didn't look at them carefully at the beginning!
google_maps_api.xml
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=9B:03:08:37:67:8F:08:E8:D6:F5:ED:66:42:43:2E:EF:58:48:E0:C4%3Bcom.gaoyy.delivery4res
You can also add your credentials to an existing key, using this line:
9B:03:08:37:67:8F:08:E8:D6:F5:ED:66:42:43:2E:EF:58:48:E0:C4;com.***.d******s
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyAFhhAGX_9cW87jrdz06uDo96iweddwBl4</string>
</resources>
AndroidManifest.xml
<!--
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/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${map_key}"/>
Solution 3: according to the official recommendation of google, generate two key s, one for debug ging, one for release, and sign the package.