Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

Flutter 2.10 build failed #184

Open
dineralex opened this issue Feb 6, 2022 · 30 comments
Open

Flutter 2.10 build failed #184

dineralex opened this issue Feb 6, 2022 · 30 comments

Comments

@dineralex
Copy link

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

@dineralex dineralex changed the title Flutter 2.10 build faled Flutter 2.10 build failed Feb 6, 2022
@bluemix
Copy link

bluemix commented Feb 6, 2022

I hope there are updates to this issue

@Aksoyhlc
Copy link

Aksoyhlc commented Feb 6, 2022

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
Copy link

bluemix commented Feb 6, 2022

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
Copy link

Aksoyhlc commented Feb 6, 2022

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
Copy link
Author

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
Copy link

Worked for me.

@saurabhdtu
Copy link

@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
Copy link

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
Copy link

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
Copy link

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
Copy link

bluemix commented Feb 12, 2022

none of the above worked with me :/

@rabihmb
Copy link

rabihmb commented Feb 13, 2022

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
Copy link

westy92 commented Feb 16, 2022

@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
Copy link

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
Copy link
Member

jkasten2 commented Mar 8, 2022

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.

@westy92
Copy link

westy92 commented Mar 28, 2022

@jkasten2 any update on this?

@uj
Copy link

uj commented Apr 24, 2022

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

@Aksoyhlc
Copy link

@jkasten2 any update on this?

@jkasten2
Copy link
Member

jkasten2 commented Apr 24, 2022

@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
Copy link

@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. OneSignal/OneSignal-Flutter-SDK#462 is there going to be an update in this, it's a very important issue.

@dgilperez
Copy link

@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
Copy link
Member

jkasten2 commented May 2, 2022

@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
Copy link

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

@fmdogan
Copy link

fmdogan commented May 12, 2022

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
Copy link

diego-lipinski-de-castro commented May 12, 2022

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

@saurabhdtu
Copy link

saurabhdtu commented May 19, 2022

@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
Copy link

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
Copy link

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
Copy link

bunphithak commented Jul 22, 2022

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
Copy link

tel-kho commented Aug 29, 2022

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests