简体   繁体   English

新的Android Gradle Build System构建配置包名称与Provider Authority的冲突

[英]New Android Gradle Build System build configs package name conflicts with Provider Authority

I've updated my project to use the new Gradle based build system, largely because I've been kind of annoyed that I can't have my app installed on my device to use it since I use the device for development. 我已经更新了我的项目以使用新的基于Gradle的构建系统,很大程度上是因为我一直很恼火,因为我使用设备进行开发,所以我无法在我的设备上安装我的应用程序来使用它。 I saw a lot of promise in the packageNameSuffix offering of the new build system. 我在新构建系统的packageNameSuffix产品中看到了很多承诺。

The problem that I'm running into involves things other than the package name in the manifest. 我遇到的问题涉及清单中包名称以外的其他内容。 There are other parts that have to be unique, including permissions (specifically for GCM) and ContentProvider Authorities. 还有其他部分必须是唯一的,包括权限(特别是对于GCM)和ContentProvider权限。 When trying to install with a .debug suffix I get errors that the GCM permission for that package hasn't been defined and that I'm trying to install a duplicate provider. 尝试使用.debug后缀进行安装时,我收到的错误是该程序包的GCM权限尚未定义,并且我正在尝试安装重复的提供程序。

Is there a variable that I can put in my manifest instead of these strings so that the build system will replace those appropriately as well? 是否有一个变量,我可以放在我的清单而不是这些字符串,以便构建系统也将适当地替换它们?

Here is my solution for GCM problems with packageNameSuffix. 这是我对packageNameSuffix的GCM问题的解决方案。

Primary problem is permission names that should have ".debug" suffix. 主要问题是应该具有“.debug”后缀的权限名称。 I put that permission to debug and release manifests that are merged to final manifest. 我将此权限用于调试和释放合并到最终清单的清单。

AndroidManfest.xml AndroidManfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.experiment.myapplication"
          android:versionCode="1"
          android:versionName="1.0" >

    <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <uses-permission android:name="android.permission.VIBRATE" />
    <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
        <activity
                android:name=".MainActivity"
                android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


    </application>

</manifest>

debug AndroidManifest 调试AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.experiment.myapplication">


    <permission android:name="com.experiment.myapplication.debug.permission.C2D_MESSAGE"
                android:protectionLevel="signature" />
    <uses-permission android:name="com.experiment.myapplication.debug.permission.C2D_MESSAGE" />

    <application>
        <receiver
                android:name=".GcmBroadcastReceiver"
                android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.experiment.myapplication.debug" />
            </intent-filter>
        </receiver>
    </application>

</manifest

> >

release Android Manifest 发布Android Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.experiment.myapplication" >

    <permission android:name="com.experiment.myapplication.permission.C2D_MESSAGE"
                android:protectionLevel="signature" />
    <uses-permission android:name="com.experiment.myapplication.permission.C2D_MESSAGE" />

    <application>
        <receiver
                android:name=".GcmBroadcastReceiver"
                android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.experiment.myapplication" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

This is a current known limitation of changing the package name for a variant. 这是当前已知的更改变体的包名称的限制。 I'm planning on fixing this as soon as possible. 我打算尽快解决这个问题。

I've replaced all my app's package name in AndroidManifest.xml with placeholder ${packageName}, so Manifest Merger does all work 我在AndroidManifest.xml中用占位符$ {packageName}替换了我在app中的所有包名,因此Manifest Merger可以完成所有工作

For example: 例如:

<uses-permission android:name="${packageName}.permission.C2D_MESSAGE" />

You can use: 您可以使用:

<permission android:name=".permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
<uses-permission android:name=".permission.C2D_MESSAGE" />

Android will add the current package name automatically, as you started with a . 当你开始使用时,Android会自动添加当前的包名. .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android新构建系统(gradle)和aspectj - Android new build system (gradle) and aspectj Android构建系统gradle - Android build system gradle 在Android gradle构建中,如何通过构建类型更改软件包名称? - In a Android gradle build, how to change the package name by build type? 如果生成构建存在,则无法安装适用于Android的Crashlytics Beta版本:&#39;该软件包与现有软件包冲突,名称相同&#39; - Crashlytics Beta build for Android will not install if production build exists: 'The package conflicts with an existing package by the same name' 如何使用新的Gradle Build System在Android上进行集成测试? - How to do Integration Testing on Android with the new Gradle Build System? 使用Gradle在自定义类加载Dalvik(Android新建系统) - Custom Class Loading in Dalvik with Gradle (Android New Build System) Gradle配置在新的Android Build System中无法正常工作 - Gradle Configurations not Working as Expected in New Android Build System android 构建系统获取源代码路径基于 package 名称 - android build system get the source code path base on package name build.gradle中的依赖冲突 - Dependency Conflicts in build.gradle Gradle Android Build System NDK问题 - Gradle Android Build System NDK issues
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM