Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Android build.xml for rename manifest package

Tags:

android

I wanna build one app into 2 version, one paid, one free, and I know aapt have a option "--rename-manifest-package" should help, but I don't know How to use it in build.xml. I find 2 place I may modify:

 <!-- first -->
 <target name="-resource-src" depends="-dirs">
    <echo>Generating R.java / Manifest.java from the resources...</echo>
    <exec executable="${aapt}" failonerror="true">
        <arg value="package" />
        <arg line="${v.option}" />
        <arg value="-m" />
        <arg value="-J" />
        <arg path="${gen.absolute.dir}" />
        <arg value="-M" />
        <arg path="AndroidManifest.xml" />
        <arg value="-S" />
        <arg path="${resource.absolute.dir}" />
        <arg value="-I" />
        <arg path="${android.jar}" />       
    </exec>
</target>



 <!-- sencod -->
 <target name="-package-resources">
    <echo>Packaging resources</echo>
     <aaptexec executable="${aapt}"
            command="package"
            manifest="AndroidManifest.xml"
            resources="${resource.absolute.dir}"
            assets="${asset.absolute.dir}"
            androidjar="${android.jar}"
            outfolder="${out.absolute.dir}"
    basename="${ant.project.name}" >
</aaptexec>
</target>

this article( http://blog.uncommons.org/2010/07/19/building-two-versions-of-the-same-android-app/ ) said I should adding "--rename-manifest-package" at the second place, but How?

like image 799
Jammy Lee Avatar asked Jul 29 '10 07:07

Jammy Lee


1 Answers

The option --rename-manifest-package cannot be used with the aaptexec ant task. It is an option that needs to go straight to the aapt executable, like this;

<exec executable="${aapt}" failonerror="true">
  <arg value="package" />
  <arg value="-f" />
  <arg value="-v" />
  <arg value="--version-code" />
  <arg value="${version.code}" />
  <arg value="--debug-mode" />
  <arg value="-M" />
  <arg path="AndroidManifest.xml" />
  <arg value="-A" />
  <arg path="${asset.absolute.dir}" />
  <arg value="-I" />
  <arg path="${android.jar}" />
  <arg value="-F" />
  <arg path="${out.absolute.dir}/${resource.package.file.name}" />
  <arg value="-S" />
  <arg path="${resource.absolute.dir}" />
  <arg value="--rename-manifest-package" />
  <arg value="com.example.pro" />
</exec>

I found no way of editing a file that actually changes the way Eclipse builds. So I put that piece of code in the build.xml, put it in the project root, and built from the console by typing;

ant debug

And if you depend on any libraries, they need to go into the packaging as well. Look into your default.properties file and you'll see the reference to the lib. Then add that to the rule above, like this;

<arg value="-S" />
<arg path="${android.library.reference.1}/res" />

It starts to feel more and more like a hack that can break with any platform SDK update.

like image 170
Martin Kretz Avatar answered Oct 12 '22 10:10

Martin Kretz