Generate multiple APK from one single project - android

I'm trying to understand how i can generate multiple APK from one single project.
I'm using gradle and this is my project's three:
ambrogiocore is the core library module that implements all the common classes and resources.
ambrogioremote is the module that has the :ambrogiocore dependence.
It's work. Now i'm able to generate multiple APK. (just one at the moment)
One apk for each module.
The problem is that i need to manually sync all the AndroidManifest.xml for every future module that i'll include in my project.
Is this the correct way?
Can i automate this operation?
I took a look at productFlavor. Just I don't understand if this tool can help me.
What do you think about?
THANK YOU ALL!
**SOLUTION**
Finally! I found the same solution proposed by #Kai!
Flavor is the way!
This is the best approach for a lots of reasons:
Single-module project
You don't need to copy XML files
RoboGuice will work like a charm. (RoboGuice presents some BIG problem on library projects)
http://www.techotopia.com/index.php/An_Android_Studio_Gradle_Build_Variants_Example

If by "one single source core and multiple project that extends "ProductName", "PackageName" and "resources"" you mean to provide each flavor with unique "ProductName", "PackageName" and "resources", then yes it can be done.
To give each flavor its own unique package, set applicationId for each of your flavors like so:
android {
productFlavors {
flavor_1 {
applicationId = 'com.app.flavor_1'
}
flavor_2 {
applicationId = 'com.app.flavor_2'
}
}
}
To give each flavor its own app name and resources, simply put them in a flavor's own directory, Gralde will merge a flavor's resources with your base resources to create a complete one.
For more detail on how Gralde flavors work, please see Gradle Plugin User Guide

This is my final solution!
All the common files, manifest and base resources are under "src/main"
I moved my projects inside "src/projects"
declared two productFlavor (one per project) specifying applicationId and versionName
created two sourceSet (one per project) indicating the specific res folder.

Related

How to merge two different projects that are already in playstore using flavors

The problem i am facing is there is two project(apps) similar and there will be more in future and when i change a code in one i will need to do same changes in other projects. when i searched on web i found product flavors but not sure if it's the answer for my problem.
How can i merge two different projects (apps) in playstore. Projects codes are %85 similar can i use flavors to merge both project in one and will i be able to update them in playstore using different jks with different package names and a few different permissions. Will i need AndroidManifest file for each flavor.
How can i solve this problem. Thanks
To change packageName you have to create product Flavor like
flavorDimensions "versionCode"
productFlavors {
doctorApp {
dimension "versionCode"
applicationId "com.doctor.app"
}
patientApp {
dimension "versionCode"
applicationId "com.patient.app"
}
}
After that create two sibling folder of main after switch project View to Project
app -> src -> main /// write all common classes here
app -> src -> doctorApp // doctor related classes here along with their resources
app -> src -> patientApp // patient related classes here along with their resources
create same package name and res folder under patientApp and doctorApp

How can I have a different package name for debug and release in a library module?

Short question:
How can I change the package name for debug or release build type in a library module?
Context:
In an Android project with MVP + Clean architecture, we have the repository pattern in a library module. We want to include Firebase on that library with two environments (development and production).
I already created the project in Firebase (com.example.com and com.example.com.dev) and then downloaded the respective google-services.json to src/main and src/debug folders.
Gradle google-services plugin validates the module package name with the client ID defined in the google-services.json, but Android restrict to change the applicationId in a library (I can't find the technical reason why)
Things that I tried:
Have two AndroidManifest.xml with different package property. com.example.com in the src/main and com.example.com.dev in src/debug/ but the second one it is just ignored
Set manifest.srcFile in Gradle sourceSets. The file is in the list when I run ./gradlew sourceSets but the package name doesn't change
Two different flavors in the library module and set different manifests for each one. The package anyway doesn't change.
At this moment I have just two suitable solutions:
1. Keep the Firebase setup and implementation in the app module outside of the repository.
2. Have only one environment for Firebase.
Thanks a lot for any help or advice.
EDIT:
Consider that I need to modify the package in a module (library), not in the app. For some weird reason Gradle shows this error when I try to use applicationIdSuffix or applicationId in a module:
ERROR: Library projects cannot set applicationIdSuffix.
Library projects cannot set applicationId.
This is the designed behaviour of Android Library project.
Two different flavors in the library module and set different
manifests for each one. The package anyway doesn't change.
Probably you need to change your Build Variants to that particular flavor/buildtype then you can see the updated package name taking effect.
See below screenshot.
I spent some time investigating and trying different alternatives to achieve two different package name per flavor or build type in a library module, and my short answer is: You can't, at least without doing something tricky and dirty.
Some guys that recommend using the parameter applicationIdSuffix or applicationId, that option doesn't work because of the design of library modules restricts those parameters to the app module. In a library, the package must be defined in the manifest.
That restriction delimits options to flavors, but, the package attribute in the manifest isn't merged, and you get an error when having different package name for the scr/main/AndroidManifest.xml and src/flavor/AndroidManifest.xml.
A tricky solution is to get the currently selected flavor form the task name and then change the main manifest in the sourceSets.
sourceSets {
main {
manifest.srcFile "src/$flavor_name/AndroidManifest.xml"
}
}
This hack works but in general is a bad idea, and I prefer to change the design of my architecture and implement the repository for both Firebase variants in a different way.
Gradle plugin: 3.2.0

How to Build different APK files using different databases in Android using Gradle tool?

We have a platform to read poetry with a SQLITE Database say SHAKESPEARE.DB .
We also have another poetry say Wordsworth.DB.
So for each poetry database we want to create a separate application like Shakespeare.apk and wordsworth.apk.
During build we want to mention the Database and mention the name of the APK.
How do we Change Database during android build through gradle and deploy different APK's
I would want to Create and Deploy Database specific APK using Gradle ?
Step #1: Use a consistent means of embedding the database in the app. For this answer, I will assume that you are using SQLiteAssetHelper, with the database packaged as words.db in assets/.
Step #2: Create two product flavors for your app in your app/ module's build.gradle file. For this answer, I will call these flavors vanilla and chocolate:
productFlavors {
vanilla {
applicationId "com.commonsware.android.gradle.hello.vanilla"
}
chocolate {
applicationId "com.commonsware.android.gradle.hello.chocolate"
}
}
(replace the applicationId values with ones more relevant to your project)
Step #3: Create a sourceset for each flavor (app/src/vanilla, app/src/chocolate/).
Step #4: Put a different words.db in assets/ of the flavor (app/src/vanilla/assets/words.db, app/src/chocolate/assets/words.db).
Now, when you build vanilla, it will use the vanilla edition of words.db. When you build chocolate, it will use the chocolate edition of words.db. No Java code changes are required. You can also put different resources in those flavor-specific sourcesets, for different icons, labels, etc. Because you have different applicationId values, both flavors can be installed on your test devices at the same time, and both flavors can be distributed through app distribution channels like the Play store.

multiple app version, 1 code base

So I have an app that would require to versions with different settings, assets etc but uses the same code base so it will generate two apks. I really have no idea how to do it in gradle. can anyone please point me to a site or a technique in which i can do this? thanks.
Start witch adding product flavors to your build.gradle script and set proper ids
productFlavors {
appOne{
applicationId 'com.app.one'
}
appTwo{
applicationId 'com.app.two'
}
}
When that's done create folders in your src directory called
appOne and appTwo. In those folders you can specify version specific stuff like drawable folders, manifest...
When that's done, remember to choose right build variant in buildvariants menu

Different Android Builds For Different Environments

I'd like to be able to build and install multiple versions of my app (concurrently), targeting different environments such as Development, Staging and of course Production.
The package name in the AndroidManifest.xml seems to be the major hurdle here, as it is what uniquely identifies the app. I thought it would be possible to simply switch between com.mydomain.prod, com.mydomain.staging and com.mydomain.dev or some sort of similar convention but so far I've had no luck coming up with a package structure that works for this approach.
What strategy can I employ to do this with as little pain as possible?
With Gradle you can specify different "flavors" of your application. This is done in your build.gradle:
android {
// …
defaultConfig {
// …
}
productFlavors {
prod
applicationId "com.mydomain.prod"
}
staging {
applicationId "com.mydomain.staging"
}
dev {
applicationId "com.mydomain.dev"
versionCode 2
}
}
}
Each flavor properties are inherited from defaultConfig.
Now, in the src directory of your app, you can create directories with flavor-specific code/resources in it:
app/
|-- src/
|-- main/
|-- prod/
|-- staging/
|-- dev/
These links might be useful:
How to build customized Android application using Gradle
Gradle Build Variants for your android project
I suggest you use the 'ant' build tool specificaly the 'regexp' task which can be used in order to replace text in certain files (i.e replace your app's package name in the manifest file according to the proper build target). You can also define differnet properties file for each build target (e.g 'build_development.properties' to hold all parameters relevant for building your product for development env.)... hope this is helpful..

Categories

Resources