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

Revert install hooks modifying build.gradle #41

Open jkasten2 opened 6 years ago

jkasten2 commented 6 years ago

Build Error

This fixes the following tns build android error.

tns build android
Preparing project...
Successfully prepared plugin nativescript-onesignal for android.
Successfully prepared plugin nativescript-theme-core for android.
Successfully prepared plugin tns-core-modules for android.
Successfully prepared plugin tns-core-modules-widgets for android.
Project successfully prepared (android)
Executing after-prepare hook from /Users/josh/Documents/tmp/os-nativescript-test/hooks/after-prepare/nativescript-onesignal-gradle.js
Building project...
Gradle build...

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/josh/Documents/tmp/os-nativescript-test/platforms/android/build.gradle' line: 9

* What went wrong:
A problem occurred evaluating root project 'osnativescripttest'.
> Could not find method maven() for arguments [build_4mersf8kdzao2x4y2lrb6flje$_run_closure1$_closure3@676290d] 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 3s
Command ./gradlew failed with exit code 1
# tns build android

Issue Details

Hooks added in 1.0.8 by PR #37 are creating Android build errors due to maven { url "https://plugins.gradle.org/m2/" } being added to incorrect locations in build.gradle files. This will resolve issues #38 and #39.

Solution

Removing these install hooks modify the build.gradle files. They are not needed as the OneSignal-Gradle-Plugin added in PR #36 takes care of fixing Android dependency versions it was trying to fix.

Upgrading from 1.0.8

  1. tns plugin remove nativescript-onesignal
  2. rm hooks/after-prepare/nativescript-onesignal-gradle.js
  3. tns build android
  4. If you get any errors with maven { url "https://plugins.gradle.org/m2/" } remove the lines from the build.gradle files it notes.
  5. Repeat steps 4 & 5 until your project builds
    • If you can't get your project to build you can run tns platform clean android
    • NOTE however, running clean will reset files in your platforms/android folder.
  6. tns plugin add https://github.com/OneSignal/nativescript-onesignal
  7. If you a had to run tns platform clean android you will need to add back the OneSignal manifestPlaceholders to platforms/android/app/build.gradle.
  8. tns build android
  9. You should be all set!
OPADA-Eng commented 6 years ago

There are missing files when you add the plugin from github can you add npm repo to the new branch ?

MopheusDG commented 6 years ago

@OPADA-Eng @jkasten2 Same problem here, tried to follow this steps and I was able to avoid the gradle issue but still cannot do the "require". Any fix ?

OPADA-Eng commented 6 years ago

@MopheusDG just remove the file from hooks/after-prepare/nativescript-onesignal-gradle.js and remove platform "android" then rebuild your project

MopheusDG commented 6 years ago

Thank you @OPADA-Eng, I've done that before but for some reason was still failing on my APP, so I created a new one and it's working now, so need to re-implement in mine.

By the way, I've created a request for help to change the main.ts code required to JS as I was able to modify the Android code but the IOS code is more difficult, to see if someone can help me. #43.

Android modified code works but I don't have the skill to modify the IOS one, it's much more complicated.

Thanks !

jkasten2 commented 6 years ago

@OPADA-Eng @MopheusDG hmm ya weird, using tns plugin add on a repo vs an npm module is causing require to no longer find OneSignal at runtime. I might be doing something different when importing from a URL then.

@roblav96 I believe after we merge this PR and create a release this should fix issues #38 and #39. Can you merge it in and push a new release to NPM?

denkan commented 6 years ago

Would love to have this merged and released to NPM. Been struggling to get this issue to work for many hours without success. Pity, when the plugin seems so nice otherwise.

Ping @roblav96 ;)

Onefivefournine commented 4 years ago

If I use tns plugin add on the Onesignal/nativescript-onesignal repo - it somehow fails to install actual .ts files (see attached image) - that's why it can't be found at runtime - there is nothing to be found image

I am struggling to make this lib working on tns v6.5.0 for android @roblav96 it would be nice to merge this pull request anyway

Onefivefournine commented 4 years ago

Ok, I resolved empty require with just using another way to add plugin from repo tns plugin add https://github.com/OneSignal/nativescript-onesignal/archive/master.tar.gz

but then I got such error:

A problem occurred configuring project ':app'.
All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

Command ./gradlew failed with exit code 1

It is resolved by removing or commenting this section from platforms/android/include.gradle:

...
    productFlavors {
        'nativescriptonesignal' {
            dimension 'nativescriptonesignal'
        }
    }
...

@jkasten2 it would be great if you make a new commit with this fix P.S. I am not into android development at all, so if it breaks something else and there is more convenient fix - you're welcome

UPDATE: As a quick workaround you may add this to your app.gradle:

android {
  ...
  flavorDimensions "nativescriptonesignal"
  ...
}
brunobg commented 4 years ago

hey @Onefivefournine, do you want to setup a fork of this project with me and make it work properly?