OneSignal / OneSignal-Cordova-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com
Other
250 stars 197 forks source link

Ionic & Latest OneSignal-Cordova SDK don't work together. #388

Closed selected-pixel-jameson closed 6 years ago

selected-pixel-jameson commented 6 years ago

Description: When I try to run ionic cordova run android --device in Ionic app with the latest OneSignal SDK I get the following error and the app fails to launch. When I downgraded to 2.4.0 it works fine.

'Please put onesignal-gradle-plugin first OR update to com.android.tools.build:gradle:3.0.0 or newer!

Environment

  1. Running the latest versions
  2. <?xml version='1.0' encoding='utf-8'?>
    <widget id="com.keycollectorcomics.keycollector" version="1.5.2" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Key Collector</name>
    <description>Key Collector Comics.</description>
    <author email="jameson@selectedpixel.com" href="http://selectedpixel.com">Selected Pixel</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="http://ionic.local/*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <allow-navigation href="*" />
    <preference name="android-minSdkVersion" value="19" />
    <preference name="android-targetSdkVersion" value="26" />
    <preference name="webviewbounce" value="false" />
    <preference name="UIWebViewBounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="30000" />
    <preference name="AutoHideSplashScreen" value="false" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="FadeSplashScreen" value="true" />
    <preference name="orientation" value="portrait" />
    <platform name="android">
        <allow-intent href="market:*" />
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
        <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
        <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />
    </platform>
    <platform name="ios">
        <icon height="57" src="resources/ios/icon/icon.png" width="57" />
        <icon height="114" src="resources/ios/icon/icon@2x.png" width="114" />
        <icon height="40" src="resources/ios/icon/icon-40.png" width="40" />
        <icon height="80" src="resources/ios/icon/icon-40@2x.png" width="80" />
        <icon height="120" src="resources/ios/icon/icon-40@3x.png" width="120" />
        <icon height="50" src="resources/ios/icon/icon-50.png" width="50" />
        <icon height="100" src="resources/ios/icon/icon-50@2x.png" width="100" />
        <icon height="60" src="resources/ios/icon/icon-60.png" width="60" />
        <icon height="120" src="resources/ios/icon/icon-60@2x.png" width="120" />
        <icon height="180" src="resources/ios/icon/icon-60@3x.png" width="180" />
        <icon height="72" src="resources/ios/icon/icon-72.png" width="72" />
        <icon height="144" src="resources/ios/icon/icon-72@2x.png" width="144" />
        <icon height="76" src="resources/ios/icon/icon-76.png" width="76" />
        <icon height="152" src="resources/ios/icon/icon-76@2x.png" width="152" />
        <icon height="167" src="resources/ios/icon/icon-83.5@2x.png" width="167" />
        <icon height="29" src="resources/ios/icon/icon-small.png" width="29" />
        <icon height="58" src="resources/ios/icon/icon-small@2x.png" width="58" />
        <icon height="87" src="resources/ios/icon/icon-small@3x.png" width="87" />
        <icon height="1024" src="resources/ios/icon/icon-1024.png" width="1024" />
        <splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
        <splash height="1334" src="resources/ios/splash/Default-667h.png" width="750" />
        <splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242" />
        <splash height="1242" src="resources/ios/splash/Default-Landscape-736h.png" width="2208" />
        <splash height="1536" src="resources/ios/splash/Default-Landscape@2x~ipad.png" width="2048" />
        <splash height="2048" src="resources/ios/splash/Default-Landscape@~ipadpro.png" width="2732" />
        <splash height="768" src="resources/ios/splash/Default-Landscape~ipad.png" width="1024" />
        <splash height="2048" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" />
        <splash height="2732" src="resources/ios/splash/Default-Portrait@~ipadpro.png" width="2048" />
        <splash height="1024" src="resources/ios/splash/Default-Portrait~ipad.png" width="768" />
        <splash height="960" src="resources/ios/splash/Default@2x~iphone.png" width="640" />
        <splash height="480" src="resources/ios/splash/Default~iphone.png" width="320" />
        <splash height="2732" src="resources/ios/splash/Default@2x~universal~anyany.png" width="2732" />
        <config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
            <string>To use the camera on your device to capture images.</string>
        </config-file>
        <config-file parent="NSPhotoLibraryUsageDescription" platform="ios" target="*-Info.plist">
            <string>To use images from your photo library within the application.</string>
        </config-file>
    </platform>
    <branch-config>
        <branch-key value="key_live_gnAO0k2tDVWly5P7SAYCMifjEwa0C87H" />
        <uri-scheme value="keycollectorcomics" />
        <link-domain value="keycollectorcomics.app.link" />
        <link-domain value="keycollectorcomics.test-app.link" />
        <ios-team-release value="CUUL5292QL" />
    </branch-config>
    <plugin name="onesignal-cordova-plugin" spec="2.4.0" />
    <plugin name="cordova-plugin-device" spec="^2.0.2" />
    <plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
    <plugin name="cordova-plugin-statusbar" spec="^2.4.2" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
    <plugin name="cordova-plugin-ionic-keyboard" spec="^2.1.2" />
    <plugin name="cordova-plugin-google-analytics" spec="^1.8.3" />
    <plugin name="cordova-plugin-camera" spec="^3.0.0" />
    <plugin name="cordova-plugin-file" spec="^5.0.0" />
    <plugin name="cordova-plugin-file-transfer" spec="^1.7.1" />
    <plugin name="cordova-plugin-apprate" spec="^1.4.0" />
    <plugin name="branch-cordova-sdk" spec="^2.7.1" />
    <plugin name="cordova-plugin-x-socialsharing" spec="^5.4.1" />
    <plugin name="cordova-plugin-appavailability" spec="^0.4.2" />
    <plugin name="cordova-plugin-inappbrowser" spec="^1.7.2" />
    <plugin name="cordova-plugin-hockeyapp" spec="^5.1.2" />
    <plugin name="cordova-plugin-app-version" spec="^0.1.9" />
    <plugin name="cordova-plugin-stripe" spec="^1.5.3" />
    <plugin name="cordova-custom-config" spec="^5.0.2" />
    <plugin name="cordova-plugin-ionic-webview" spec="^1.2.1" />
    <engine name="android" spec="~6.3.0" />
    </widget>

Steps to Reproduce Issue:

  1. Add the onesignal-cordova-plugin to your project
  2. Build and run android on device.
jfishman1 commented 6 years ago

Please double check that you are using Cordova 8.0.0 or newer.

Also update to the onesignal-cordova-plugin 2.4.1 by removing the plugin and adding it back:

ionic cordova plugin remove onesignal-cordova-plugin ionic cordova plugin add onesignal-cordova-plugin

Please share the config.xml and crash log after checking these.

grotaldo commented 6 years ago

@fatsjohonimahnn hi i think it's a problem with the change on build-extras-onesignal.gradle file.

jkasten2 commented 6 years ago

@selected-pixel-jameson The onesignal-gradle-plugin message is only a warning as it might not be able to correctly align dependencies with other plugins. In addition to updating to Cordova CLI 8.0.0 it is recommend to update the Cordova Android Platform to 7.0.0 or newer.

cordova platform remove android
cordova platform add android@7.1.0

Please include the full runtime error if the above does not fix your issue.

princenishchal commented 6 years ago

I am having the same issue with Latest Ionic and OneSignal. In fact a few other projects that we have used Onesignal when recompiled with the latest OneSignal plugin are giving compilation errors.

I created an empty "tabs" Ionic project, no additional code just added latest OneSignal Plugin and can reproduce the above error.

Please somebody help fixing this error!

SUNILs-MacBook-Pro:sample princenishchal$ ionic cordova build android
Running app-scripts build: --platform android --target cordova
[16:46:38]  build dev started ... 
[16:46:38]  clean started ... 
[16:46:38]  clean finished in 3 ms 
[16:46:38]  copy started ... 
[16:46:39]  deeplinks started ... 
[16:46:39]  deeplinks finished in 18 ms 
[16:46:39]  transpile started ... 
[16:46:41]  transpile finished in 2.18 s 
[16:46:41]  preprocess started ... 
[16:46:41]  preprocess finished in 1 ms 
[16:46:41]  webpack started ... 
[16:46:41]  copy finished in 2.29 s 
[16:46:45]  webpack finished in 4.22 s 
[16:46:45]  sass started ... 
Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning.
[16:46:46]  sass finished in 805 ms 
[16:46:46]  postprocess started ... 
[16:46:46]  postprocess finished in 5 ms 
[16:46:46]  lint started ... 
[16:46:46]  build dev finished in 7.31 s 
> cordova build android
Android Studio project detected

ANDROID_HOME=/Users/princenishchal/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
studio
Subproject Path: CordovaLib
Subproject Path: app
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
    at build_ds6tfvzg89yqndetr6b006ner.run(/Users/princenishchal/myworkspace/mobile/testprojs/sample/platforms/android/app/build.gradle:144)
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
[16:46:48]  lint finished in 1.92 s 
:CordovaLib:preBuild
 UP-TO-DATE
:CordovaLib:preDebugBuild
 UP-TO-DATE

:CordovaLib:compileDebugAidl
 UP-TO-DATE
:CordovaLib:compileDebugRenderscript

UP-TO-DATE
:CordovaLib:checkDebugManifest UP-TO-DATE
:CordovaLib:generateDebugBuildConfig 
UP-TO-DATE
:CordovaLib:prepareLintJar UP-TO-DATE
:CordovaLib:generateDebugResValues UP-TO-DATE
:CordovaLib:generateDebugResources UP-TO-DATE
:CordovaLib:packageDebugResources 
UP-TO-DATE
:CordovaLib:platformAttrExtractor UP-TO-DATE

:CordovaLib:processDebugManifest
 UP-TO-DATE
:CordovaLib:processDebugResources 
UP-TO-DATE
:CordovaLib:generateDebugSources
 UP-TO-DATE
:CordovaLib:javaPreCompileDebug
 UP-TO-DATE

:CordovaLib:compileDebugJavaWithJavac
 UP-TO-DATE

:CordovaLib:processDebugJavaRes
 NO-SOURCE

:CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE

:app:preBuild
 UP-TO-DATE
:app:preDebugBuild

FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Could not find runtime.aar (android.arch.lifecycle:runtime:1.1.0).
  Searched in the following locations:
      https://jcenter.bintray.com/android/arch/lifecycle/runtime/1.1.0/runtime-1.1.0.aar
> Could not find livedata-core.aar (android.arch.lifecycle:livedata-core:1.1.0).
  Searched in the following locations:
      https://jcenter.bintray.com/android/arch/lifecycle/livedata-core/1.1.0/livedata-core-1.1.0.aar
> Could not find viewmodel.aar (android.arch.lifecycle:viewmodel:1.1.0).
  Searched in the following locations:
      https://jcenter.bintray.com/android/arch/lifecycle/viewmodel/1.1.0/viewmodel-1.1.0.aar
> Could not find runtime.aar (android.arch.core:runtime:1.1.0).
  Searched in the following locations:
      https://jcenter.bintray.com/android/arch/core/runtime/1.1.0/runtime-1.1.0.aar

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

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

BUILD FAILED in 3s
14 actionable tasks: 1 executed, 13 up-to-date
(node:27878) UnhandledPromiseRejectionWarning: Error: /Users/princenishchal/myworkspace/mobile/testprojs/sample/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Could not find runtime.aar (android.arch.lifecycle:runtime:1.1.0).
  Searched in the following locations:
      https://jcenter.bintray.com/android/arch/lifecycle/runtime/1.1.0/runtime-1.1.0.aar
> Could not find livedata-core.aar (android.arch.lifecycle:livedata-core:1.1.0).
  Searched in the following locations:
      https://jcenter.bintray.com/android/arch/lifecycle/livedata-core/1.1.0/livedata-core-1.1.0.aar
> Could not find viewmodel.aar (android.arch.lifecycle:viewmodel:1.1.0).
  Searched in the following locations:
      https://jcenter.bintray.com/android/arch/lifecycle/viewmodel/1.1.0/viewmodel-1.1.0.aar
> Could not find runtime.aar (android.arch.core:runtime:1.1.0).
  Searched in the following locations:
      https://jcenter.bintray.com/android/arch/core/runtime/1.1.0/runtime-1.1.0.aar

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

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

BUILD FAILED in 3s
    at ChildProcess.whenDone (/Users/princenishchal/myworkspace/mobile/testprojs/sample/platforms/android/cordova/node_modules/cordova-common/src/superspawn.js:169:23)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
(node:27878) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:27878) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The project will compile if I remove the onesignal plugin

The installed plugins are

> cordova plugin ls
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-ionic-keyboard 2.0.5 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.1.19 "cordova-plugin-ionic-webview"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-whitelist 1.3.3 "Whitelist"
onesignal-cordova-plugin 2.4.1 "OneSignal Push Notifications"

Ionic Info

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 8.0.0 

local packages:

    @ionic/app-scripts : 3.1.10
    Cordova Platforms  : android 7.0.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 26.1.1
    ios-deploy        : 1.9.2 
    Node              : v8.11.3
    npm               : 5.6.0 
    OS                : macOS High Sierra
    Xcode             : Xcode 9.4.1 Build version 9F2000 

Environment Variables:

    ANDROID_HOME : /Users/princenishchal/Library/Android/sdk

Misc:

    backend : pro
princenishchal commented 6 years ago

Hey, I found one way that worked. It is same as what @atorgfr has suggested.

Steps:

  1. Remove the existing onesignal plugin
  2. Add a previous version of the plugin, in my case I added ionic cordova add plugin onesignal-cordova-plugin@2.3.0
  3. Copied the gradle file from the location platforms/android/onesignal-cordova-plugin to a temporary location
  4. After copying this file, I removed this plugin and added the latest Onesignal plugin once again
  5. Replaced the gradle file with my file from step 3 into location platforms/android/onesignal-cordova-plugin
  6. Compile the project and it worked back fine.

pheww... lots of steps. After so many permutations and combinations this seemed to work. Special thanks and mentions to @atorgfr .

drubetti commented 6 years ago

@princenishchal

There's a simpler way, and no need to downgrade: https://github.com/OneSignal/OneSignal-Cordova-SDK/issues/385

pookdeveloper commented 3 years ago

When will it be resolved? Thanks