Android:使用哪一个作为包名?清单的包名或 Gradle applicationId? [英] Android:Which one to use for package name? Manifest's packagename or Gradle applicationId?

本文介绍了Android:使用哪一个作为包名?清单的包名或 Gradle applicationId?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Android Studio 2.1.2 版,并且正在尝试将 Google Cloud Messaging 实施到我的应用中.

I am using Android Studio version 2.1.2, and I am trying to implement Google Cloud Messaging to my app.

为了能够做到这一点,我必须获取一个 Google 服务 json 文件(配置文件)以添加到我的项目中.

To be able to do that I have to obtain a Google Services json file(configuration file) to add to my project.

要从 Google Api 控制台面板获取此文件,我需要提供我的应用名称我的应用程序包名称.这就是我的问题开始的地方.

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.

在我的应用中,Manifest 文件中的包名与应用程序级 build.gradle 文件中的 applicationId 不同.在 google play store 上,正在使用 applicationId.

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">

在我的 gradle 文件中;

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"
}

现在,将哪一个作为包名提供给 google 以获取配置文件?

其次,在我的 manifest 文件中请求 C2D_MESSAGE 的权限时应该使用哪个格式;

<application-package-name> + ".permission.C2D_MESSAGE

感谢您的帮助.

推荐答案

将使用build.gradle中指定的应用程序id.

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

AndroidManifest.xml 中的条目被覆盖

您的 AndroidManifest.xml 将如下所示

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

这篇关于Android:使用哪一个作为包名?清单的包名或 Gradle applicationId?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆