くわこのpermission denied.

WEBエンジニアの僕がぶつかった技術的な問題や発見

【Android】開発環境では動くのにapkファイルに固めた後だとGoogleMapが表示されない問題

f:id:mask0702:20160131145020p:plain

えぇ、3時間ほど無駄にしましたよ。お陰様で。えぇ。

タイトル通りなんですが、開発環境の実機デバッグではGoogleMapが普通に使えていたのに実際にapk形式に固めて動かしてみたらグレーの画面が表示されていました。

↓ 開発環境
f:id:mask0702:20160131145455p:plain

↓ apkに固めてみて動かしたら
f:id:mask0702:20160131145553p:plain


どうした俺のGoogleMap!!!!
動け動け動け動け!!!!今動かないとダメなんだよ!!!!(納期的に)
f:id:mask0702:20160131150504p:plain


ってわけで泣きながら原因を探す。
ちゃんとgoogle_maps_api.xmlにキー書いてあるしなー。

teratail.com

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表示されないわ。

公式ドキュメント、読もう。ちゃんと。

f:id:mask0702:20151209100945j:plain