Reputation: 31
I have an application that needs to be built under multiple package names with minor changes in resources.
These changes are as simple as changing Strings.xml
, Colors.xml
, Package name in Gradle and manifest and changing icons and other resource files. All these changes can be done via the Command line easily.
The hard part that I want to automate is the package name (which is done via Refactor->Rename in Android Studio).
So, I want to change the package name via the Command line including other changes as above. I've read up the other available answers on StackOverflow and other websites but I couldn't get it working.
Upvotes: 0
Views: 1407
Reputation: 1387
An easier way to achieve that is by creating different product flavours, like so:
android {
...
flavorDimensions "version"
productFlavors {
flavourA {
applicationId "com.myapp.name"
}
flavourB {
applicationId "com.myapp.anothername"
}
}
}
Note that if you don't want to set a completely new application ID (package) to every flavour but rather just add a suffix you can do so like the following example:
flavourA {
applicationIdSuffix ".mysuffix"
}
Say your application package is com.test.myapp
. With the suffix it will be com.test.myapp.mysuffix
when you build your app with flavourA
.
Then, to build your specific flavour with command line you should do:
APK
./gradlew assembleFlavourADebug // for debug builds
./gradlew assembleFlavourARelease // for release builds
Bundle
./gradlew bundleFlavourADebug
./gradlew bundleFlavourARelease
As for your colour, string, etc. resources you can create resource files specifically for each flavour you're dealing with.
src
|
+--- main
| |
| +--- res
| |
| +--- values
| |
| +--- strings.xml
+--- flavourA
| |
| +--- res
| |
| +--- values
| |
| +--- strings.xml
|
+--- flavourB
|
+--- res
|
+--- values
|
+--- strings.xml
Upvotes: 1