How to configure android map sdk v2 to use different keys for production and development?

回眸只為那壹抹淺笑 提交于 2019-11-27 02:12:15

问题


I want to automatically set different android map api V2 keys for development and production.


回答1:


Log in to Google APIs Console Under "Simple API Access" click "Edit Allowed Android apps..." on the right side Enter one SHA-1 fingerprint per line like the instructions say:

"One SHA1 certificate fingerprint and package name (separated by a semicolon) per line. Example: 45:B5:E4:6F:36:AD:0A:98:94:B4:02:66:2B:12:17:F2:56:26:A0:E0;com.example 45:B6:E4:6F:36:AD:1A:98:94:B4:02:66:2B:12:17:F1:56:26:A0:E0;com.example"

Now, just use the same "Simple API key" and it'll work for your debug and publish certificate without having to change anything.




回答2:


I may be wrong, but I think you can use the same V2 API key for both development and production builds. In your Google APIs Console, after generating a simple Android key, you just need to enter the SHA-1 fingerprints of your production signing key, and all the development Android debug signing keys you may have. Then in your manifest, just use that simple Android key and the app should work for both debug and production builds.




回答3:


One of the easiest solution.You can achieve it with two simple steps.

Add custom value to manifestplaceholders build.gradle file. See below

buildTypes {
    debug {
        manifestPlaceholders = [ mapApiKeyValue:"GHjaSyAjlyp3O831lgaonHMXsd-_DpQ3002x3S4"]
    }

    release {
        manifestPlaceholders = [ mapApiKeyValue:"AIzaSyAuMGDLr2HeuRed4JA0CrdYYdZRjeC3EA"]
    }
}

Edit manifest file like below. part of my manifest file

 <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="${mapApiKeyValue}" />

This solution works for the latest Android 5.0 and Android 6.0 (API 20, 21,22,23)



来源:https://stackoverflow.com/questions/13878249/how-to-configure-android-map-sdk-v2-to-use-different-keys-for-production-and-dev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!