Flutter无法运行项目,afterEvaluate(Closure)当项目已被评估时

jv2fixgn  于 2023-01-14  发布在  Flutter
关注(0)|答案(4)|浏览(411)

解决方法:看起来onesignal插件依赖于flutter_tools。解决方案是将onesignal插件放在"android/app/build. gradle"序列中的onesignal插件之后:

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

Flutter版本从2.8.1升级到2.10后,我开始收到以下错误。我重新安装了Flutter,但结果没有变化。当我将Flutter降级到2.8.1时,它工作正常,但当我升级到2.10时,它不工作。

Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* Where:
Script '/Users/aksoyhlc/flutter/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 421

 What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > **Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.**

* 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

BUİLD FAILED in 798ms
Exception: Gradle task assembleDebug failed with exit code 1

Android/应用程序/build. gradle文件的一部分

buildscript {
    repositories {
       
        google()  // Google's Maven repository
        maven { url 'https://plugins.gradle.org/m2/' } 
    }
    dependencies {
       
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.6, 0.99.99]'
        classpath 'com.google.gms:google-services:4.3.8'
    }
}
allprojects {

    repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository

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

安卓/构建版本. gradle文件

一个三个三个一个

1dkrff03

1dkrff031#

有同样的问题。仍然没有解决它,但看起来像一个插件的一个错误。如果你将删除它,一切工作。至少对我来说。
在OneSignal-Gradle-Plugin存储库中打开的问题:https://github.com/OneSignal/OneSignal-Gradle-Plugin/issues/184

ef1yzkbh

ef1yzkbh2#

看起来onesignal插件依赖于flutter_tools。解决方案是将onesignal插件放在“android/app/build.gradle”序列中的onesignal插件之后:

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

ecbunoof3#

对于那些谁仍然得到这个错误。这个解决方案为我工作。
问题是OneSignal插件与Gradle 7.x版本不兼容。因此,您可以按如下方式修改Gradle版本:
android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-all.zip

android/build.gradle

dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0'
        // OTHERS
    }

然后您可以在android/app/build.gradle中初始化OneSignal插件

buildscript {
    repositories {
        // ...
        maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
    }
    dependencies {
        // ...
        // OneSignal-Gradle-Plugin
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
    }
}

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

您应该注意OneSignal插件必须放置在apply plugin: 'com.android.application'之上,因此将其放置在apply plugin: 'com.android.application'之下可能会导致插件无法按预期工作。

myzjeezk

myzjeezk4#

所有这些答案对我都不起作用,我在android/build.gradle中将我的gradle版本从7.1.2降级到4.1.0。

相关问题