问题
I have Google Maps in my Android App. I added it by selecting new Google Maps Activity & pasting the key in Android Studio. It worked fine in my Android phone (Lenovo K5 Note) but when I copied the project to another computer & run in another device (Coolpad), it shows a blank screen (beige or white colored) with Google logo on bottom left.
回答1:
Fought with blank map past two days and here is the summary (which I'm sure is not a complete list of possible issues!) collected from various sources.
1. Missing or incorrect or disabled API key
Seems to be most often. I recommend to follow official documentation. If you finish all steps, issue persists and you're still unsure whether it could be the reason, clone official android samples, find the MapWithMarker sample (android-samples/tutorials/MapWithMarker) and test against it. If you run the sample and it shows the map correctly, try to exchange default API KEY for the one you own.
- If it works, the key is not an issue.
- If it doesn't work, the key is your issue.
In such case make sure, you enabled it in Google API Console.
2. Missing Android GMS version meta-data tag
Your AndroidManifest.xml needs to define following metadata attribute:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
See the answer here for more details and official documentation.
3. Missing user permissions
In older versions of Android SDK, you had to explicitly set certain user permissions to work with Google Maps API correctly, for example:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
This is not the case anymore but I would recommend to visit official documentation to make sure you meet those version requirements.
4. Requirement for OpenGL ES version 2
In the past, there seemed to be requirement to specify following metadata attribute within AndroidManifest.xml
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
This shouldn't be required anymore per official documentation. Some additional details are available e.g. here.
5. AVD Manager device configurations
Android Studio 3.0 AVD Manager allows you to create device configurations for APIs that don't seem to be working well. At the moment, you can create configuration against API v27 which doesn't seem to be released yet if I'm not mistaken. Basic emulations worked well even there until I started work with Google Maps API. None of the device configurations set to v27 worked with Maps API resulting in blank map.
- Try downgrading to lower SDK version.
Note: Would be happy if anyone with deeper knowledge correct my simplified and probably incorrect interpretation. Since this was my problem, I stopped evaluating deeper and simply switch to different configuration for now.
Using following setup:
Android Studio 3.0
Build #AI-171.4408382, built on October 20, 2017
JRE: 1.8.0_152-release-915-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Hope this will help at least one person to save some time..
回答2:
Given the fact that your app works on Lenovo
, the most probable cause is that your Coolpad
phone doesn't have Google Play services
which are mandatory when you use most of Google's products. (here you can find more details about this problem for Coolpad 8675
). Unfortunately, you can't fix this as a developer. If an user really wants to user your app and doesn't have the Play Services
you can show an error telling what's the problem and that they should install them before using your app. From this point, they should be able to find enough tutorials on how to do this thing.
回答3:
The debug.keystore is different from two computers.
Solutions:
1) Copy the keystore from the pc to new in Android folder.
2) Generate new sha and put in your google api's project. https://developers.google.com/maps/documentation/android-api/signup#release-cert
回答4:
I had similar problem and spent a lot of time before solving it. Usually all was OK on real device, but failed to show Google Map on some of my emulator variants. Obviously, the program code was OK, so the question was why?
What I observe so far:
If hardware acceleration is disabled - all is back working.
If use pure android image, cpu-arm (not accelerated x86, it was slower), but also works.
If you are under x86_64 OS - macOS 10.13.2 in my case, USE x86_64 version of emulator image, instead of universal x86!!! That was my mayor mistake to do not get it works! Replacing my emulator's image with x86_64 variants, solve all of them!
回答5:
I think the SHA1 key you used to develop the app on pc is creating this problem on another pc. Generate SHA1 on new pc and replace old one then it will work fine. As you are using it as debugging purposes. For production purposes there is documentation on developer page.
来源:https://stackoverflow.com/questions/42852462/why-google-maps-is-showing-empty-screen-in-my-android-app