I have followed Google's official doc for creating multiple APKs for different API levels. (I know it is not recommended to have different APKs, however in my specific case I must use it).
The only difference between the two APKs in my case would only the AndroidManifest.xml files content. While reading through the official doc which recommends creating a shared library between two different apps modules, I wondered whether it is going to be possible to achieve the same through different flavors in Gradle's build setting, specifying a different AndroidManifest.xml file for each flavor and thus generating two APKs with different manifests (the idea came from this post).
Since creating two flavors is much simpler (time and maintenance wise), and my only need is two different manifests files, isn't this a better option than the suggest common library module shared between two different app modules?
You should check about Product flavors
A product flavor defines a customized version of the application build
by the project. A single project can have different flavors which
change the generated application.
Structure
android {
productFlavors {
dev {
applicationId "root.com.android.dev"
}
product {
applicationId "root.com.android"
}
}
}
You can read also
Product flavors in Android Studio for hermetic testing
Related
I have an android app in use by several clients, when I build the app currently I have 2 options 1. release and 2. debug
Now my problem is some om my clients require certain features others do not, meaning that for the same app some features might be disabled for some clients while other clients would have extra features.
I would like to know how I can have more than one release option when building my app. eg.
ClientARelease
ClientBRelease
ClientCRelease
ClientADebug
ClientBDebug
ClientCDebug
So if Client A wants all features of the app but client B does not when I select ClientBRelease the features not required by ClientB are not bundled with the apk.
How do I achieve this with android?
You should use Android Build Types and Build Flavors. Check out Android Developer Guide
Each build variant represents a different version of your app that you can build. For example, you might want to build one version of your app that's free, with a limited set of content, and another paid version that includes more. You can also build different versions of your app that target different devices, based on API level or other device variations.
Creating product flavors is similar to creating build types: add them
to the productFlavors block in your build configuration and include
the settings you want.
In some cases, you may want to combine configurations from multiple
product flavors. For example, you may want to create different
configurations for the "full" and "demo" product flavors that are
based on API level. To do this, the Android plugin for Gradle allows
you to create multiple groups of product flavors as flavor dimensions.
When building your app, Gradle combines a product flavor configuration
from each flavor dimension you define, along with a build type
configuration, to create the final build variant.
Also for some cases you can use APK splitting/AppBundle.
I am still working with Eclipse to develop android applications. Now there is a situation where I am supposed to build 2 different applications (You can consider as free and non-free version apk) using same app-code. I have got thousands of links regarding build.gradle and application package-name and others on google, but I don't how to build/use it in Eclipse.
Another question I have is how to point to 2 different images
based on different application.?
If you want to release two different build (paid and free). You need to change the package name. Just goto the manifest file.
For example: for free version
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.free">
and similarly for paid version
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.paid">
Alternatively, I will recommend you to use In app purchase feature and release only build
Try this.. Is there any way to integrate Eclipse with Gradle in Android project?.. There is no simple answer for this question.. Either you use eclipse with gradle and set two flavours with different in your build.gradle
productFlavors {
free {
applicationId 'your.package.name.free'
}
paid {
applicationId 'your.package.name.paid'
}
}
or else just copy your project twice and change package name. If you want to upload both your apps in play store then you need two different package names.
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.
I have an Android app that will be distributed in two (or more) brands. All java code for each distributions is exactly same, just different assets/resources (like layouts, drawables, dimensions, etc)
What is the best way to organize the project? I am using Git for version control, and trying to keep all distributions developed as a single project. So I can switch asset/resource sets easily for different branding each time needed.
Is there a good approach for it?
One good approach would be turning your main project code in a library and then, for the other projects (brands), import that library and override the assets as you want.
Gradle Build Variants allow you to have a shared main codebase/resources and multiple variants with custom resources/code associated with each - you then can generate a separate APK for each variant. Of course, using Gradle for Android development requires you use Android Studio (which is currently in beta) as well.
As mentioned above, Gradle Build Variants is the best way to handle this. We have 11 variants (and counting) where the only difference are some configuration values. I organized the project as follows:
app/src/configurations/
flavor1/
common/res/...
release/res/...
stage/res/...
where the common directory holds configurations common to that build variant and the release and stage hold custom values for our release and staging versions (they have slightly different configurations as well).
All configurations common to all build variants live in the normal app/src/main/res folder.
Then in the app's build.grade, I have each product flavor defined:
productFlavors {
flavor1 {
applicationId = "com.example.flavor1"
}
flavor1stage {
applicationId = "com.example.flavor1stage"
}
// etc. for each build flavor
}
android.sourceSets.flavor1 {
res {
srcDirs = ['src/configurations/flavor1/release/res', 'src/configurations/flavor1/common/res', 'src/res']
}
}
android.sourceSets.flavor1stage {
res {
srcDirs = ['src/configurations/flavor1/stage/res', 'src/configurations/flavor1/common/res', 'src/res']
}
}
I worked with iPhone Xcode Traget to create multiple iPhone apps with single code base. My question, is it possible to create multiple targets for Android project. If yes, is it possible with Eclipse?
Edit:
Xcode Target: A single Projects can contain one or more targets, each of which produces one product (App). This has always only one Project in which we can select the specific target and run desired app
iPhone have only one Project for many products (App1, App2, App3 etc), Now can I have same as this, one Android Project and multiple products (App1, App2, App3 etc)
Thanks in advance
A bit late, but for those who still looking for solution:
Gradle Build System uses a Build Variant and combination of product flavors to generate different apps with shared/common code base and resources.
As per Android Developer Reference Site:
The build system uses product flavors to create different product versions of your app. Each product version of your app can have different features or device requirements. The build system also uses build types to apply different build and packaging settings to each product version. Each product flavor and build type combination forms a build variant. The build system generates a different APK for each build variant of your app.
Now one can have two or more product flavors e.g (paid flavor, free/demo flavor) etc for one single project with same code base.
For more information See Build Variants & Product Flavors Doc
After a wide research I realized Android Library Project will provide solution for my requirement
An Android library project is a development project that holds
shared Android source code and resources. Other Android application
projects can reference the library project and, at build time, include
its compiled sources in their .apk files. Multiple application
projects can reference the same library project and any single
application project can reference multiple library projects.
Note: You need SDK Tools r14 or newer to use the new library project
feature that generates each library project into its own JAR file. You
can download the tools and platforms using the Android SDK and AVD
Manager, as described in Adding SDK Components.
• If you have source code and resources that are common to multiple
Android projects, you can move them to a library project so that it is
easier to maintain across applications and versions. Here are some
common scenarios in which you could make use of library projects:
• If you are developing multiple related applications that use some of
the same components, you move the redundant components out of their
respective application projects and create a single, reuseable set of
the same components in a library project. If you are creating an
application that exists in both free and paid versions. You move the
part of the application that is common to both versions into a library
project. The two dependent projects, with their different package
names, will reference the library project and provide only the
difference between the two application versions.
There is only one build target in android in a single project. Backword compatibility is controlled at install time using minSdkVersion, targetSdkVersion and maxSdkVersion in the manifest file
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
Also android market make sure that if your app has native code and is built for ARM architecture it is not visible on a x86 device
You can control what version someone has installed and starting one activity or another depending on that. You can use something like this:
private static boolean version= android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.HONEYCOMB;
And then do something like:
public void onCreate(Bundle savedInstanceState){
Intent startActivity =null;
if(version)
startActivityIntent = new Intent( this, newVersionActivity.class );
else
startActivityIntent = new Intent( this, oldVersionActivity.class );
finish();}
This example is from a video of the Google I/O (min 5~): http://www.google.com/events/io/2011/sessions/android-protips-advanced-topics-for-expert-android-app-developers.html.
So you are supposed to specify the minSdkVersion and the maxSdkVersion and then control what which activity to start.