5

I am trying to add OneSignal SDK to my Android library project. Therefore, I added necessary dependencies in my library's build.gradle and also 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"]

The problem is that when I try to build a demo app which uses my library to which I added OneSignal I get these errors:

/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

I didn't add anything manually to any AndroidManifest.xml (neither application's nor library's).

I want to use OneSignal SDK in my library and be able to add my library to any app, so that onesignal_app_id and onesignal_google_project_number are the same for all apps using my library. How can I achieve this?

fragon
  • 3,391
  • 10
  • 39
  • 76
  • 1
    My guess is that you need to define your placeholders at the app level, not the library level. You could use `gradle.properties` or some other common location for the values of the placeholder values, so you're not duplicating those. – CommonsWare Jan 12 '17 at 15:25
  • @CommonsWare But is there any way to do it so that these "keys" are only in my library and not in the app using it? I would like not to share `onesignal_app_id` and `onesignal_google_project_number` with other users of my library or at least not ask them to put these values manually in their application's `build.gradle`. – fragon Jan 12 '17 at 16:18
  • 1
    "But is there any way to do it so that these "keys" are only in my library and not in the app using it?" -- not that I am aware of. "I would like not to share onesignal_app_id and onesignal_google_project_number with other users of my library" -- I would be fairly surprised if the terms of service would allow you to do that, though I haven't read them. Regardless, I would expect that the app developers need to have their own values, rather than use yours. I assumed that "all apps" meant apps in a suite of yours, not third parties. – CommonsWare Jan 12 '17 at 16:27
  • @CommonsWare Ok. So it seems that I have to change the way this SDK is connected to my library and make the user put his own OneSignal credentials instead of using mine. – fragon Jan 13 '17 at 10:28
  • I am stuck in some similar problem but more complex.I have a common-base library which requires a **manifestPlaceholders**.Besides, I divide my business into several business-base library.The business-base libraries refer to the common-base library.And my app refers to both business-base libraries and common-base library.In such case,**manifestPlaceholders** is required for each library as well as my app.Have you find some perfect solution? – Qian Sijianhao Apr 08 '18 at 02:00

2 Answers2

-2

I have the same problem as you. After some research, there is a solution.

You can override your library's mate-data in your own manifest as follows:

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

The attribute tools:replace="android:value" allow you to override the manifest's meta-data of your library.

Then you can define the manifestPlaceholders in your own gradle file.

Yang Kang
  • 31
  • 3
  • Also have to do this https://stackoverflow.com/questions/18633511/namespace-is-not-bound-in-android-studio. But even doing this, still having the same error https://github.com/geektimecoil/react-native-onesignal/issues/639#issuecomment-494756894. – Pablo May 22 '19 at 11:25
-6
manifestPlaceholders = [onesignal_app_id: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
                            // Project number pulled from dashboard, local value is ignored.
                            onesignal_google_project_number: "XXXXXXXXXXXX"]

You can add the code into your library build.gradle.

like this:

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"]
        }
    }

it works for me.

Kishan Viramgama
  • 893
  • 1
  • 11
  • 23