Skip to content Skip to sidebar Skip to footer

Android:which One To Use For Package Name? Manifest's Packagename Or Gradle Applicationid?

I am using Android Studio version 2.1.2, and I am trying to implement Google Cloud Messaging to my app. To be able to do that I have to obtain a Google Services json file(configura

Solution 1:

The application id specified in the build.gradle will be used.

The entry in the AndroidManifest.xml is overridden

Your AndroidManifest.xml will look like this

<uses-permissionandroid:name="${applicationId}.permission.C2D_MESSAGE" /><uses-permissionandroid:name="com.google.android.c2dm.permission.RECEIVE" /><receiver...><intent-filter><actionandroid:name="com.google.android.c2dm.intent.RECEIVE" /><actionandroid:name="com.google.android.c2dm.intent.REGISTRATION" /><categoryandroid:name="${applicationId}" /></intent-filter></receiver>

Solution 2:

There's a great support article about this here by Android Studio.

Why are there two?

  • The final package that is used in your built .apk's manifest, and is the package your app is known as on your device and in the Google Play store, is the "application id" as specified in the gradle file.
  • The package that is used in your source code to refer to your R class, and to resolve any relative activity/service registrations, continues to be called the "package" as defined in your manifest.

Which one should I edit to change my final package name The package name in Gradle will overwrite the package name in the Manifest. So you should change it in Gradle.

If you would like to actually change the structure of your project, then you'd need to change your packagename in Manifest.xml

For permissions In your particular case, the permissions, you ask which package name you should provide for Google Messaging. Since Google Messaging requires your final package name, you should enter your gradle packagename. If you're using flavours, you should do this dynamically as suggested by @alim's answer.

Solution 3:

gradle replaces manifest. use gradle

Solution 4:

With introduction with Android Studio seen has been changed. Earlier in eclipse Manifest.xml package name considered whole and sole as you upload your app on Google Play store it will pick the package name from Manifest.xml but it is not the case with Android Studio.

In Android Studio there are two place where application package name goes.

  1. Manifest.xml
  2. build.gradle

build.gradle example

defaultConfig {
    applicationId "com.company.testapp" 
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

Notice the applicationId above which is other place where package name goes.

@Mdlc is absolutely right.

Which one should I edit to change my final package name? The package name in Gradle will overwrite the package name in the Manifest. So you should change it in Gradle.

If you would like to actually change the structure of your project, then you'd need to change your packagename in Manifest.xml

When we refactor rename application package name in Android Studio it does not change application Id. We have to do it manually. Please pay attention to this because it very important. As when we upload our application on Google Play store google pick package name matching with applicationId as in case of above example com.company.testapp.

Solution 5:

Google uses your package name as a unique name to identify your app. Since you mentioned that it is on Google Play, you should use the one in Gradle file to make it possible.

And to answer the second part of your question, it is just a convention to define the app <application-package-name> + ".permission.C2D_MESSAGE as your permission name, so you can use the one mentioned in Gradle file.

Hope this helps :)

Post a Comment for "Android:which One To Use For Package Name? Manifest's Packagename Or Gradle Applicationid?"