How to install two separate versions of an app from android studio? - android

I am working with the Firebase chat project from github.
I am trying to make 2 apps, one client-side and one admin-side.
I have two copies of the project with different project names and different app names.
Still, I can't run both on the same device with android studio. Running one requires uninstalling the other.
I understand it might be a pretty basic thing, but any suggestions?
Thanks

what you need to do is change package name on App Build.Gradle, find applicationId and change one of your project package name
hopefully it works

In your app level build.gradle file under android tag define different product flavors for different app.
Please find the below code and do changes according to your project.
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
flavorDimensions "default"
project.archivesBaseName = "Visualogyx";
signingConfigs {
release {
storeFile file(System.getenv('KEYSTOREPATH'))
storePassword System.getenv("VISUALOGYX_KEYSTORE_PASSWORD")
keyAlias System.getenv("VISUALOGYX_KEYALIAS_NAME")
keyPassword System.getenv("VISUALOGYX_KEYALIAS_PASSWORD")
}
}
defaultConfig {
applicationId "com.visualogyx.app"
minSdkVersion 16
targetSdkVersion 26
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
signingConfig signingConfigs.release
ndk {
abiFilters "armeabi-v7a"
}
}
lintOptions {
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
dexOptions {
javaMaxHeapSize "4g"
jumboMode true
}
productFlavors {
dev {
versionCode 778899
versionName "v.1.1.BUILD_NUM"
applicationIdSuffix ".dev"
resValue "string", "app_name", "VisualogyxDEV"
buildConfigField "String", "HOST", System.getenv("VISUALOGYX_HOST_DEV")
}
qa {
versionCode 778899
versionName "v.1.0.BUILD_NUM"
applicationIdSuffix ".qa"
resValue "string", "app_name", "VisualogyxQA"
buildConfigField "String", "HOST", System.getenv("VISUALOGYX_HOST_QA")
}
pro {
versionCode 778899
versionName "v.1.0.BUILD_NUM"
resValue "string", "app_name", "Visualogyx"
buildConfigField "String", "HOST", System.getenv("VISUALOGYX_HOST_PRO")
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "Visualogyx-${variant.baseName}-${variant.versionName}.apk"
}
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/XXX'
}
}
Hope it works.Thanks.

Related

how to add different flavours of same application(want to clone the application) with differnt google-services.json file in android project?

I want to clone my android app and launch it with a different name and a fresh new database in a different region, I don't want to write the code all over again or make a duplicate copy of the project. i used productFlavour{} in my build.gradle file in project, but i couldnt get it right.
flavour1 {
dimension 'default'
applicationId "com.example.flavour1"
}
flavour2 {
dimension 'default'
applicationId "com.example.flavour2"
}
I am getting this error that says
No signature of method: build_7epdrck7cjxe08sh65acsfob0.android() is applicable for argument types: (build_7epdrck7cjxe08sh65acsfob0$_run_closure1) values: [build_7epdrck7cjxe08sh65acsfob0$_run_closure1#29754fbc]
I also created two folders under my project src/ root folder with the same names of flavour1 and flavour2 and added their respective google-service.json file. but it's not working.
am I doing anything wrong?
this is my whole gradle file code except dependencies
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.example.scs"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
debuggable false
jniDebuggable false
renderscriptDebuggable false
pseudoLocalesEnabled false
zipAlignEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
productFlavours{
flavour1 {
dimension 'default'
applicationId "com.example.flavour1"
}
flavour2 {
dimension 'default'
applicationId "com.example.flavour2"
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
aaptOptions {
cruncherEnabled = true
}
}
any help or suggestion is greatly appreciated.
thanks in advance.

How to configure product flavor in new gradle

I am configuring paid and free version of my app and I got below error. I already configure same before android 3 without problem.
How to fixe it please ?
Gradle script
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "capstone.nanodegree.udacity.com.mypodcast"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
//flavorDimensions "default"
flavorDimensions "free", "paid"
productFlavors {
free {
applicationId "capstone.nanodegree.udacity.com.mypodcast.free"
dimension "free"
}
paid {
applicationId "capstone.nanodegree.udacity.com.mypodcast.paid"
dimension "paid"
}
}
}
def AAVersion = '4.4.0'
def GLIDEVersion = '4.3.1'
def supportVersion = '26.1.0'
Check that there's entries for both packages in your google-services.json .....also, and this might be separate issue, I believe you should only have to define one dimension (both your flavors would have same dimension value)
I am using Flavors same as you, I'll remove 2 of my flavors and rename for simplicity comparisons:
compileSdkVersion 26
buildToolsVersion googleBuildTools
dataBinding {
enabled = true
}
defaultConfig {
applicationId "com.myapp"
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
signingConfigs {
releaseMyApp {
storeFile file("$projectDir/../myappkeystore.jks")
storePassword System.getenv('MYAPP_STORE_PASSWORD')
keyAlias System.getenv('MYAPP_KEY_ALIAS')
keyPassword System.getenv('MYAPP_KEY_PASSWORD')
}
}
productFlavors {
myapp {
applicationId "com.myApp.one"
buildConfigField "String", "SERVER_URL", '"https://api.myappone.com"'
versionCode 24
versionName "1.18"
minSdkVersion 21
}
myappStaging {
applicationId "com.myapp.one.staging"
buildConfigField "String", "SERVER_URL", '"https://stg.api.myappone.com"'
versionCode 24
versionName "1.18"
minSdkVersion 21
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
productFlavors.myapp.signingConfig signingConfigs.releaseMyapp
productFlavors.myappStaging.signingConfig signingConfigs.releaseMyapp
}
}
without issues, but i'll post in case there is something different that you notice that I didn't, but your error is probably related to your firebase json. You can use the same json file for all your flavors, you just need a client section for each application identifier. which you can create online through firebase portal.
I made the mistake of making individual firebase json files for each flavor and later figured out I didn't need to do that as they were all identical with all clients in them.
Originally I only used flavors for two different application types, but later had to make flavors for staging as well to support PUSH in multiple environments. Goodluck. Hopefully that helps, but I'm guessing you need to fix your firebase json file.

App with two flavors generate the same key hash

I have two apps from the same project with two different flavors, they have Facebook sign-in, one of them is published and working fine, the problem is with the other flavor, every thing is working fine in debug, but when i try to login with facebook in release i got invalid key hash, the key hash doesn't match...
I tried re-generating the key hash many times, even with differnt keystore, but i have the same result, I even tried copying the key hash in the error message with no luck.
Then I compared the key hash with the published app's key hashes in facebook console, and it was there.
My question is why the two flavors have the same key hashes even they have different package names and facebook ApplicationIds in different manifest files ?
This is my build.gradle
android {
signingConfigs {
release {
keyAlias 'alias'
keyPassword '********'
storeFile file('keystore.jks')
storePassword '********'
v2SigningEnabled false
}
}
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
flavorDimensions "app"
productFlavors {
A {
dimension "app"
applicationId "com.app1"
versionCode 12
versionName '1.12'
resValue "string", "app_name", "App1"
resValue "string", "facebook_app_id", "1**************7"
resValue "string", "fb_login_protocol_scheme", "fb1**************7"
}
B {
dimension "app"
applicationId "com.app2"
versionCode 0
versionName '1.0'
resValue "string", "app_name", "App2"
resValue "string", "facebook_app_id", "1**************5"
resValue "string", "fb_login_protocol_scheme", "fb1**************5"
}
}
Your using the same signing configuration for both variants with the same keystore, please different keystore for each variant.

Building Different APK with different flavors

I want to be able to build same app with different package name. My current approach is using flavor (build variant). This works fine except that app built on different flavors replaces the other one on the device. What i want to achieve is building this same app with different flavors and not replacing same app on the same phone built with another flavor. Below is a snippet of my current approach. How can i achieve and am i doing anything wrong?
buildTypes {
release {
applicationIdSuffix ".release"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
}
}
flavorDimensions "flavor"
productFlavors {
flavor1 {
flavorDimension "flavor"
applicationId
"com.eample.flavor1"
versionName "1.0"
}
flavor2 {
flavorDimension "flavor"
applicationId
"com.example.flavor2"
versionName "1.0"
}
flavor3 {
flavorDimension "flavor"
applicationId
"com.example.flavor3 "
versionName "1.0"
}
}

Android gradle product flavors with wearable apps

I'm adding a wearable component to an existing app which uses product flavors in the gradle build to build multiple versions of the app.
I know the package names / application Id's need to match between the mobile and wearable builds, but do I just need to copy the
productFlavors
signingConfigs
buildTypes
from my main mobile app. I'm not quite sure if all of this is needed to get things working or not.
The productFlavors no, unless you are going to do something specific for the wear app with a particular flavor.
The signingConfigs and buildTypes you should copy, the wear app definitely needs to be signed as well. You may adapt the buildType for wear such is enable/disable minify it you want from the main app.
Here's a portion of my own mobile and wear build configs
Mobile
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "org.codechimp.qrwear"
minSdkVersion 18
targetSdkVersion 20
versionCode 26
versionName "1.20"
}
productFlavors {
prod {
}
dev {
versionName = android.defaultConfig.versionName + " dev"
}
}
signingConfigs { release }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
Wear
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "org.codechimp.qrwear"
minSdkVersion 20
targetSdkVersion 20
versionCode 26
versionName "1.20"
}
signingConfigs { release }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}

Categories

Resources