Two android manifests in one flavor - android

I'm trying to build an app with platform-independent activities, but I also need to build an app that is multiplatform. So, I created the config:
sourceSets {
getByName("any") {
// How to add here two manifests: mobile and tv?
manifest.srcFile("src/platform/any/AndroidManifest.xml")
java.srcDirs("src/platform/any/java")
kotlin.srcDirs("src/platform/any/java")
res.srcDirs("src/platform/any/res")
}
getByName("mobile") {
manifest.srcFile("src/platform/mobile/AndroidManifest.xml")
java.srcDirs("src/platform/mobile/java")
kotlin.srcDirs("src/platform/mobile/java")
res.srcDirs("src/platform/mobile/res")
}
getByName("tv") {
manifest.srcFile("src/platform/tv/AndroidManifest.xml")
java.srcDirs("src/platform/tv/java")
kotlin.srcDirs("src/platform/tv/java")
res.srcDirs("src/platform/tv/res")
}
}
The problem is that the manifest file in any must be always a merge of mobile and tv manifest files. For now, I have the third manifest file. But sometimes developers forget to add needed activity or receiver to any manifest file and any build may be broken or vice versa.
Is there any solution to this?

Related

Can I have different classes (using flavors) in a library module for different application modules?

I have two applications: Application Module A and Application Module B. They both use Library Module X.
Inside Library Module X I have some different behaviors depending of which app is using the library. I thougth about three alternatives to anchieve that.
1º Hardcoded mentioning the applications. someClass would be injected by the application or just check the package. (The worst one I think):
if (someClass.isApplicationA()) {
doThis()
} else {
doThat()
}
2º Hardcoded mentioning what is about to be done. someClass would be injected by the application. (I don't like it to much either):
if (someClass.shouldDoThis()) {
doThis()
} else {
doThat()
}
3º Using flavors. I would define a flavor A for Application Module A and a flavor B for Application Module B. In Library Module X I would define both flavors. So I would put the custom code in some specific classes that have different versions for each flavor.
customClassByFlavor.justDoIt()
Everywhere I only see flavors been used for a single application. Is this a correct use of it?
The elegant way to achieve this is
Ask the app to specify a identifier / key in their manifest
Ask the app to specify a variable in their build.gradle file
defaultConfig {
resValue "string", "identifier", "identifierConstant"
}
Use the variable in you app, like you acesss a string constant
context.getString(R.string.identifier);
Pick the package name of app from default applicationId in build.gradle file
defaultConfig {
applicationId "com.google.example"
}

Conditionally include meta-data in Android manifest file

Is there way to conditionally include meta-data element in Android manifest file based on value set in Gradle. I am able to do following (using resValue to set <some_value> in build.gradle) but haven't been able to find way to include/exclude complete meta-data element.
<meta-data
android:name="<some_setting>"
android:value="#string/<some_value>" />
Somewhat of a hack but only way I've been able to address this is by having something like following (have changed names in example) in build.gradle (am using this in context of having different build flavors as well but isn't dependent on that)...I think there's probably some additional smarts that can be done around manifest merging that would make this a bit cleaner as well. myFlag is coming from a project.hasProperty() value I'm passing in as part of Fastlane script
sourceSets {
flavor1 {
if (myFlag == "true") {
manifest.srcFile "src/flavor1_flag/AndroidManifest.xml"
} else {
manifest.srcFile "src/flavor1/AndroidManifest.xml"
}
}
}
<meta-data android:name="string"
android:resource="resource specification"
android:value="string" />

Android-studio. I have 1 apk working. need to make 3 different app´s. for 3 local tablets

I have 1 simple apk working. (it is not for the internet)
I can changes pictures and text in my apk.
I can copy (unsigned)apk to my phone and it works.
it runs in debug mode.
Question.
I need to make 3 different app´s with 3 different names. For example app1 app2 and app3. The wireframe/design will be identical but pictures and text will be different.the different app´s should be updated (only pictures and text stings) for each app.
I want create three unique apps from here. three different application ID´s (i think)
All 3 should be able to run and be updated on same device.
Is it flavors I shall use?
or can I create and rename into 3 project (three unique app´s)? I would prefer this.
You should use gradle product flavours. For example, go to your app's build.gradle file (find module level file, not top/project level) and inside android { ... } section add following lines:
productFlavors {
flava {
applicationIdSuffix ".flava"
}
flavb {
applicationIdSuffix ".flavb"
}
flavc {
applicationIdSuffix ".flavc"
}
}
That way, you will generate apk with three different package names. So, if your default package id (or, how gradle call it, application id) is com.myapp, you will get three apks with ids com.myapp.flava, com.myapp.flavb and com.myapp.flavc.
The gradle build command should generate all three apks. Or, if you are building and pushing the app from Android Studio, open "Build Variants" panel and choose flavor you'd like to push on a device.

Android how to manage project name and logo and application icon for different clients

As per need i need to manage one project for different clients in which i usually need to change application icon, app name and client logo. what is the efficient way to handle this??
I have read about properties file in the Android but that does provide option to change application icon and name.. it there any why to handle this.
To achieve this you will to have use flavour in your project, if you are using Android studio add the following code in your build.gradle file.
productFlavors {
flavor1 {
applicationId "com.app.client1"
}
flavor2 {
applicationId "com.app.client2"
}
}
Then create directory structure like
flavor1>res>drawable-XXX>ic_launcher.png (app icon for client1)
flavor2>res>drawable-XXX>ic_launcher.png (app icon for client2)
For more you can refer to this blog http://www.pcsalt.com/android/product-flavors-android/
You can create Multiple flavor for multiple vendors like this:
Here is a syntax for gradle
productFlavors {
flavor1 {
packageName 'com.android.studio.test.foobar'
}
}
You can also put variable to make changes in app according to flavor

Android application with two packages

I do an application in two versions: premium and free. Now for me the functional of premium version works after verification of:
if (isPremiumVersion){
//to do premium fuctions
}.
But I do not think that it is good tone. How is it possible to divide these two versions, that they were independent of each other? Only at the start of application to do verification, and then already, for example, to start the certain manifest file with a certain package, and classes. Unfortunately, does not turn out to find material, how more correct to do it.
What you need is Product flavors.
You can define them in build.gradle:
android {
....
productFlavors {
free {
applicationId 'com.myapp.free'
}
premium {
applicationId 'com.myapp.premium'
}
}
}
For each product flavor you can create it's own source set by creating directory with name of flavor in app src directory so your app structure will be like:
src/
main/
free/
premium/
You can add customized AndroidManifest.xml, resources and sources in flavor source sets and they will be merged with main source set.
You should carefully read official documentation at link I mentioned above. There much more possibilities and details then I described here.

Categories

Resources