OneSignal-Gradle-Plugin icon indicating copy to clipboard operation
OneSignal-Gradle-Plugin copied to clipboard

Flutter 2.10 build failed

Open dineralex opened this issue 2 years ago • 30 comments

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

dineralex avatar Feb 06 '22 18:02 dineralex

I hope there are updates to this issue

bluemix avatar Feb 06 '22 20:02 bluemix

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.

Aksoyhlc avatar Feb 06 '22 20:02 Aksoyhlc

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 :/

bluemix avatar Feb 06 '22 20:02 bluemix

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

Aksoyhlc avatar Feb 06 '22 21:02 Aksoyhlc

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'

dineralex avatar Feb 07 '22 06:02 dineralex

Worked for me.

vietlinhtspt avatar Feb 09 '22 03:02 vietlinhtspt

@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 avatar Feb 09 '22 17:02 saurabhdtu

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 avatar Feb 09 '22 17:02 saurabhdtu

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.

saurabhdtu avatar Feb 10 '22 04:02 saurabhdtu

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

mamonraab avatar Feb 10 '22 13:02 mamonraab

none of the above worked with me :/

bluemix avatar Feb 12 '22 16:02 bluemix

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!

rabihmb avatar Feb 13 '22 08:02 rabihmb

@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.)

westy92 avatar Feb 16 '22 01:02 westy92

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.

dgilperez avatar Feb 25 '22 19:02 dgilperez

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:

  • onesignal-gradle-plugin (this gradle plugin) - This resolves conflicting versions of Firebase and other libraries to prevent compile and some runtime issues.
  • com.onesignal:OneSignal (OneSignal-Android-SDK) - This is the SDK that has all the logic to integrate with OneSignal and gets built into your app.

jkasten2 avatar Mar 08 '22 03:03 jkasten2

@jkasten2 any update on this?

westy92 avatar Mar 28 '22 17:03 westy92

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

uj avatar Apr 24 '22 20:04 uj

@jkasten2 any update on this?

Aksoyhlc avatar Apr 24 '22 22:04 Aksoyhlc

@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)

jkasten2 avatar Apr 24 '22 22:04 jkasten2

@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.

Aksoyhlc avatar Apr 24 '22 23:04 Aksoyhlc

@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

dgilperez avatar May 02 '22 09:05 dgilperez

@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

jkasten2 avatar May 02 '22 18:05 jkasten2

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

dgilperez avatar May 02 '22 19:05 dgilperez

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

fmdogan avatar May 12 '22 13:05 fmdogan

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

@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

saurabhdtu avatar May 19 '22 13:05 saurabhdtu

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

krismata15 avatar Jun 06 '22 20:06 krismata15

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

abdullah-khudher avatar Jul 03 '22 06:07 abdullah-khudher

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!

bunphithak avatar Jul 22 '22 10:07 bunphithak

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?

tel-kho avatar Aug 29 '22 12:08 tel-kho