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

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

问题描述

过时了:这个老问题是指过时的 Google Maps v1 API.使用 v2 API 时,您可以在一个 Google API 控制台条目中使用多个证书指纹.API Key 不再存储在 Manifest 和代码中.

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 的证书?我想在应用程序中调试和发布地图证书,并将有效的证书传递给 MapView 构造函数.

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) 常量以运行仅调试功能.

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.DEBUGtrue.描述在这里:http://code.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

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

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