Android:使用哪一个作为包名?清单的包名或 Gradle applicationId?

Android:Which one to use for package name? Manifest#39;s packagename or Gradle applicationId?(Android:使用哪一个作为包名?清单的包名或 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
cocos2d-android: how to display score(cocos2d-android:如何显示分数)
Authenticate with Google App Engine from an Iphone Native Client(从 Iphone Native Client 使用 Google App Engine 进行身份验证)
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
Android file copy(安卓文件拷贝)