Publishing same app but two versions - android

Hi I wish to publish on play 2 similar apps but one with commercials and other one for money. How do I approach to this?
Do changing applicationId in gradle will be enough? Due to that play store not allowing same package names...
Please give me any tips how to arrange this in Studio and how to publish it.

You can define the flavors in your build.gradle file.
apply plugin: 'com.android.application'
android {
defaultConfig { ... }
signingConfigs { ... }
buildTypes { ... }
productFlavors {
demo {
applicationId "com.buildsystemexample.app.demo"
versionName "1.0-demo"
}
full {
applicationId "com.buildsystemexample.app.full"
versionName "1.0-full"
}
}
}
More info here.

flavors solves this problem. I think the link will help.

Related

Make Android build variants with different package and application id

Dears I want to make every build variant with a separated package name and application id because i need to upload app to google play testing env but i can't becuase of it's have project same package for published app on store
you don't need to change the package name, you can add a suffix to each variant like this in app/build.gradle:
debug {
...
applicationIdSuffix = ".debug"
}
anotherFlavor {
...
applicationIdSuffix = ".another"
}
or you can change the application id like this :
debug {
applicationId "com.app.debug"
}
In app/build.gradle, you setup
productFlavors {
dev {
dimension 'api'
applicationId "com.abc.dev"
targetSdkVersion 29
}
production {
dimension 'api'
applicationId "com.abc"
targetSdkVersion 29
}
}
Refer: enter link description here

Upload apk to existing play store project after adding flavors

I want to upload a new version of my app, but I can't because I added flavors so the package name has changed from:
com.myapp.android
to
com.myapp.android.flavor1
Inside my build.gradle:
productFlavors {
main {
applicationId 'com.myapp.android'
versionName '1.0'
versionCode 4
}
flavor1 {
applicationId 'com.myapp.android.flavor1 '
versionName '1.0'
versionCode 5
}
}
If I change the applicationId of flavor1 to 'com.myapp.android' I get this error:
Error:Execution failed for task ':app:processMainDebugGoogleServices'.
No matching client found for package name 'com.myapp.android'
So my question is, should I try to fix that error (and if yes how?) or is there any other work around ?
I haven't tried this, but reading the docs it seemd that just taking "applicationId" out of both flavor sections (main and flavor1) should work fine.
The new applicationId should be in your google-services.json as well.

get App name in gradle.build

Hi I have a common module for two apps,and I want to add a dependency in that common module if I am running on a certain app,I tried the code below,but that didn't work.
if (project.getName() == 'MyApp')
{
compile 'com.facebook.react:react-native:0.49.5'
}
Any help is appreciated.
This post Might be helpful for you. It sounds like creating different product flavors is an option for creating dependency conditions.
Update:
Adding examples of productFlavors from android studio documentation
android {
...
defaultConfig {
minSdkVersion 8
versionCode 10
}
productFlavors {
flavor1 {
applicationId "com.example.flavor1"
versionCode 20
}
flavor2 {
applicationId "com.example.flavor2"
minSdkVersion 14
}
}
}
dependencies {
flavor1Compile "..."
...
flavor2Compile “...”
}
If this isn’t sufficient for your needs you could always have your dependencies rely on external project dependencies, an example from the above post I mentioned is here:
dependencies {
compile "com.squareup.leakcanary:leakcanary-android"+(project.ext.has("leakCanary")?"":"-no-op")+":1.3.1"
}

Create separate apk for separate flavor in android

I have used build.gradle(app) to create different flavors of apk.
But installing different flavors of same apk overrides the previous one.
I want to create different apks to run on same device simultaneously.
I want to create different apk with different appicon which can be installed on same device and run simultaneously.
Any link or tutorial or direct help is appreciated.
Thanks in advance.
Change the PackageName of the flavor
Sample Gradle File
apply plugin: 'com.android.application'
android {
lintOptions {
abortOnError false
}
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
buildTypes {
debug {
minifyEnabled false
zipAlignEnabled true
}
release {
minifyEnabled true
zipAlignEnabled true
}
}
productFlavors {
Flavor1 {
applicationId "com.falvor.one" //This is where you change the package name
}
Flavor2 {
applicationId "com.falvor.two"
}
}
}
Flavor Hierarchy in Android
- src/main/java
- src/flavor1
--------------Java
----------------Your java files
--------------res
----------------Drawable
src/flavor2/java
For more understanding, follow this link
You need to create new productFlavors in your gradle file, like this;
productFlavors {
Flavor1 {
applicationId 'com.project.fl1'
signingConfig signingConfigs.xx
versionCode 1
}
Flavor2 {
applicationId 'com.project.fl2'
signingConfig signingConfigs.xx
versionCode 1
}
Flavor3 {
applicationId 'com.project.fl3'
signingConfig signingConfigs.xx
versionCode 1
}
}
The important thing here is to give each one a unique applicationId, they can then be installed on the same phone.
This post explains exactly how to achieve what you want step by step.
Most importantly:
add the product flavours container to the app build.gradle file
productFlavors {
free {
applicationId "antoniocappiello.com.buildvariantsexample.free"
}
paid {
applicationId "antoniocappiello.com.buildvariantsexample.paid"
}
}
create inside src a directory with the exact name of the product flavour that you want to look different from the main variant, for example with the configuration at step 1 the directory name could be paid or free . And inside that directory create the subfolder res/drawable where you are going to place your new app launcher icon.
Directory structure example

Android Studio 1.0 and error "Library projects cannot set applicationId"

After updating Android Studio to 1.0, I see this error:
Error: Library projects cannot set applicationId. applicationId is set
to 'com.super.app' in default config.
I updated the Gradle plugin as suggested but I did not understand how to fix this.
Based on this info:
ApplicationId in Library Projects
You cannot use applicationId to customize the package of a library project. The package name has to be fixed in library projects (and specified as packageName in the manifest). The Gradle plugin did not enforce this restriction earlier.
Removing applicationId variable from the library's build.gradle file should resolve the issue.
Thanks to Joel for his correct answer: I need to remove only 1 line from te .gradle file:
defaultConfig {
applicationId "com.super.app" <---- remove this line
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
becomes
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
and my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.super.app">
...
This is the right solution if you don't need to rename the package name of your app. To rename it you need to use "flavours":
android {
...
productFlavors {
flavor1 {
applicationId 'com.super.superapp'
}
}
Libraries can't set applicationId and if you are working in a multi-module project and picking up flavors from a separate file , none of the above answers will work. For a modularized app, you need the following steps -
Create a flavors.gradle file in project root directory
ext.flavorConfig = { // 1
flavorDimensions "pricing"
productFlavors {
free {
dimension "pricing"
ext.myApplicationIdSuffix = '.free' // 2
}
paid {
dimension "pricing"
ext.myApplicationIdSuffix = '.paid'
}
}
productFlavors.all { flavor -> // 3
if (flavor.hasProperty('myApplicationIdSuffix') && isApplicationProject()) {
flavor.applicationIdSuffix = flavor.myApplicationIdSuffix
}
}
}
def isApplicationProject() { // 4
return project.android.class.simpleName.startsWith('BaseAppModuleExtension')
}
In 1 we export a closure so that we can use it in our modules’ build.gradle files.
In 2 we define a custom myApplicationIdSuffix property. We cannot simply have applicationIdSuffix as it is not possible to use it in library modules (build would fail if you did).
In 3 we iterate over created flavors and set applicationIdSuffix if we detect that it’s an application module only.
4 is a way to check where this closure is being used.
All that’s left is to use this closure in our modules’ build.gradle files. E.g. in application module this would look like this:
apply plugin: 'com.android.application'
apply from: "${rootProject.projectDir}/flavors.gradle"
android {
// other config...
with flavorConfig
}
If this isn't clear, you can check out this article for better understanding.
Just incase it helps some one :
When i imported an eclipse project into android studio,i got an error ::
"Error:Application and test application id cannot be the same"
Strange though,but i looked into the build.gradle and found the two placeholders,one for the application and other for testapplication.
I removed the testApplicationId from that as is suggested in this post and this helped me resolve the issue.
Note: This explaination is not related to the errors posted in this question,but might help someone who is getting a similar error.
You cannot define applicationId for your lib.
But incase you want to use an identifier in your build file, which will give you, your library package name, you can define a variable for the module and then use the value as required.
eg : Library's build.gradle
apply plugin: 'com.android.library'
def libraryGroupId = 'com.google.example'
def libraryArtifactId = project.getName()
def libraryVersion = '1.1'
Also, you can use the value below as needed in your build file itself in lib.
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "$libraryVersion"
resValue "string", "Library", libraryGroupId"
}
}

Categories

Resources