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.
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. Once you publish your app, you should never change the application ID.
The package name of an Android app uniquely identifies your app on the device, in Google Play Store, and in supported third-party Android stores.
Right click to src folder in your project->New->package. write the name of the package there->Finish. you will see the package what you named under src folder of your project. Add class files into that package.
The package name is just to organize your code. The applicationId, on the other hand, is used to identify your app in the Play Store. You will change this only if you plan to generate another app based on same code.
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With