views:

723

answers:

3

Whats the best way to deploy several customized versions of a Android application?

Currently I have a script to exchange the resource folder for getting a customized version of my app. It works great, but all custom versions still have the same package name in the AndroidManifest.xml. Therefore it is not possible to install two customized versions of the app at the same time.

This is one solution for this problem, but that has to be done by hand

Can you think of a more easy solution, or how this could be built into a skript?

(btw: it is not for a porn/spam/whatever app, not even a paid one)

+2  A: 

The linked-to solution does not have to be done by hand. Bear in mind that the package attribute in the <manifest> element does not have to be where the code resides, so long as you spell out the fully-qualified classes elsewhere in the manifest (e.g., activity android:name="com.commonsware.android.MyActivity" rather than activity android:name=".MyActivity"). Script your manifest change and use Ant to build a new APK. AFAIK, that should work.

CommonsWare
This destroys the auto-generated R file. So you have to go through more or less all your source files and change the import of the R file (point 8).
Ulrich Scheller
Ah. Good point. Still scriptable, just more painful.
CommonsWare
We solved the R issue.import old.package.string.*;import new.package.string.*;This just imports R for both builds.
Fedor
+4  A: 

What I did for something similar to this is to just use an antlib task and then go through all java and xml files to replace my old package string to the new package string. It didn't matter if the files were not in the correct src paths according to the package. Just doing a regex replace for all the files was enough for me to get this working...

For example to replace it in all your java files under the src directory:

 <replaceregexp flags="g" byline="false">
    <regexp pattern="old.package.string" /> 
    <substitution expression="new.package.string" />
    <fileset dir="src" includes="**/*.java" /> 
 </replaceregexp>
Prashast
This solved my problem, thank you.I am now using two replaceregexp. One is exactly as yours and another one for replacing the package name in the AndroidManifest.xml.
Ulrich Scheller
Doesn't work for me, because all the source files are still in a directory structure matching the old package name. How did you solve this?
Matthias
For me the source file location didn't matter. As long as they have the correct package information.Opening it in Eclipse may not work though. I had used this only with the ant build and the use the generated apk file.
Prashast
+1  A: 

I'm using the maven-android-plugin to achieve this. Specify one AndroidManifest.xml for the generated-sources goal and another AndroidManifest.xml for the final apk goal. That way the source code project retains the actual source code package name during generation of the R class and the build phase, while the market adapted manifest package name is in the second AndroidManifest.xml which is included in the final apk file.

Fredrik Jonson