Integration of Google map correct signature packaging posture

Keywords: Google Android xml Gradle

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]


1. Add manifestPlaceholders field value under build.gradle

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
            manifestPlaceholders = [ map_key:"AIzaSyAFhhAGX_9cW87jrdz06uDo96iweddwBl4" ]
        debug {
            manifestPlaceholders = [ map_key:"AIzaSyAFhhAGX_9cW87jrdz06uDo96iweddwBl4" ]

2. Modify registration file


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!


    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:

    You can also add your credentials to an existing key, using this line:

    Alternatively, follow the directions here:

    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>

     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/. 

Solution 3: according to the official recommendation of google, generate two key s, one for debug ging, one for release, and sign the package.

Posted by Supplement on Sun, 03 May 2020 02:44:57 -0700