Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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(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.

like image 506
Orcun Avatar asked Jul 13 '16 09:07

Orcun


People also ask

What is applicationID Android?

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.

What is the Android package name?

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.

What is the right way to declare package in Android?

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.

What is the difference between package name and application ID?

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.


3 Answers

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>
like image 167
Alim Parkar Avatar answered Sep 27 '22 04:09

Alim Parkar


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.

like image 29
Mdlc Avatar answered Sep 27 '22 04:09

Mdlc


gradle replaces manifest. use gradle

like image 2
Prashant Avatar answered Sep 29 '22 04:09

Prashant