Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separate XML line for debug or release mode in android manifest

My Android manifest uses different values when debugging and when releasing.

What's the easiest way to differentiate a value for each build type?

When debug:

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="my-lovely-debug-api-key" />

When release:

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="my-lovely-release-api-key" />

tia.

like image 233
ericosg Avatar asked Dec 13 '13 15:12

ericosg


People also ask

What is difference between release and debug APK?

Major differences are the debug apk and the release apk: For debug builds the apk will be signed with the default debug signing keys with debug flag enabled. For release apk you will have to explicitly specify the apk to sign with and the debug flag will be turned off so that it cannot be debugged.

How do I change AndroidManifest XML?

Open your Android project and go to <AppProjectFolder>/app/src/main/. Open the app manifest file AndroidManifest. xml and add the following lines to the file as child elements of the <manifest> element. Note: You must include the QUERY_ALL_PACKAGES permission if your app targets Android 11 (API Level 30) or higher.

What is the use of AndroidManifest XML file?

Every app project must have an AndroidManifest. xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.

What is contained within the manifest XML file?

The AndroidManifest. xml file contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc.


1 Answers

Note that if you are using default Eclipse builds it probably uses a specially configured 'Ant' module within eclipse. You can check on the degree of Eclipse/Ant coordination by checking 'Window/Preferences/Ant' section in eclipse/Prefs....

One solution is to make more explicit, the collaboration of Eclipse/Ant so that a 'build.xml' file is part of your project ( project level build file rather than the default file copied in at build time from the $SDK/ROOT folder ).

see here and read the comments at bottom here to get better idea of how a project level 'build.xml' file is used.

Once you've digested that , the solution below will make more sense...

--Solution--

Modify the Release and the Debug sections of you 'build.xml' file as follows:

  <!-- **************** Debug specific targets *************** -->
  ...
    <target name="-set-debug-mode" depends="-setup">
  ...

        <!-- API modify belo for build-typ -->
         <copy file="config/strings.xml" todir="res/values">
       <filterset>
    <filter token="CONFIG.API" value="${config.db.api}"/>
    <filter token="CONFIG.REST" value="${config.db.rest}"/> 
    </filterset> 
    </copy>
  ...



   <!-- *************** Release specific targets ************** -->
  ...
  <target name="-set-release-mode" depends="-set-mode-check">
   ...
   <!-- API modify belo for build-typ -->
   <copy file="config/strings.xml" todir="res/values">
     <filterset>
     <filter token="CONFIG.API" value="${config.db.api.prod}"/> 
     <filter token="CONFIG.REST" value="${config.db.rest.prod}"/>
    </filterset> 
   </copy>

And in the 'ant.properties' file in your root folder, put the property values for the API keys and whatever...

# API condition builds dev|prod in DB @parse.com
config.db.api=some_key_val
config.db.rest=some_k2_val
config.db.api.prod=some_k3_val
config.db.rest.prod=some_k4_val

And tie it together in a resource xml that is the target of the 'copy' commands in the build...

 'config/strings.xml'  

<string name="default_value_parse_key_appId">@CONFIG.API@</string>
<string name="default_value_parse_key_rest">@CONFIG.REST@</string>
like image 95
Robert Rowntree Avatar answered Oct 17 '22 03:10

Robert Rowntree