Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit an AndroidManifest when compiling to remove API-key

Tags:

I'm currently working on an Android project, and learning how to use git. I'm blocked because of a problem with git : I have my Google Maps api key declared in my android-manifest file :

<meta-data     android:name="com.google.android.maps.v2.API_KEY"     android:value="HEREISMYKEY"/> 

Now, I'd like to push my code in github, but I can't push my AndroidManifest, because it contains my api key (which is supposed to remain secret).

I'd like to know if there is a way to modify it before every push, or maybe modify it each time I compile my application?

Thank you for your help !

like image 802
MagicMicky Avatar asked Dec 20 '12 19:12

MagicMicky


People also ask

How do I edit AndroidManifest XML?

The Android manifest file is a specially formatted XML file. You can edit the XML manually by clicking on the AndroidManifest. xml tab. Android manifest files generally include a single <manifest> tag with a single <application> tag.

How do I restrict my API key to specific Android applications?

If you're using Play App Signing instead, you must go to the app signing page on the Play Console to get your certificate fingerprint. Go to the Google Maps Platform > Credentials page. Select the API key that you want to set a restriction on. The API key property page appears.

Where is the AndroidManifest XML file located?

xml file is created in the app's corresponding dist folder. The file is located at WorkspaceName>/temp/<AppName>/build/luaandroid/dist. The manifest file provides essential information about your app to the Android operating system, and Google Play store.


1 Answers

Create a new *.xml file in your res/values (call it api-keys.xml or something similar).

Change your manifest to point to this string:

 <meta-data     android:name="com.google.android.maps.v2.API_KEY"     android:value="@string/GoogleMapsKey"/> 

When you first push your changes to the public, put in a dummy key.

Then edit the file with your real API key.

Then add the file to your .gitignore file so it doesn't get pushed again.

like image 144
Bryan Denny Avatar answered Sep 19 '22 08:09

Bryan Denny