简体   繁体   中英

Android Google Map v2 signed apk doesn't work

Yet another question on GoogleMaps Api Key and release mode.

I have my API key, correctly added the SHA-1 in the allowed Android Applications, copied the key in the manifest and the same in both google_maps_api.xml (debug, release) in Android Studio. In debug everything works fine, but when I install the app through the Signed Apk it shows me gray screen and google logo. Anyone knows what I can do about that? Any help would be much appreciated. This is my AndroidManifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission
    android:name="com.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.permission.C2D_MESSAGE" />

<application
    android:name=".app.AppController"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Welcome"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".MenuActivity"
        android:label="@string/title_activity_menu"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".GalleryActivity"
        android:label="@string/title_activity_gallery"
        android:screenOrientation="portrait" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.MainActivity" />
    </activity>
    <activity
        android:name=".TripActivity"
        android:label="@string/title_activity_trip"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".PromoActivity"
        android:label="@string/title_activity_promo"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".ContactActivity"
        android:label="@string/title_activity_contact"
        android:screenOrientation="portrait" >
    </activity>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />

Did you implement the map in xml code like this:

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

also implement map in java?

GoogleMap googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.getUiSettings();
googleMap.getUiSettings().setZoomControlsEnabled(true);

There is more info about Google Maps here

Also if you have any question just ask

Update:

This part of the code:

  <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />

needs to implemented right after the activity of the class where the map is located/

For example if the map is located in Welcome class the the manifest should look like this:

<permission
    android:name="com.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.permission.C2D_MESSAGE" />

<application
    android:name=".app.AppController"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Welcome"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main"
        android:screenOrientation="portrait" >
    </activity>

    <activity
        android:name=".MenuActivity"
        android:label="@string/title_activity_menu"
        android:screenOrientation="portrait" >
    </activity>

    <activity
        android:name=".GalleryActivity"
        android:label="@string/title_activity_gallery"
        android:screenOrientation="portrait" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.MainActivity" />
    </activity>
    <activity
        android:name=".TripActivity"
        android:label="@string/title_activity_trip"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".PromoActivity"
        android:label="@string/title_activity_promo"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".ContactActivity"
        android:label="@string/title_activity_contact"
        android:screenOrientation="portrait" >
    </activity>

Update

Check if you have updated google play services in android sdk and also check in gradle if you have added this line in dependencies :

compile 'com.google.android.gms:play-services:7.0.0'

I think you generated SHA fingerprint key from machine A and compiled your android project in machine B. That's one of reason you may get blank screen. Please build your android project in machine A.

I think that you miss google play services . You need to have it in order to use Google Maps API v.2 You can get it from here or here .

I have just same issue and i know why.

Check the logcat if you find:

Google Maps Android API: Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
Google Maps Android API: In the Google Developer Console (https://console.developers.google.com)
Google Maps Android API: Ensure that the "Google Maps Android API v2" is enabled.
Google Maps Android API: Ensure that the following Android Key exists:
Google Maps Android API:       API Key: YOUR_KEY_HERE
Google Maps Android API:       Android Application (<cert_fingerprint>;<package_name>): xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx;com.example

Check file google_maps_api.xml in folder

app\\src\\ debug \\res\\valuess and app\\src\\ release \\res\\values

For debug is another file with API that in release.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM