Git:跟踪还是取消跟踪Android API密钥? [英] Git: track or untrack Android API keys?

查看:61
本文介绍了Git:跟踪还是取消跟踪Android API密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Maps API for Android.我想将代码从台式机推送到Github上,然后在旅行时想将代码从Github上下载到笔记本电脑上.

就Google Maps API而言,我需要将API密钥放置在android清单中,如下所示:

<application>
  ...
  <meta-data
      android:name="com.google.android.geo.API_KEY"
      android:value="YOUR_API_KEY"/>
</application>

现在,因为我有两个不同的调试证书(一个在笔记本电脑上,一个在台式机上),所以Google的API密钥也会有所不同,因为调试证书中的SHA-1指纹会有所不同.

如何在两台PC上保持唯一性?

我认为有必要在git上跟踪android清单,因为这是任何应用程序的重要组成部分,但是现在如何避免每次按下API密钥时发生冲突?

解决方案

不跟踪android清单:在git checkout上自动生成.

称为smudge脚本,是内容过滤器驱动程序的一部分,使用自定义Git的图片- Git属性",摘自" Pro Git书)

"smudge"脚本(必须编写)需要:

  • 检测其环境
  • 获取正确的密钥(可以从已经跟踪的另一个文件中获取,并列出这些密钥)
  • 使用清单中带有占位符值的跟踪清单 template 替换清单.

I'm using Google Maps API for Android. I push my code onto Github from my desktop and then download it off Github onto my laptop when I want to work on code while travelling.

In terms of Google Maps API, I need to put the API key in the android manifest like this:

<application>
  ...
  <meta-data
      android:name="com.google.android.geo.API_KEY"
      android:value="YOUR_API_KEY"/>
</application>

Now, because I have two different debugging certificate (the one on the laptop and the one on the desktop), the API keys from google would also be different as the SHA-1 fingerprint from the debugging certificates would differ.

How do I keep this unique on both PCs?

I think it is necessary to track the android manifest on git as that's quite an important component of any app but now how do I avoid conflicts in the API key each time I push?

解决方案

Don't track the android manifest: generate it automatically on git checkout.

That is called a smudge script, part of a content filter driver, using using .gitattributes declaration.

(image from "Customizing Git - Git Attributes", from "Pro Git book")

That 'smudge' script( that you have to write) would need to:

  • detect its environment
  • fetch the right key (possible from another file already tracked, and which would list those keys)
  • generate the manifest, using a tracked manifest template with placeholder value in it to replace.

这篇关于Git:跟踪还是取消跟踪Android API密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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