【Android】開発環境では動くのにapkファイルに固めた後だとGoogleMapが表示されない問題
えぇ、3時間ほど無駄にしましたよ。お陰様で。えぇ。
タイトル通りなんですが、開発環境の実機デバッグではGoogleMapが普通に使えていたのに実際にapk形式に固めて動かしてみたらグレーの画面が表示されていました。
↓ 開発環境
↓ apkに固めてみて動かしたら
どうした俺のGoogleMap!!!!
動け動け動け動け!!!!今動かないとダメなんだよ!!!!(納期的に)
ってわけで泣きながら原因を探す。
ちゃんとgoogle_maps_api.xmlにキー書いてあるしなー。
teratailに質問投げても帰ってこないしなー。
公式ドキュメント読んでもよくわから...ん?
The API key is based on a short form of your app's digital certificate, known as its SHA-1 fingerprint. To display the SHA-1 fingerprint for your certificate, first ensure that you are using the right certificate. You may have two certificates:
Get API Key | Google Maps Android API | Google Developers
You may have two certificates
!!!!
debug版とrelease版では別のAPIキーが必要!!!!
やったね、たえちゃん。なんでだよ、たえちゃん。
というわけで公式ドキュメント見ながら release certificate 作って別のAPIキー作って
app/src/release/res/values/google_maps_api.xml
に書いて一件落着。
ちなみにこの時、
app/src/debug/res/values/google_maps_api.xml と
app/src/release/res/values/google_maps_api.xml が分かれてることを知った笑
なるほどね。さすがにそれはGoogleMap表示されないわ。
公式ドキュメント、読もう。ちゃんと。