I have one android project where I need to create multiple apks. The only difference between each apk will be package name (e.g. com.my.package.name) and the app string name so I can install multiple instances of the app on one device. Is there a better way of doing this? I thought about creating a library project, but I thought there might be an easier way of doing this.
7 Answers
You can put your main code in a Library and build multiple sibling projects that have multiple APKs generated:
I tested this and was much easier than I first thought: https://stackoverflow.com/a/9971543/305135

- 1
- 1

- 17,993
- 23
- 107
- 210
The library project is the correct way of doing this. You create and work on the library project and have a project for each version, that depends on the library project. Bare in mind that you need to have a correct Androidmanifest for each project.

- 1,686
- 1
- 11
- 18
-
So if I do an Ant build on the library project does it automatically generate the apk for the other dependent projects? – squistbe Nov 02 '12 at 21:21
-
You can create a single ant build for all projects, but i'm not aware of a tool that might do this "reverse dependency building" automatically for you. However the builds for the projects would be pretty much identical, so this should not create a lot of extra effort. – stoilkov Nov 03 '12 at 02:11
-
What do you mean by having the correct Androidmanifest for each project? – squistbe Nov 05 '12 at 15:54
-
1well, it might seem logical to you (as it seems logical to me) that projects inherit definitions like permissions, activites, services, receiver, etc. from their library project's manifest files, however this is not the case. This means, you have to have a "full" manifest file defined for each project, and if you need to make a change, you should make it in each of these files. Also, be carefull with the qualified names of activites,services, as the default style of manifest files is to have them inside the package project package (start with "."). – stoilkov Nov 05 '12 at 17:14
You can try out the new Android build system. Here are some links
- http://tools.android.com/tech-docs/new-build-system
- http://tools.android.com/tech-docs/new-build-system/build-system-concepts
- http://tools.android.com/tech-docs/new-build-system/using-the-new-build-system
You can customize the following properties:
- minSdkVersion
- targetSdkVersion
- versionCode
- versionName
- package name (overrides value from manifest)
- etc..

- 4,171
- 2
- 28
- 32
You can use productFlavors in gradle of app level.
flavorDimensions "tier"
productFlavors {
dev
{
dimension "tier"
buildConfigField "String", "URL", "\"http://glapp/demo.php\""
buildConfigField "boolean", "ENABLE_DEBUG", "false"
versionName = android.defaultConfig.versionName + " dev"
applicationId = "com.abc.glnewapp.dev"
resValue "string", "app_name", "GL Demo"
}
prod
{
dimension "tier"
buildConfigField "String", "URL", "\"http://glapp/live.php\""
buildConfigField "boolean", "ENABLE_DEBUG", "false"
applicationId = "com.abc.glnewapp.prod"
resValue "string", "app_name", "GL Live"
}
}
Then select build variant to build apk as per as varient You can put many flours(different apks) as you want.
You can change app icon and other drawables by adding same res structure in falour name folder under src directory. Also if you find any issue relevant to google json then just copy google json file in src->productflavour
For more info visit at

- 6,198
- 2
- 47
- 58
You cannot change package name programmatically. So only solution is to change it manually and create apk.

- 885
- 6
- 18
To change the package name you can do this:
You'll need to duplicate the project. Right click in one, select "Android Tools -> Rename Application Package"
Hope this help.

- 1,972
- 17
- 22
-
I have already done this in eclipse. I would rather do something to automate it instead of changing the package name 30 different times and then building another apk. – squistbe Nov 02 '12 at 21:13
I actually used the apktool to decompile the apk and then edited the smali files using some Perl script to change the package name.

- 305
- 1
- 3
- 18
-
Hi ! I would like to know what files should I edit, if I want to make a different APK from the same sourcode (Beta version). I can't rename the packagename, because I use guice and it get's crazy :\ – narancs Jan 07 '14 at 14:56