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

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

问题描述

我使用的是 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 商店中,正在使用 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"
}

现在,提供给谷歌哪一个作为包名来获取配置文件?

其次,我的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 应用程序 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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