roblav96 / nativescript-onesignal

A Nativescript plugin that wraps the iOS and Android OneSignal Push Notifications SDK.
https://documentation.onesignal.com/docs/getting-started
Other
24 stars 42 forks source link

Not compatable for Android on NS CLI5+ #46

Open delanick opened 5 years ago

delanick commented 5 years ago

I'm getting massive errors when trying to use this plugin on my Android app (iOS builds fine but users don't register with APNS) and would like to know if this can please be updated asap to cater for it.

pdipax commented 5 years ago

Same issue. I have problem with hook.


* What went wrong:
A problem occurred evaluating root project 'app'.
> Could not find method maven() for arguments [build_8zgjr781l7hf81fhe2eo68bvw$_run_closure1$_closure3@c2b688a] on object of type org.gradle.api.internal.initialization.DefaultScriptHandler.

* 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 0s
Unable to apply changes on device: xxxx. Error is: Command gradlew.bat failed with exit code 1.
yclau commented 5 years ago

+1

karlix commented 5 years ago

The problem is in file hooks/after-prepare/nativescript-onesignal-gradle.js. This tries to modify the gradle files incorrectly. Finally I have been able to solve it following the official documentation of onesignal for android sdk and modifying the files manually https://documentation.onesignal.com/docs/android-sdk-setup

yclau commented 5 years ago

@karlix

The problem is in file hooks/after-prepare/nativescript-onesignal-gradle.js. This tries to modify the gradle files incorrectly. Finally I have been able to solve it following the official documentation of onesignal for android sdk and modifying the files manually https://documentation.onesignal.com/docs/android-sdk-setup

May I know what you modify?

delanick commented 5 years ago

@karlix Thanks for letting us know. Sadly I'm no expert when it comes to SDKs etc.... can you please share with us how you fixed it?

guzz commented 5 years ago

Hi @karlix it is realy working? Im trying to mess with it but having no luck.

karlix commented 5 years ago

The steps I have taken to apply this manually are these:

remove code contains in: hooks\after-prepare\nativescript-onesignal-gradle.js

in platforms\android\build.gradle add: inner buildscript -> repositories -> maven { url 'https://plugins.gradle.org/m2/'} inner buildscript -> dependencies -> classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.11.0, 0.99.99]'

there should be something like that:

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.11.0, 0.99.99]'
    }
}

in platforms\android\app\build.gradle add:

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

add to the end of the file

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '27.1.0'
            }
        }
    }
}

in app\App_Resources\Android\app.gradle add/modify:

dependencies {
    compile 'com.android.support:recyclerview-v7:+'
    implementation 'com.android.support:appcompat-v7:27.+'
    implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'
}
android {  
  defaultConfig {  
....
    manifestPlaceholders = [
      onesignal_app_id: 'you_app_id_onesignal',
      onesignal_google_project_number: 'REMOTE'
    ]
....
  }  
....
} 

The only downside of this is that if you create the platform again you will restore the gradle files and you will have to re-apply the changes (this would be avoided with the hook that we deleted in the first step, since this does not modify the files in a way correct)

delanick commented 5 years ago

@karlix thank you so much for posting this. As soon as I reclaim the push notifications ticket I will try this out. Thank you!

delanick commented 5 years ago

@roblav96 Any update on this plugin correction yet?

max-pro commented 5 years ago

I Try all steps but know i getting error Could not get unknown property 'android' for root project 'project' of type org.gradle.api.Project

kvindascr commented 5 years ago

I think version 1.0.8 is broken. We have keep using version 1.0.7 for a while to avoid this issue.

delanick commented 5 years ago

@kvindasAB How do I install that version?

oncul commented 5 years ago

@kvindasAB How do I install that version?

bofore uninstall current version and remote hooks/onesignal file you can use

tns plugin add nativescript-onesignal@1.0.7

pdipax commented 5 years ago

for me this plugin doesn't work

CapellaBlue commented 5 years ago

I'm also experiencing difficulty in getting this plugin to run successfully. I did combine information/steps from the the Android SDK-- I also tried adding my app ID where I believed this should be placed based on the format in the npm instructions within main.ts as well as the specified location in app.gradle per the modification of deleting the hook and adding in code from Android SDK.

The main complaints from my console:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'driver'.
> Could not get unknown property 'android' for root project 'driver' of type org.gradle.api.Project.

* 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 1s
app/main.ts(27,11): error TS2420: Class 'MyDelegate' incorrectly implements interface 'UIApplicationDelegate'.
  Property 'applicationDidFinishLaunchingWithOptions' is private in type 'MyDelegate' but not in type 'UIApplicationDelegate'.

app/main.ts(31,93): error TS2314: Generic type 'NSDictionary<KeyType, ObjectType>' requires 2 type argument(s).
12:25:13 - Compilation complete. Watching for file changes.

I do comment out console.dump lines as they also throw an error. Commending them out does not change the errors above.

Here is my package.json:

{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "com.dispatchbot.driver",
    "name": "DispatchBot Driver",
    "tns-ios": {
      "version": "4.1.1"
    },
    "tns-android": {
      "version": "4.2.0"
    }
  },
  "engines": {
    "node": ">= 8.0.0",
    "npm": ">= 5.0.0"
  },
  "dependencies": {
    "@angular/animations": "~5.2.0",
    "@angular/common": "~5.2.0",
    "@angular/compiler": "~5.2.0",
    "@angular/core": "~5.2.0",
    "@angular/forms": "~5.2.0",
    "@angular/http": "~5.2.0",
    "@angular/platform-browser": "~5.2.0",
    "@angular/platform-browser-dynamic": "~5.2.0",
    "@angular/router": "~5.2.0",
    "@ngrx/effects": "^5.1.0",
    "@ngrx/router-store": "^5.0.1",
    "@ngrx/store": "^5.1.0",
    "@ngrx/store-devtools": "^5.2.0",
    "@types/moment-timezone": "^0.5.4",
    "codelyzer": "^4.3.0",
    "guid-typescript": "^1.0.7",
    "log4ts": "^0.4.2",
    "moment": "^2.22.1",
    "moment-timezone": "^0.5.17",
    "nativescript-angular": "^5.2.0",
    "nativescript-appavailability": "1.3.1",
    "nativescript-background-fetch": "^1.2.0",
    "nativescript-background-geolocation-lt": "^1.9.0-beta.4",
    "nativescript-drawingpad": "^3.0.3",
    "nativescript-iqkeyboardmanager": "^1.3.0",
    "nativescript-material-icons": "^1.0.3",
    "nativescript-ng2-fonticon": "^1.3.4",
    "nativescript-onesignal": "^1.0.8",
    "nativescript-phone": "^1.3.1",
    "nativescript-sentry": "^1.5.2",
    "nativescript-theme-core": "^1.0.4",
    "nativescript-ui-listview": "^3.5.1",
    "nativescript-ui-sidedrawer": "^4.1.0",
    "nativescript-unit-test-runner": "^0.3.4",
    "reflect-metadata": "^0.1.8",
    "remotedev": "^0.2.7",
    "reselect": "^3.0.1",
    "rxjs": "^5.5.2",
    "tns-core-modules": "^4.2.1",
    "tslint": "^5.10.0",
    "zone.js": "^0.8.18"
  },
  "devDependencies": {
    "@types/jasmine": "^2.8.6",
    "babel-traverse": "6.26.0",
    "babel-types": "6.26.0",
    "babylon": "6.18.0",
    "jasmine-core": "^2.9.1",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^2.0.2",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^1.0.1",
    "karma-coverage": "^1.1.1",
    "karma-jasmine": "^1.1.2",
    "karma-mocha-reporter": "^2.2.5",
    "karma-nativescript-launcher": "^0.4.0",
    "karma-typescript": "^3.0.12",
    "lazy": "1.0.11",
    "nativescript": "^4.1.2",
    "nativescript-dev-sass": "^1.6.0",
    "nativescript-dev-typescript": "~0.6.0",
    "remotedev-server": "^0.2.4",
    "tns-platform-declarations": "^4.1.0",
    "typescript": "~2.8.3"
  },
  "scripts": {
    "build": "npm run build:android",
    "build:android": "tns build android --release --env.aot --key-store-path dispatchbot-worker.keystore --key-store-password $ANDROID_KEYSTORE_PASSWORD --key-store-alias dispatchbot-worker --key-store-alias-password $ANDROID_KEYSTORE_PASSWORD --copy-to dist/build.apk",
    "build:ios": "tns prepare ios --release --env.aot",
    "clean": "npm run clean:js && npm run clean:platforms",
    "clean:js": "find . -type f -name 'app/*.js' -exec rm {} +",
    "clean:platforms": "rm -rf platforms",
    "lint": "tslint -p tsconfig.json",
    "preinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') >= 0) throw new Error('Sorry dawg, you gotta use npm on this project ;(')\"",
    "remotedev": "remotedev --hostname=localhost --port=8000",
    "start": "npm run start:android",
    "start:android": "tns debug android --watch",
    "start:ios": "tns debug ios --watch",
    "test": "npm run test:android",
    "test:android": "tns test android --emulator",
    "test:ios": "tns test ios --emulator"
  }
}

I'm happy to provide any further information that is needed.

CapellaBlue commented 5 years ago

After removing the iOS portion of the code, the only error that remains is the error: Could not get unknown property 'android' for root project 'driver' of type org.gradle.api.Project.

Is property 'android' the android of application.android? Trying to figure out how to resolve it if possible.

oncul commented 5 years ago

I fixed with this

remove this file hooks/after-prepare/nativescript-onesignal-gradle.js

Add this to App_Resource/Android/app.gradle

dependencies {
    implementation 'com.onesignal:OneSignal:[3.11.2, 3.99.99]'
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
    maven { url 'https://maven.google.com' }
}

Add this to App_Resource/Android/buildscript.gradle

repositories {
    maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
    classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.4, 0.99.99]'
}

rebuild.

lsapan commented 4 years ago

Thanks for that @oncul! I had to add one additional piece to App_Resource/Android/app.gradle:

android {
  ...

  configurations {
    all*.exclude module: 'play-services-base'
  }
}

Without that, there were tons of errors about duplicate classes (i.e.):

java.lang.RuntimeException: Duplicate class com.google.android.gms.common.api.internal.zza found in modules classes.jar (com.google.android.gms:play-services-base:15.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)
oncul commented 4 years ago

Today, i got same issue. There is a pull request about gradle. Update your code with that pr and remove platform. You will be succeed.

25 Eki 2019 Cum, saat 23:44 tarihinde Luke Sapan notifications@github.com şunu yazdı:

Thanks for that @oncul https://github.com/oncul! I had to add one additional piece to App_Resource/Android/app.gradle:

android { ...

configurations { all*.exclude module: 'play-services-base' } }

Without that, there were tons of errors about duplicate classes (i.e.):

java.lang.RuntimeException: Duplicate class com.google.android.gms.common.api.internal.zza found in modules classes.jar (com.google.android.gms:play-services-base:15.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/roblav96/nativescript-onesignal/issues/46?email_source=notifications&email_token=AAC2Q3DJVZ2TLGVBWCNEYOLQQNLEDA5CNFSM4GL3SKL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECJQRIY#issuecomment-546506915, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC2Q3FGZREKG2BRIOUBMDLQQNLEDANCNFSM4GL3SKLQ .