简体   繁体   English

Google API 调试和发布密钥之间的区别

[英]Difference between Google API Debug and Release keys

I suppose this question has been answered a lot but I can't find any understandable answer.我想这个问题已经得到了很多回答,但我找不到任何可以理解的答案。

I'm currently developing an Android App that uses Google Maps API.我目前正在开发一个使用 Google Maps API 的 Android 应用程序。 I managed to make it work for some time but I never truly understand how to correctly use the Debug and Release keys.我设法让它工作了一段时间,但我从来没有真正理解如何正确使用DebugRelease键。

I don't know how to get the SHA-1 debug and release certificates for my app through Android Studio.我不知道如何通过 Android Studio 为我的应用程序获取 SHA-1 调试和发布证书。

On the Playstore console, I can get the SHA-1 release certificate (see picture below) but I don't know how to get it before publishing my app on the store.在 Playstore 控制台上,我可以获得 SHA-1 发布证书(见下图),但在商店发布我的应用程序之前我不知道如何获得它。 And that's a problem because when I need to publish my app for the first time, I don'thave this certificate and the map can't work.这是一个问题,因为当我第一次需要发布我的应用程序时,我没有这个证书并且地图无法工作。 I have to publish my app with a broken map and then retrieve the SHA-1 certificate through the Play Store console.我必须使用损坏的地图发布我的应用程序,然后通过 Play 商店控制台检索 SHA-1 证书。

从 Playstore 发布 SHA-1

Moreover, I don't know how to add a debug and release key in my Android Studio project.此外,我不知道如何在我的 Android Studio 项目中添加调试和发布密钥。 On the Android view, in the res folder, I have a google_maps_api.xml with a debug tag (see picture below).Android视图的res文件夹中,我有一个带有调试标记的google_maps_api.xml (见下图)。 But how can I add one for release ?但是我怎样才能添加一个发布呢? Is it the same key ?是同一个键吗? In that case, why is there a debug tag here ?在这种情况下,为什么这里有一个调试标签?

调试文件示例

Thanks for any tip and explanation you can give me!感谢您给我的任何提示和解释!

Based on the Google Maps Places SDK for Android Documentation基于Google Maps Places SDK for Android 文档

A debug certificate : The Android SDK tools generate this certificate automatically when you do a debug build.调试证书:当您进行调试构建时,Android SDK 工具会自动生成此证书。 Only use this certificate with apps that you're testing.仅将此证书用于您正在测试的应用程序。 Do not attempt to publish an app that's signed with a debug certificate.不要尝试发布使用调试证书签名的应用程序。 The debug certificate is described in more detail in Signing in Debug Mode in the Android Developer Documentation.调试证书在 Android 开发人员文档中的调试模式下签名中有更详细的描述。

A release certificate :The Android SDK tools generate this certificate when you do a release build.发布证书:当您进行发布构建时,Android SDK 工具会生成此证书。 You can also generate this certificate using the keytool program.您还可以使用 keytool 程序生成此证书。 Use this certificate when you are ready to release your app to the world.当您准备好向全世界发布您的应用程序时,请使用此证书。

Now to get your Release certificate, follow the steps below:现在要获取您的发布证书,请按照以下步骤操作:

  1. Locate your release certificate keystore file.找到您的发布证书密钥库文件。 There is no default location or name for the release keystore.发布密钥库没有默认位置或名称。 If you don't specify one when you build your app for release, the build will leave your .apk unsigned, and you'll have to sign it before you can publish it.如果您在构建要发布的应用程序时未指定一个,则构建过程将使您的 .apk 处于未签名状态,您必须先对其进行签名,然后才能发布它。 For the release certificate, you also need the certificate's alias and the passwords for the keystore and the certificate.对于发布证书,您还需要证书的别名以及密钥库和证书的密码。 You can list the aliases for all the keys in a keystore by entering:您可以通过输入以下内容列出密钥库中所有密钥的别名:

     keytool -list -keystore your_keystore_name

Replace your_keystore_name with the fully-qualified path and name of the keystore, including the .keystore extension.your_keystore_name替换为密钥库的完全限定路径和名称,包括.keystore扩展名。 You'll be prompted for the keystore's password.系统会提示您输入密钥库的密码。 Then keytool displays all the aliases in the keystore.然后keytool显示密钥库中的所有别名。

  1. Enter the following at a terminal or command prompt:在终端或命令提示符下输入以下内容:

     keytool -list -v -keystore your_keystore_name -alias your_alias_name

Replace your_keystore_name with the fully-qualified path and name of the keystore, including the .keystore extension.your_keystore_name替换为密钥库的完全限定路径和名称,包括.keystore扩展名。 Replace your_alias_name with the alias that you assigned to the certificate when you created it.your_alias_name替换为您在创建证书时分配给该证书的别名。

You should see output similar to this:您应该会看到与此类似的输出:

Alias name: <alias_name>
Creation date: Feb 02, 2013
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 4cc9b300
Valid from: Mon Feb 02 08:01:04 UTC 2013 until: Mon Feb 02 18:05:04 PST 2033
Certificate fingerprints:
    MD5:  AE:9F:95:D0:A6:86:89:BC:A8:70:BA:34:FF:6B:AC:F9
    SHA1: BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:90:AF:A1:66:6E:44:5D:75
    Signature algorithm name: SHA1withRSA
    Version: 3

The line that begins SHA1 contains the certificate's SHA-1 fingerprint.SHA1开头的行包含证书的 SHA-1 指纹。 The fingerprint is the sequence of 20 two-digit hexadecimal numbers separated by colons.指纹是由冒号分隔的 20 个两位十六进制数字的序列。

This certificate will be the one that you will include in your API key restriction in your GCP(Google Cloud Platform) Console.此证书将包含在 GCP(Google 云平台)控制台的API 密钥限制中。

Please also note that this can be found in the documentation mentioned above.另请注意,这可以在上述文档中找到。

Sorry, my answer is not formatted properly.抱歉,我的答案格式不正确。 Remember the goal is not the names debug or release but to add a layer of security through encryption with private and public keys.请记住,目标不是名称调试或发布,而是通过使用私钥和公钥加密来添加一层安全性。

There are many formats in the security encryption world so in this context the formats used are from OpenSSL and Java.安全加密领域有许多格式,因此在此上下文中使用的格式来自 OpenSSL 和 Java。

Basically, you sign packages with a JKS java key store that contains the certificate and private/public keys.基本上,您使用包含证书和私钥/公钥的 JKS java 密钥库对包进行签名。

To generate the keys follow https://source.android.com/devices/tech/ota/sign_builds#certificates-keys要生成密钥,请遵循https://source.android.com/devices/tech/ota/sign_builds#certificates-keys

The Keys will be generated using the OpenSSL framework and will come in formats .pk8 for the private key and x509.pem for the public certificate.密钥将使用 OpenSSL 框架生成,私钥格式为 .pk8,公共证书格式为 x509.pem。 You will get a bunch of keys: releasekey, shared, media and platform.您将获得一堆密钥:releasekey、shared、media 和 platform。 The names don't really matter much.名字其实并不重要。 What matter is the $subject that you generate for your keys.重要的是您为密钥生成的$subject

Once you have the keys based on the android docs you must convert them to PK12 which is the compatible format of the JKS.获得基于 android 文档的密钥后,您必须将它们转换为 PK12,这是 JKS 的兼容格式。 openssl pkcs12 -export -in platform.x509.pem -inkey /dev/stdin -name platform-debug -password pass:AStrongP4ssword -out tmp.p12

Finally, you can create you JKS that contains the PK12 formats.最后,您可以创建包含 PK12 格式的 JKS。

keytool -genkey -keystore platform-debug.jks

# Import created JKS
keytool -importkeystore -deststorepass 'AStrongP4ssword' -srckeystore tmp.p12 -srcstoretype PKCS12 -srcstorepass 'AStrongP4ssword' -destkeystore release.jks -destkeypass 'AStrongP4ssword'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调试和发布 apk 之间的区别 - Difference between debug and release apks cordova build --debug 和 --release 之间的区别 - Difference between cordova build --debug and --release Google Server和Android API密钥之间的区别 - Difference between Google Server and Android API keys for Places 在Google Maps Android API v2 DEBUG和RELEASE API Key之间切换 - Switching between Google Maps Android API v2 DEBUG and RELEASE API Key Android:签名发布和调试的apk文件之间没有差异 - Android: no difference found between an apk file signed for release and for debug 发布版本和调试版本之间的应用程序操作有什么区别吗? - Is there any difference in the app operation between release and debug versions? Android中的&#39;debug.keystore&#39;和&#39;release.keystore&#39;有什么区别? - What is difference between 'debug.keystore' and 'release.keystore' in Android? google api和google rest api之间的区别? - difference between google api and google rest api? 如何将 google map api 密钥从调试更改为在 android 中发布? - How to change google map api key from debug to release in android? Android Google服务:用于发布和调试的API密钥和SHA-1指纹 - Android Google Services: API key and SHA-1 fingerprint for release and debug
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM