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(configuration file) to add to my project.
For getting this file from Google Api console panel, I am required to provide my app name and my app's package name. And here is where my problem starts.
In my app, package name in Manifest file is different than the applicationId in the application level build.gradle file. And On google play store, the applicationId is being used.
To Illustrate what I mean, In my Manifest file;
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
and in my gradle file;
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId 'com.menu.jkrk'
minSdkVersion 16
targetSdkVersion 23
versionCode 3
versionName "1.0"
}
Now, which one of those to provide to google as package name to get configuration file?
Secondly, which one should use for requesting permisson of C2D_MESSAGE in my manifest file where the format is;
<application-package-name> + ".permission.C2D_MESSAGE
Thanks for any help.
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-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<receiver ...>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
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.
gradle replaces manifest. use gradle
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 :)
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.
- Manifest.xml
- 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.
Gradle applicationId is the final PackageName for playstore.