android – applicationId显示占位符,用于多个构建版本无法正常工作

前端之家收集整理的这篇文章主要介绍了android – applicationId显示占位符,用于多个构建版本无法正常工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在修改当前的 android项目,因此它可以安装在同一设备上,用于多种口味和构建配置.

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

当我编译相同风格的调试版和发行版时,我收到错误消息:

INSTALL_Failed_DUPLICATE_PERMISSION

烫发= com.myapp.permission.C2D_MESSAGE

PKG = com.myapp.dev

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

有谁知道如何解决这个问题?谢谢.

解决方法

OneSignal要求manifestPlaceholders键manifestApplicationId设置为您的applicationId(AKA您的包名称).

这可以通过在buildTypes中设置它来完成,如下所示.

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.

原文链接:https://www.f2er.com/android/311889.html

猜你在找的Android相关文章