如何在应用程序中使用库的manifestPlaceholders?

时间:2017-01-12 15:16:30

标签: android android-gradle android-manifest android-library onesignal

我正在尝试将OneSignal SDK添加到我的Android库项目中。因此,我在我的库build.gradle以及manifestPlaceholders中添加了必要的依赖项:

        // One Signal:
        manifestPlaceholders = [onesignal_app_id: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
                                // Project number pulled from dashboard, local value is ignored.
                                onesignal_google_project_number: "XXXXXXXXXXXX"]

问题在于,当我尝试构建一个使用我的库的演示应用程序时,我添加了OneSignal,我得到了以下错误:

/path_to_project/demoapp/demoapp/src/main/AndroidManifest.xml Error:
    Attribute meta-data#onesignal_app_id@value at AndroidManifest.xml requires a placeholder substitution but no value for <onesignal_app_id> is provided.
/path_to_project/demoapp/demoapp/src/main/AndroidManifest.xml Error:
    Attribute meta-data#onesignal_google_project_number@value at AndroidManifest.xml requires a placeholder substitution but no value for <onesignal_google_project_number> is provided.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

:demoapp:processDebugManifest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':demoapp:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs

我没有手动向任何AndroidManifest.xml添加任何东西(既不是应用程序也不是库)。

我想在我的库中使用OneSignal SDK并能够将我的库添加到任何应用,因此onesignal_app_idonesignal_google_project_number对于使用我的库的所有应用都是相同的。我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:-1)

我和你有同样的问题。经过研究,有一个解决方案。

您可以按以下方式在自己的清单中覆盖库的mate-data:

<meta-data
        android:name="onesignal_app_id"
        android:value="${onesignal_app_id}"
        tools:replace="android:value"/>

属性tools:replace="android:value"允许您覆盖库清单的元数据。

然后您可以在自己的gradle文件中定义manifestPlaceholders。

答案 1 :(得分:-5)

manifestPlaceholders = [onesignal_app_id: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
                            // Project number pulled from dashboard, local value is ignored.
                            onesignal_google_project_number: "XXXXXXXXXXXX"]

您可以将代码添加到库build.gradle中。

像这样:

buildTypes {
        release {
            minifyEnabled false
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.awter
            manifestPlaceholders = [onesignal_app_id: "xxxxxxx",
                                    // Project number pulled from dashboard, local value is ignored.
                                    onesignal_google_project_number: "REMOTE"]
        }
        debug {
            manifestPlaceholders = [onesignal_app_id: "xxxxx",
                                    // Project number pulled from dashboard, local value is ignored.
                                    onesignal_google_project_number: "REMOTE"]
        }
    }

它对我有用。