Google Map仅显示谷歌Logo且地图空白,多次排查未解决求助
Hey there, let’s dig into why your Google Map is only showing the logo with a blank map—super frustrating, I know! Let’s break down the checks for your Manifest and Build.gradle files step by step:
These are the most common culprits for map loading failures, so let’s start here:
Verify your Google Maps API Key configuration
Make sure you’ve added the API key correctly inside the<application>tag of your AndroidManifest.xml. The key name must becom.google.android.geo.API_KEY(the oldcom.google.android.maps.v2.API_KEYis deprecated). Here’s the correct format:<application ...> <!-- Other app components --> <meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_ACTUAL_API_KEY"/> </application>Also double-check that this key is enabled for the Maps SDK for Android in your Google Cloud Console, and that the SHA-1 fingerprint and app package name linked to the key match exactly (case-sensitive!).
Ensure required permissions are present
Maps needs internet access and location permissions (at least coarse) to load properly. Add these lines outside the<application>tag:<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- Optional, for precise location --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>Don’t forget to request runtime permissions for location if your target SDK is 23 or higher.
Check for the Maps service declaration
Ensure you’ve included the Maps service component inside<application>(though newer Play Services versions might handle this automatically, it’s still worth verifying):<service android:name="com.google.android.gms.maps.GoogleMapService" android:enabled="true" android:exported="false"/>
Next, let’s confirm your dependencies and build setup are correct:
Validate Maps dependency version
Make sure you’re using a stable, up-to-date version of the Maps SDK. Add or verify this line in your module’s build.gradle (underdependencies):implementation 'com.google.android.gms:play-services-maps:18.2.0' // Use the latest stable versionYou can check for the latest version in the Google Play Services release notes.
Confirm Google Maven repository is added
In your project-level build.gradle, ensure the Google repository is listed in therepositoriesblock (this is required to pull Play Services dependencies):allprojects { repositories { google() mavenCentral() // Other repositories } }Check SHA-1 fingerprint and package name alignment
Run thesigningReporttask in Android Studio (via Gradle > Tasks > android > signingReport) to get your debug/release SHA-1 fingerprints. Then go to your Google Cloud Console, find your API key, and make sure these fingerprints + your app’s exact package name are added to the key’s restrictions. A mismatch here will block map loading every time.Handle ProGuard/R8 obfuscation (if enabled)
If you’re using obfuscation in your build, add these rules to yourproguard-rules.profile to prevent Maps-related code from being stripped or mangled:-keep class com.google.android.gms.maps.** { *; } -keep interface com.google.android.gms.maps.** { *; } -keep class com.google.android.gms.location.** { *; }
- Test with a physical device
Emulators can sometimes have issues with Google Play Services—try running your app on a real device to rule out emulator-specific problems. - Check network connectivity
Ensure your device has a stable internet connection, and that you’re not using a VPN/proxy that blocks access to Google’s servers. - Verify Google Play Services is up to date
Outdated Play Services can cause map loading failures. Go to the Google Play Store on your device and update Google Play Services if an update is available.
Try going through each of these checks one by one—9 times out of 10, it’s either a misconfigured API key, missing permissions, or incorrect dependency setup. Let me know if any of these steps fix your issue, or if you need to share snippets of your files for deeper debugging!
内容的提问来源于stack exchange,提问作者Aqra Yosef

