OneSignal / OneSignal-Gradle-Plugin

Use with OneSignal-Android-SDK to help integrate it into your Android Studio or Gradle project. https://onesignal.com
Other
64 stars 17 forks source link

Flutter 2.10 build failed #184

Open dineralex opened 2 years ago

dineralex commented 2 years ago

Please read here: https://stackoverflow.com/questions/71003124/flutter-cannot-run-project-afterevaluateclosure-when-the-project-is-already-ev/71009865#71009865

bluemix commented 2 years ago

I hope there are updates to this issue

Aksoyhlc commented 2 years ago

I moved the code "classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.6, 0.99.99]'" into "android/build.gradle" and added the onesignal in "android/app/build.gradle" I deleted the codes and it was fixed. There is no problem with the notification process, it continues to work.

Just add apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin' to "android/app/build.gradle" file.

bluemix commented 2 years ago

I moved the code "classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.6, 0.99.99]'" into "android/build.gradle" and added the onesignal in "android/app/build.gradle" I deleted the codes and it was fixed. There is no problem with the notification process, it continues to work.

Just add apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin' to "android/app/build.gradle" file.

did not worked with me :/

Aksoyhlc commented 2 years ago

I moved the code "classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.6, 0.99.99]'" into "android/build.gradle" and added the onesignal in "android/app/build.gradle" I deleted the codes and it was fixed. There is no problem with the notification process, it continues to work. Just add apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin' to "android/app/build.gradle" file.

did not worked with me :/

Can you share the content of "android/app/build.gradle" file

dineralex commented 2 years ago

Looks like there is dependecy of onesignal plugin on flutter_tools. The solution is to place onesignal plugin after it in the sequence in the "android/app/build.gradle":

apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

vietlinhtspt commented 2 years ago

Worked for me.

saurabhdtu commented 2 years ago

@dineralex One signal's documentation specifically says to keep the plugin above the apply plugin: 'com.android.application https://documentation.onesignal.com/docs/troubleshooting-android#warning-the-onesignal-gradle-plugin-must-be-before-comandroidapplication

And flutter gradle has to be kept after this apply plugin: 'com.android.application So if you change this order of plugins, the notifications don't actually work in a release signed apk

saurabhdtu commented 2 years ago

Getting Caused by: org.gradle.api.InvalidUserCodeException: Cannot run Project.afterEvaluate(Closure) when the project is already evaluated. When adding this in app/build.gradle

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'//important to be placed at top before android application
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

However if the order of the one signal plugin is moved after flutter gradle, the error doesn't come, but the notifications aren't delivered in release signed apk. And the reason behind not using the one signal's flutter sdk is that, the notifications on mi/huawei devices don't open the app when clicked. So to manually open the app using OneSignal's notification listener android sdk is being used

saurabhdtu commented 2 years ago

Worked for me on removing the plugin from app/build.gradle. Just having the classpath in project/build.gradle and the library dependency app/build.gradle.

mamonraab commented 2 years ago

to me i fix this by upgrading the kotlin in android\build.gradle from

ext.kotlin_version = '1.3.50' to

ext.kotlin_version = '1.4.32'

then i did flutter clean and all work

bluemix commented 2 years ago

none of the above worked with me :/

rabihmb commented 2 years ago

I upgraded to 4.6.7 implementation 'com.onesignal:OneSignal:4.6.7' and placed the

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin' after apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle

Problem Solved for me!

westy92 commented 2 years ago

@rabihmb does that just allow it to compile, or do push notifications work with a release-signed build? (That's been reportedly still an issue with your proposed solution.)

dgilperez commented 2 years ago

Nothing of the workarounds here works for us. We're forced to move down to flutter 2.8 and kotlin 1.5, but this is causing other kinds of trouble.

I'd like to kindly ping @jkasten2 in case you're not aware of this particular bug. I assume this is preventing everyone to upgrading flutter, or I'd be happy to learn a working recommended workaround.

jkasten2 commented 2 years ago

Update

Thanks for reporting, we will look into the issue.

Workaround

In the meantime you can omit this Gradle plugin (onesignal-gradle-plugin), you may not have any conflicting versions of Firebase or other libraries this plugin is designed to solve. If you do, the alternative is to resolve them manually by upgrading or downgrading the libraries causing issues.

If you need help resolving specific Java library conflicts after removing onesignal-gradle-plugin create a new issue on the matching OneSignal SDK you are using (example OneSignal-Flutter-SDK). Make sure to note that you are not using onesignal-gradle-plugin if you removed it to work around this issue.

Background

The native Android part of OneSignal has two pieces:

westy92 commented 2 years ago

@jkasten2 any update on this?

uj commented 2 years ago

6 weeks later... any update on this???

Aksoyhlc commented 2 years ago

@jkasten2 any update on this?

jkasten2 commented 2 years ago

@westy92, @uj, and @Aksoyhlc There has been some investigation of a rewrite of this plugin to use the newer Gradle ComponentMetadataRule API. This should solve this issue, as well as a number of the other open issues on this repo, while greatly simplifying the code and performance of this plugin. However, we don't have an ETA on this at this time.

However as noted above, onesignal-gradle-plugin is an optional part of integrating OneSignal into your Android app, it simply resolves dependency version mismatches. This is the main part is OneSignal-Android-SDK, which is used by OneSignal-Flutter-SDK and the other wrapper / binder SDKs.

Given the above, if you are seeing an issue with onesignal-gradle-plugin you can remove it from your project. After that makes sure your app builds AND runs. If you see either a build issue or crash after removing it, post an issue on the Github repo of the SDK you are using. A maintainer there will try to help you with any remaining issues. (Example OneSignal-Flutter-SDK/issues)

Aksoyhlc commented 2 years ago

@westy92, @uj, and @Aksoyhlc There has been some investigation of a rewrite of this plugin to use the newer Gradle ComponentMetadataRule API. This should solve this issue, as well as a number of the other open issues, while greatly simplifying the code and performance of this plugin. However, we don't have an ETA on this at this time.

However as noted above, onesignal-gradle-plugin is an optional part of integrating OneSignal into your Android app, it simply resolves dependency version mismatches. This is the main part is OneSignal-Android-SDK, which is used by OneSignal-Flutter-SDK and the other wrapper / binder SDKs.

Given the above, if you are seeing an issue with onesignal-gradle-plugin you can remove it from your project. After that makes sure your app builds AND runs. If you see either a build issue or crash after removing it, post an issue on the Github repo of the SDK you are using. A maintainer there will try to help you with any remaining issues. (Example OneSignal-Flutter-SDK/issues)

Thanks for the answer. https://github.com/OneSignal/OneSignal-Flutter-SDK/issues/462 is there going to be an update in this, it's a very important issue.

dgilperez commented 2 years ago

@jkasten2 I am a bit confused about your latest message

it simply resolves dependency version mismatches

I am not sure that means we can just drop the plugin. Dependency mismatches sounds like a dangerous thing. What dependency mismatches precisely? Can we update firebase dependencies freely? Is it possible that we see runtime errors even if the app builds, depending on particular firebase versions?

Before pouring costly dev hours to find those answers out, could you please provide a more comprehensive list of things to check? Or could you just please push this fix so we don't need to dig this?

Thanks

jkasten2 commented 2 years ago

@dgilperez We have seen less incompatibility issues with firebase-messaging version 22 and newer, which the OneSignal-Android-SDK switched to in version 4.4.0. Before this there was a lot of conflicts between firebase-iid and firebase-messaging.

Can we update firebase dependencies freely?

To make sure you are always using compatible set of Firebase libraries Google recommends including firebase-bom: https://firebase.google.com/docs/android/learn-more#bom

Is it possible that we see runtime errors even if the app builds, depending on particular firebase versions?

Yes this is possible, normally if there is an issue it will happen on start up, but sometimes it won't happen until a specific feature is used.

Before pouring costly dev hours to find those answers out, could you please provide a more comprehensive list of things to check?

Most of the rules in this plugin are for Firebase, and a number of them only apply to very old projects, but you can check out all the definitions here: https://github.com/OneSignal/OneSignal-Gradle-Plugin/blob/0.14.0/src/main/groovy/com/onesignal/androidsdk/GradleProjectPlugin.groovy#L54-L266

dgilperez commented 2 years ago

Thanks a lot for your thorough response @jkasten2 - we will take it from there.

fmdogan commented 2 years ago

So to manually open the app using OneSignal's notification listener android sdk is being used

@saurabhdtu how to integrate android sdk? i tried but it still doesn't open terminated app on click. and when it opens the app which is in background, it restarts the app as new activity. i am new with native site. so please guide me. any tutorial or github repo is welcome

diego-lipinski-de-castro commented 2 years ago

is there a simple, straight solution to this or just not?

saurabhdtu commented 2 years ago

@fmdogan in the project level build.gradle add this

buildscript {
    ext.kotlin_version = '1.5.31'
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
        classpath 'com.google.gms:google-services:4.3.10'

    }
}

in app level build.gradle file add this

dependencies {
..// all the app dependencies
..
implementation 'com.onesignal:OneSignal:[4.0.0, 4.99.99]'
}

Then see if you can follow my implementation that I have described -->>>>> here..

It has the native side implementation. Flutter/React native side implementation has to be handled

krismata15 commented 2 years ago

I change in my "android > gradle > wrapper > gradle-wrapper.properties" file the version of "distributionUrl" to "gradle-6.7.1-all.zip" and all works, even with flutter 3.

I guess is a problem with version 7 of gradle.

gradle-wrapper.properties

abdullah-khudher commented 2 years ago

Looks like there is dependecy of onesignal plugin on flutter_tools. The solution is to place onesignal plugin after it in the sequence in the "android/app/build.gradle":

apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

thank you @dineralex it worked

bunphithak commented 1 year ago

Looks like there is dependecy of onesignal plugin on flutter_tools. The solution is to place onesignal plugin after it in the sequence in the "android/app/build.gradle":

apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

thank you it work!

tel-kho commented 1 year ago

Looks like there is dependecy of onesignal plugin on flutter_tools. The solution is to place onesignal plugin after it in the sequence in the "android/app/build.gradle":

apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

thank you it work!

I have seen in some answers that placing the plugin after can prevent it from working properly, is this really a solution?