問題描述
發布不顯示谷歌地圖的 APK 文件 (Release APK file not showing google maps)
我應用了谷歌開發者文檔中提到的確切步驟來創建一個示例谷歌地圖項目,並且在模擬器上一切正常,但是當我生成項目 apk 文件並在真實設備上啟動它時三星 Galaxy S4 谷歌地圖沒有'不顯示它只顯示一個空白背景,僅在屏幕左下角出現彩色的 Google 徽標!!
我為谷歌地圖創建了新項目我為該項目創建了新的 .jks 文件並創建了商店和密鑰傳遞和別名然後我從 cmd java bin 中提取 SHA1 我去 dev.google.com/console 創建了新項目然後啟用 google maps android API 然後從 Credentials 創建 API 密鑰 將此 API 密鑰粘貼到 google_maps_api.xml 中我的項目使用 .jks 文件路徑和別名以及兩個密碼更新了 signingConfigs 版本。然後從 Android Studio 生成簽名的 APK 然後將 app‑release.apk 傳輸到真實設備然後安裝它同樣的問題谷歌地圖不顯示。
參考解法
方法 1:
Reason for this issue
This occurred because there are different SHA1
s in debug
and release
types.
Fix for this issue
Add the SHA1
of the keystore used to build the release
APK
to Google console
Steps:
Get the path of the keystore when you generate signed APK
Build ‑‑‑‑> Generate Signed APK..
Save the key store path
Remember to make Build Type ‑‑‑ release
- Extract
SHA1
from the keystore.
Open your terminal use command below:
keytool ‑list ‑v ‑keystore "/Users/NT/Desktop/generalkey.jks"
You will be asked for password for your keystore.
Change path to your keystore path keytool ‑list ‑v ‑keystore "keystore path"
From the Certificate fingerprints, you will see the SHA1
- Generate android key using this
SHA1
and your package name
Generate APK using keystore and enjoy your map
方法 2:
It might be silly but I had my API key included in
app\src\debug\res\values\google_maps_api.xml (debug)
You also need to include in‑
app\src\release\res\values\google_maps_api.xml (release)
方法 3:
if any one still facing this problem :
this happend to me because we need two google maps api keys one for the debug and another one for the release, you can check in :
C:\Users\username\AndroidStudioProjects\yourapp\app\src\ debug \res\values and you'll find an xml with your api key like:
<string name="google_maps_key" templateMergeStrategy="preserve"
translatable="false">AIza...etc</string>
but if you check here:
C:\Users\username\AndroidStudioProjects\yourapp\app\src\ release \res\values you will find an xml but without api key inside like:
<string name="google_maps_key" templateMergeStrategy="preserve"
translatable="false">YOUR_KEY_HERE</string>
it was noted as a comment inside the xml file itself :
Before you release your application, you need a Google Maps API key.
To do this, you can either add your release key credentials to your existing
key, or create a new key.
Note that this file specifies the API key for the release build target.
If you have previously set up a key for the debug target with the debug signing certificate,
you will also need to set up a key for your release certificate.
Follow the directions here:
https://developers.google.com/maps/documentation/android/signup
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
方法 4:
Check the following things:
This below file should be in both debug and release
app\src\debug\res\values\google_maps_api.xml (debug)
You also need to include in
app\src\release\res\values\google_maps_api.xml (release)
Add the SHA1 for release apk into Google Api Console. You can get SHA1 key from play console >> App Signing >> SHA1 Certificate
方法 5:
Another additional step: In google play developer console add App Signing SHA1 fingerprint:
(by user2985035、Mina Fawzy、Varun Kumar、ehab、Govind Prajapati、NELSON RODRIGUEZ)