I have two programs. First is a desktop app (C#) and the other is an android app.
The C# one makes some text files and puts them in some of android app folders. So we can have multiple android apps with different contents. the android app is pre-compiled. and the c# app just puts the test files in (with 7za) and repackages it (with zipalign).
The problem is, All of these apps have a single source! means same package name and same app name!
And as you know, android considers same package names as same apps! How can i solve this problem? and create separate apps from a single android app with different text files (contents)
More details: I have a single android app (test.apk). My C# app should edit this zip file and repackage it. putting text files in assets folder is working good. But by this method, the C# app output's apks all are the same! i can't install them on mobile separately, because android OS replaces them on each other.
I found myself in a similar situation.
I had a single app but built for different customers (having specific customization like resources, properties...). I eventually decided to manage the whole thing using maven.
What I've done is creating a "config" folder in my codebase and inside it I've added pro customer a folder containing the properties, string, pictures related to him.
My structure is something like this:
MyAppBase
src/
build/
BaseAndroidManifest.xml
...
config/
customerA/
logo.png
customerA.xml
customerA.properties
customerB/
customerC/
...
Using maven artifacts for copying, move, replace I've then managed to build customer specific apk in the following way:
1) Create a temporary customer specific source folder where all code is copied to
<copy todir="src_${customer}">
<fileset dir="src"/>
</copy>
2) Rename packages and imports
<!-- Rename main package -->
<move file="src_${customer}/ch/wizche/myapp" tofile="src_${customer}/ch/wizche/${customer}"/>
<!-- Replace package imports with the newly one -->
<replace dir="src_${customer}/" value="ch.wizche.${customer}">
<include name="**/*.java"/>
<replacetoken>ch.wizche.myapp</replacetoken>
</replace>
3) Replace specific resources based on the customer
<!-- Copy images icon to the drawable folder -->
<copy file="./configs/${customer}/ic_launcher_l.png" tofile="./res/drawable-ldpi/ic_launcher.png" overwrite="true" verbose="true"/>
<copy file="./configs/${customer}/ic_launcher_m.png" tofile="./res/drawable-mdpi/ic_launcher.png" overwrite="true" verbose="true"/>
4) Replace "Template" AndroidManifest and injecting customer versions, names, ...
<copy file="./BaseAndroidManifest.xml" tofile="./AndroidManifest.xml" overwrite="true" verbose="true"/>
<replace file="./AndroidManifest.xml" value="ch.wizche.${customer}" token="ch.wizche.myapp"/>
<replace file="./AndroidManifest.xml" value="android:versionCode="${versionCode}" token="android:versionCode="1"/>
5) Signing using customer alias
6) Building APK
7) Deleting temporary customer folder
So, to build a customer specific app, I just need to:
mvn install -Dcustomer=customerA -P release
Hope this may give you some inputs.
I had a similar problem where i wanted multiple apks with different resolutions of graphics in each (a single apk with all images for all display sizes was too big).
I ended up creating a custom build process where i inserted a 'prebuild' AntTask that basically copied over the correct resources for the build and preprocessed the source such that the package was updated for each apk..
can't find any official docs but this should be a good start..using-ant-to-automate-building-android
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With