VoltBuilder failing - OneSignal plugin

I’ve hit an issue in attempting to use the OneSignal plugin for push notifications. I’ve followed all the steps in the OneSignal documentation for Phonegap Build but am seeing the following error in the VoltBuilder logs:

onesignal-cordova-plugin 2.10.1 "OneSignal Push Notifications"

Output: 9.0.0 (cordova-lib@9.0.1)

Output: Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at /platforms/android/app/src/main/res/xml/config.xml
Merging project's config.xml into platform-specific android config.xml
[Gradle Properties] Preparing Configuration
[Gradle Properties] Appending default configuration properties
[Gradle Properties] Appending custom configuration properties
[Gradle Properties] Updating and Saving File
Merging and updating files from [www, platforms/android/platform_www] to platforms/android/app/src/main/assets/www
Wrote out android application name "Mighty Saints App" to /platforms/android/app/src/main/res/values/strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (0.8.4 (beta)): 800
Wrote out Android package name "com.nsbasic.ClubApp" to /platforms/android/app/src/main/java/com/nsbasic/ClubApp/MainActivity.java
Updating icons at platforms/android/app/src/main/res
Updating splash screens at platforms/android/app/src/main/res
This app does not have additional resource files defined
Prepared android project successfully
Running command: /usr/libexec/java_home 
Command finished with error code 0: /usr/libexec/java_home 
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/Users/voltbuilder/Code/android-sdk (recommended setting)
ANDROID_HOME=/Users/voltbuilder/Code/android-sdk (DEPRECATED)
Reading build config file: /build.json
Running command: /usr/local/Cellar/gradle/6.4/bin/gradle -p /platforms/android wrapper -b /platforms/android/wrapper.gradle
> Task :wrapper

BUILD SUCCESSFUL in 456ms
1 actionable task: 1 executed
Command finished with error code 0: /usr/local/Cellar/gradle/6.4/bin/gradle -p,/platforms/android,wrapper,-b,/platforms/android/wrapper.gradle
Subproject Path: CordovaLib
Subproject Path: app
Running command: /platforms/android/gradlew cdvBuildDebug -b /platforms/android/build.gradle

> Configure project :app
WARNING: The onesignal-gradle-plugin MUST be before com.android.application!
   Please put onesignal-gradle-plugin first OR update to com.android.tools.build:gradle:3.0.0 or newer!
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
/platforms/android/app/app/src/main/res/xml/config.xml
/platforms/android/app/src/main/res/xml/config.xml
loglevel

> Task :app:preBuild UP-TO-DATE
> Task :CordovaLib:preBuild UP-TO-DATE
> Task :CordovaLib:preDebugBuild UP-TO-DATE
> Task :CordovaLib:checkDebugManifest
> Task :CordovaLib:processDebugManifest
> Task :app:preDebugBuild
> Task :CordovaLib:compileDebugAidl NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :CordovaLib:packageDebugRenderscript NO-SOURCE
> Task :app:compileDebugRenderscript
> Task :app:checkDebugManifest
> Task :app:generateDebugBuildConfig
> Task :app:prepareLintJar
> Task :app:generateDebugSources
> Task :CordovaLib:compileDebugRenderscript
> Task :CordovaLib:generateDebugBuildConfig
> Task :CordovaLib:generateDebugResValues
> Task :CordovaLib:generateDebugResources
> Task :CordovaLib:packageDebugResources
> Task :CordovaLib:generateDebugRFile
> Task :CordovaLib:prepareLintJar
> Task :CordovaLib:generateDebugSources
> Task :CordovaLib:javaPreCompileDebug
> Task :CordovaLib:compileDebugJavaWithJavac
> Task :CordovaLib:processDebugJavaRes NO-SOURCE
> Task :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug
> Task :app:javaPreCompileDebug
> Task :app:mainApkListPersistenceDebug
> Task :app:generateDebugResValues
> Task :app:generateDebugResources
> Task :app:mergeDebugResources
> Task :app:createDebugCompatibleScreenManifests

> Task :app:processDebugManifest FAILED
/platforms/android/app/src/main/AndroidManifest.xml:49:9-51:51 Error:
	Attribute meta-data#onesignal_app_id@value at AndroidManifest.xml:49:9-51:51 requires a placeholder substitution but no value for <onesignal_app_id> is provided.
/platforms/android/app/src/main/AndroidManifest.xml:53:9-55:70 Error:
	Attribute meta-data#onesignal_google_project_number@value at AndroidManifest.xml:53:9-55:70 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.


FAILURE: Build failed with an exception.

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

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s
22 actionable tasks: 22 executed
Command finished with error code 1: /platforms/android/gradlew cdvBuildDebug,-b,/platforms/android/build.gradle
/platforms/android/gradlew: Command failed with exit code 1 Error output:
/platforms/android/app/src/main/AndroidManifest.xml:49:9-51:51 Error:
	Attribute meta-data#onesignal_app_id@value at AndroidManifest.xml:49:9-51:51 requires a placeholder substitution but no value for <onesignal_app_id> is provided.
/platforms/android/app/src/main/AndroidManifest.xml:53:9-55:70 Error:
	Attribute meta-data#onesignal_google_project_number@value at AndroidManifest.xml:53:9-55:70 requires a placeholder substitution but no value for <onesignal_google_project_number> is provided.

FAILURE: Build failed with an exception.

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

I’ve tried various adjustments to config.xml but all unsuccessful so far - currently am including the following settings:

<plugin name="onesignal-cordova-plugin" source="npm" />

<preference name="phonegap-version" value="cli-8.0.0" />

<preference name="android-build-tool" value="gradle" />
<preference name="android-minSdkVersion" value="19" />

I’ve found some references to the same error on stack overflow - with the following solution:

“The error message suggests that the OneSignal library is not configured correctly. Looking trough their setup instructions it seems like you missed point 1.3. Add this to the app level build.gradle; inside the android / defaultConfig tag:”

```
  manifestPlaceholders = [
      onesignal_app_id: 'PUT YOUR ONESIGNAL APP ID HERE',
      // Project number pulled from dashboard, local value is ignored.
      onesignal_google_project_number: 'REMOTE'
  ]
```

However, how would manifestPlaceholders be set in VoltBuilder?

You won’t be able to this with a build tool - you might be able to do so using the Cordova CLI.

I would file an issue in the github repo for this and see the developer can fix it.

There is a step to follow in the OneSignal Phonegap Build documentation which states to add the following to index.js - where would this be best placed in AppStudio?

// Add to index.js or the first page that loads with your app.
// For Intel XDK and please add this to your app.js.

document.addEventListener('deviceready', function () {
  //Remove this method to stop OneSignal Debugging 
  window.plugins.OneSignal.setLogLevel({logLevel: 6, visualLevel: 0});
  
  var notificationOpenedCallback = function(jsonData) {
    console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
  };
  // Set your iOS Settings
  var iosSettings = {};
  iosSettings["kOSSettingsKeyAutoPrompt"] = false;
  iosSettings["kOSSettingsKeyInAppLaunchURL"] = false;
  
  window.plugins.OneSignal
    .startInit("YOUR_ONESIGNAL_APP_ID")
    .handleNotificationOpened(notificationOpenedCallback)
    .iOSSettings(iosSettings)
    .inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
    .endInit();
  
  // The promptForPushNotificationsWithUserResponse function will show the iOS push notification prompt. We recommend removing the following code and instead using an In-App Message to prompt for notification permission (See step 6)
  window.plugins.OneSignal.promptForPushNotificationsWithUserResponse(function(accepted) {
    console.log("User accepted notifications: " + accepted);
  });
  
}, false);

Choose Project Properties and Global Code in the Project Explorer.

Put it into the Code Window for that. Make sure the language is set to JavaScript.

Let us know what happens!

Tried it but same error. Interestingly, iOS is building correctly on Phonegap Build (and looks like it might be fine too on VoltBuilder - I just need to sort a specific P12 file for Push). Here is the log link: https://apps.volt.build/8fc16ad4-cd91-4fea-86c7-eeb51f875830/voltbuilder.log

Seems to be gradle causing the issue. Did see a warning in the log:
WARNING: The onesignal-gradle-plugin MUST be before com.android.application!
Please put onesignal-gradle-plugin first OR update to com.android.tools.build:gradle:3.0.0 or newer!

Not sure if that’s a potential cause?

I saw that. I would file an issue in the github repo for this and see the developer can fix it.

I seem to have made some good progress after contacting OneSignal. Turns out there is a problem with their Cordova Troubleshooting page (Troubleshooting Cordova Variants) - which is blank. However, using Inspect I was able to access some of the tips. Turns out that cordova-plugin-googlemaps can cause problems so removed that and build worked fine. I then re-tested with that plugin put back in but without ‘spec’ set (so that I am using latest version) and again build is successful. So looks like I can now move forwards in terms of using OneSignal in my app.

Good trick!

We had the same issue…we just upgraded to the latest cordova-one-signal and installed gmaps. Build issue got resolved.