安卓:自动选择调试/发布地图API密钥? [英] Android: automatically choose debug/release Maps api key?

查看:127
本文介绍了安卓:自动选择调试/发布地图API密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已过时:这个老问题是指废弃谷歌地图API的第一版。当使用V2 API,你可以在一个谷歌API控制台作品。 API密钥不再存储在清单,也没有code。

OBSOLETED: this old question refers to obsoleted Google Maps v1 API. When using v2 API, you can use multiple certificate fingerprints in one Google API Console entry. API Key is no longer stored in Manifest nor code.

是否可以自动检测,其证书用于签名APK?我想有两个调试和在应用程序中释放地图证书,并通过有效的一个图形页面的构造函数。

Is it possible to automatically detect, which certificate was used for signing APK? I'd like to have both debug and release Maps certificates in application and pass valid one to MapView constructor.

通过这样的设置,我不会出错,同时释放出的应用程序 - 我使用的模拟器调试证书,我的设备,然后发送到应用程序市场之前,释放一个符号

With such setup I will not make mistake while releasing application - I'm using debug certificate on emulator and my device, then sign with release one before sending app to Market.

我在想我的检测特定设备或是否调试器连接,但它并非十全十美。也许有些文件标记需要调试证书?有没有什么更好的办法?

I was thinking about detecting my particular device or whether debugger is connected but it is not perfect. Maybe some file marking need for debug certificate? Is there any better way?

推荐答案

有一个新的方法来确定它是一个调试版本或发布之一的 SDK工具,修订17 。新功能的摘录概述:

There is a new way to determine is it a debug build or release one in SDK Tools, Revision 17. An excerpt from new features overview:

现在建立产生一类名为 BuildConfig 包含 DEBUG 常量,它是根据你的编译类型自动设置。您可以检查( BuildConfig.DEBUG )不断在code到运行调试,只等功能。

Builds now generate a class called BuildConfig containing a DEBUG constant that is automatically set according to your build type. You can check the (BuildConfig.DEBUG) constant in your code to run debug-only functions.

所以,现在你可以简单地这样写:

So now you can simply write something like this:

if (BuildConfig.DEBUG)
{
    //Your debug code goes here
}
else
{
    //Your release code goes here
}

更新:我在ADT中遇到的错误:有时候 BuildConfig.DEBUG 导出后的应用程序包。说明是在这里:<一href="http://$c$c.google.com/p/android/issues/detail?id=27940">http://$c$c.google.com/p/android/issues/detail?id=27940

UPDATE: I've encountered bug in ADT: sometimes BuildConfig.DEBUG is true after exporting application package. Description is here: http://code.google.com/p/android/issues/detail?id=27940

这篇关于安卓:自动选择调试/发布地图API密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆