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.
gradle replaces manifest. use gradle
The application id specified in the build.gradle will be used.
The entry in the
AndroidManifest.xml
is overriddenYour
AndroidManifest.xml
will look like thisGradle applicationId is the final PackageName for playstore.
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.
build.gradle example
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.
There's a great support article about this here by Android Studio.
Why are there two?
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.