Android package name - android

What is the mean of applicationId in build.gradle. and what is the difference between package name in manifest file and applicationId in build.gradle.

What is the mean of applicationId in build.gradle
Every Android app has a unique application ID that looks like a Java package name, such as com.nilu.myapp. This ID uniquely identifies your app on the device and in Google Play Store. If you want to upload a new version of your app, the application ID (and the certificate you sign it with) must be the same as the original APK—if you change the application ID, Google Play Store treats the APK as a completely different app. So once you publish your app, you should never change the application ID.
Read more about applicationId
what is the difference between package name in manifest file and applicationId in build.gradle
package specified in AndroidManifest.xml identify one application installed on the device
Read more from this answer and this also Package Name Vs Application ID

applicationId in build.gradle will overwrite the manifest file's package value. And in build.gradle file you can use productFlavors to define different flavors, and each flavor can have different applicationId.
productFlavors {
free {
applicationId "com.myapp.free"
}
paid {
applicationId "com.myapp.pro"
}
}

Related

What is the difference between Package name & App Package Name?

I'm practising Android Program with a book
and it says if the package name is same, android understand it's same app even if the project is different.
so, I changed it with Refactor.
and it also says if you want to change app package name too, then please change the application ID in build.gradle(Module:app)
what is the difference between Package name & App Package Name?(Maybe the name is wrong because I just translate it.)
Every Android app has a unique application ID that looks like a Java package name, such as com.example.myapp. This ID uniquely identifies your app on the device and in Google Play Store. If you want to upload a new version of your app, the application ID (and the certificate you sign it with) must be the same as the original APK—if you change the application ID, Google Play Store treats the APK as a completely different app. So once you publish your app, you should never change the application ID.
android {
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
...
}
Although your project's package name matches the application ID by default, you can change it. However, if you want to change your package name, be aware that the package name (as defined by your project directory structure) should always match the package attribute in the AndroidManifest.xml file, as shown here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >

Not working with package name and firebase

I have an app uploaded to the play store. The package is: com.pathapp but then with gradle are generated two apk, com.path debug and release (without app). Now I want to integrate firebase, but I do not know what name of the app is what I have to put in firebase, if com.path or com.pathapp in order to have a well constructed google-services.json file.
If I change the original package of the directories from pathapp to path, there would be a problem?
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.00"
}
}
applicationId in the gradle is your package name.
So you need to add that in the firebase console.
In the above example, the package name is com.example. Likewise, check your gradle.
If you go to the Play Store you can see the package name of your current app. Use this, or you won't be able to upload in the store.
To see the package name is linked with your Firebase, open your project in Firebase and click on Settings, here you will see the package name of the app.
If is not the same:
-There, you can see an option to add a new app. Click the button and add a new app with your new package: com.pathapp
-Finally, you have to download the new google-services.json and add it in your project, deleting the old one if you still have it.

No matching client found for package name (Google Analytics) - multiple productFlavors/application ids

I am setting up Firebase for my Android application and have run into a slight wrinkle/problem. I have multiple product flavors such as the standard dev, qa and prod. These product flavors share the same application id. However, I have one flavor where the application id is different:
productFlavors {
dev {
applicationId "com.acme.myandroidapp"
}
qa {
applicationId "com.acme.myandroidapp"
}
foo {
applicationId "com.acme.foo"
}
prod {
applicationId "com.acme.myandroidapp"
}
This is causing my gradle build to fail with a "No matching client found for package name 'com.acme.foo'" error.
I have looked at both: No matching client found for package name (Google Analytics) - multiple productFlavors & buildTypes and google-services.json for different productFlavors
Unfortunately, neither question deals with the wrinkle of having a different application id for a particular product flavor. I did try putting a copy of the google-services.json file at the base of each flavor but there was no joy.
Thoughts on how do you support different applicationIds with Google Services under Android?
You can Add app for both the application Ids in Project setting in Firebase Console.
By doing so the new google-services.json file will contain two client-info, 1 for each application ID.
Putting a copy of the google-services.json file at at the base of each flavor should solve the issue.

Does same package name APK(with different applicationId) use same data location?

we know APK save data in /data/data/PackageName,if two different apk with same package name,will they cover other's data?(like sharepreference's data)
The Answer is No, Why? This is not possible, Play store will not let you to upload an apk with the same package,Package name at play store is important for many reasons, one of them is update detection, if you updated an application the first thing Google pay attention is the package name in order to know what is the current release version.
Somehow it will be happened by same developer at the DEVELOPMENT stage only then you can name your package whatever do you want.
As far as same package name is concerned it's not possible to have installed on same device it will be replaced.
But if we have different appliationId, yes another app can be installed on same device but in that case packageName will also be change.
Working Sample
Project 1
app/build.gradle
applicationId "com.test.sample"
Android Manifest
package="com.test.sample"
Result
When i print applicationId and package name, it was same:
applicationId: "com.test.sample"
package: "com.test.sample"
Project 2
I've added buildTypes/flavor but keeping applicationId and package name same, but in that case outpout of applicationId and package name will be changed.
build.gradle(app)
applicationId "com.test.sample"
buildTypes {
release {
applicationIdSuffix ".release"
}
debug {
applicationIdSuffix ".debug"
}
}
Android Manifest
package="com.test.sample"
Result
When i print applicationId and package name, it was different:
applicationId: "com.test.sample.debug"
package: "com.test.sample.debug"
So that is how two applications are installed due to change in buildType/flavors(pro/free).
And if you want to access sharedPreferences of each-other (assume free/pro version) than you need to create a ContentProvider to expose data you need and grant permissions to paid app.

AndroidManifest file with different package name for china for different flavor.

I am releasing the build for china market and we all know that they don't support Playstore. Henceforth we have decided to release in china stores.
One of the china store has requirement to have the package name in manifest file
must contain the application name. But right now our Main manifest file package name does not contain the application name.
So we created new Manifest file for china flavor with only package name change but Android studio expects the User Permission and Activity declarations in this china manifest file.
Can we create the manifest with only package name changes? All the other permissions and declaration must e taken from Main Manifest file.
You should specify package name in gradle for each flavor. Use the applicationId parameter
buildTypes {
forChina {
applicationId my.domain.appName.chinasuffix
}
notForChina {
applicationId my.domain.appName.other
}
}

Categories

Resources