多个构建版本的applicationId清单占位符不起作用 [英] applicationId manifest placeholder for multiple build flavors not working

查看:134
本文介绍了多个构建版本的applicationId清单占位符不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改当前的android项目,因此可以将其安装在同一设备上以实现多种口味并构建配置.

I am modifying current android project so it can be installed on same device for multiple flavors and build configs.

build.gradle:

{
    // ...
    defaultConfig {
        applicationId "com.myapp"
        manifestPlaceholders = [
            manifestApplicationId: "${applicationId}",
            onesignal_app_id: "xxxx",
            onesignal_google_project_number: "xxxx"
        ]
    // ...
    }

    productFlavors {
        production {
            applicationId "com.myapp"
            // ...
        }

        dev {
            applicationId "com.myapp.dev"
            // ...
        }

        // ...
    }

    buildTypes {
        release {
            // ...
        }

        debug {
            applicationIdSuffix ".debug"
            // ...
        }
    }

    // ...
}

AndroidManifest.xml :

<manifest ... >
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <permission
    android:name="${applicationId}.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />      
    <!-- ... -->

    <receiver
        android:name="com.onesignal.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="${applicationId}" />
        </intent-filter>
    </receiver>

    <!-- ... -->
</manifest>

当我编译相同版本的调试版本和发行版时,出现错误消息:

When I compile both debug and release version of the same flavor, I got error message:

...

INSTALL_FAILED_DUPLICATE_PERMISSION

INSTALL_FAILED_DUPLICATE_PERMISSION

perm = com.myapp.permission.C2D_MESSAGE

perm=com.myapp.permission.C2D_MESSAGE

pkg = com.myapp.dev

pkg=com.myapp.dev

...

manifestApplicationId占位符来自 https://documentation上的说明来自OneSignal库上的AndroidManifest.xml. .onesignal.com/docs/android-sdk-setup

manifestApplicationId placeholder came from AndroidManifest.xml on OneSignal library as instructed on https://documentation.onesignal.com/docs/android-sdk-setup

有人知道如何解决此问题吗?谢谢.

Anybody have a clue how to fix this problem? Thank you.

推荐答案

OneSignal要求将manifestPlaceholders密钥manifestApplicationId设置为您的applicationId(也就是您的软件包名称).

OneSignal requires the manifestPlaceholders key manifestApplicationId to be set to your applicationId (AKA your package name).

可以通过在buildTypes中对其进行设置,如下所示.

This can be done by setting it in your buildTypes like the following.

buildTypes {
   debug {
      defaultConfig {
         manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                 onesignal_app_id               : "11111111-1111-1111-1111-111111111111",
                                 onesignal_google_project_number: "111111111"]
       }
   }

   release {
      defaultConfig {
         manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                 onesignal_app_id               : "22222222-2222-2222-2222-222222222222",
                                 onesignal_google_project_number: "222222222"]
      }
   }
}

更新:3.3.0及更高版本的OneSignal SDK不再需要manifestApplicationId.

Update: manifestApplicationId is no longer required for 3.3.0 and newer of the OneSignal SDK.

这篇关于多个构建版本的applicationId清单占位符不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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