user9348691
user9348691

Reputation: 34

How to change applicationId without changing packagename?

Is there any way to change applicationId without changing packagename in android studio?
As read some where i changed applicationid from flavors in project module setting. but doing this getting

Error:Execution failed for task ':app:processDebugGoogleServices'.
> No matching client found for package name 'com.myapplicationid' 

Is there any idea how to do this?

and my gradle is after changing flavor

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId 'com.myapplicationid'
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
    sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
    productFlavors {
    }
}

dependencies {
....
}
apply plugin: 'com.google.gms.google-services'

Upvotes: 0

Views: 4022

Answers (4)

Teddy
Teddy

Reputation: 11

2 steps to answer your question:

  • Change applicationId in your app gradle to the new one
  • Change package_name of google-services.json to the new one

If you got an error No matching client found for package name... when doing so, then just try steps as follows and it worked for me:

  • Remove apply plugin: 'com.google.gms.google-services' out of your app gradle.
  • Sync Project with Gradle File -> Clean build
  • Make sure if your applicationId is valid
  • Change your applicationId to the new one to make sure it works without errors while built.
  • Add apply plugin: 'com.google.gms.google-services' to your app gradle again
  • Change package_name of google-services.json to the new one like step 3
  • Build successfully

Upvotes: 1

Natig Babayev
Natig Babayev

Reputation: 3305

You can set applicationId from defaultConfig and remove productFlavors from build.gradle file (I've tested, it should work):

apply plugin: 'com.android.application'
android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.myapplicationid"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
    sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
}

dependencies {
....
}
apply plugin: 'com.google.gms.google-services'

If you look carefully, I removed

productFlavors {
}

part

Also, don't forget to update the google-services.json

Upvotes: 1

MJM
MJM

Reputation: 5311

You can declare different applicationId like this

 android {  
      flavorDimensions "Flavors1"
            productFlavors {
                Flavors1{
                    applicationId "com.myapplicationid1"
                           }

                Flavors2{
                    applicationId "com.myapplicationid2"
                           }
            }
    }

If you want to change the applicationId just update in defaultConfig

 defaultConfig {
        applicationId "your_new.id"
}

Don't forgot to update the google-services.json if you have used

Upvotes: 1

Ahmed
Ahmed

Reputation: 305

You can declare multiple Flavors for your application like this

productFlavors {
    MainApp {
        applicationId = "com.company.app"
    }
    NewAppFlavor {
        applicationId = "com.company.newapp"
    }
}

and build your application and sign using this flavor and you can change between different flavors via build variants option in android studio

Upvotes: 1

Related Questions