Flutter Gradle初始化异常

时间:2018-11-02 09:10:25

标签: android gradle flutter

我正在尝试通过Android Studio 3.2运行Flutter应用,但无法正常工作。

我尝试了太多的想法和解决方案,但仍然无法正常工作。

Linux Ubuntu 18.04

flutter doctor
[✓] Flutter (Channel beta, v0.9.4, on Linux, locale cs_CZ.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[✓] Android Studio (version 3.2)
[✓] Connected devices (1 available)

• No issues found!

错误:

Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Finished with error: Please review your Gradle project setup in the android/ folder.
* Error running Gradle:
Exit code 1 from: /media/hdd/Projects/apps/flutter_app_new/android/gradlew app:properties:
Starting a Gradle Daemon, 1 busy Daemon could not be reused, use --status for details

Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.

FAILURE: Build failed with an exception.

* Where:
Build file '/media/hdd/Projects/apps/flutter_app_new/android/app/build.gradle' line: 25

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all files for configuration 'classpath'.
   > Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2).
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar

* 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 9s

我通过apt install gradle安装了gradle并运行gradle --stacktrace

gradle --stacktrace
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.gradle.internal.reflect.JavaMethod (file:/usr/share/gradle/lib/gradle-base-services-3.4.1.jar) to method java.lang.ClassLoader.getPackages()
WARNING: Please consider reporting this to the maintainers of org.gradle.internal.reflect.JavaMethod
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Starting a Gradle Daemon (subsequent builds will be faster)
:help

Welcome to Gradle 3.4.1.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

To see more detail about a task, run gradle help --task <task>

BUILD SUCCESSFUL

我尝试在gradle-wrapper.properties中更改gradle的版本 来自

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

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

gradle.build

{
buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

} 

但仍然无法正常工作。 请帮忙。谢谢你。

2 个答案:

答案 0 :(得分:0)

我不知道为什么,但是在第25行的app / build.gradle中我有

应用来自:“ $ flutterRoot / packages / flutter_tools / gradle / flutter.gradle”

所以我不得不在flutter库中更改文件!在文件flutter.gradle中,我有

buildscript {
    repositories {
        jcenter() 
        maven {
            url 'https://dl.google.com/dl/android/maven2'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

更改为此

buildscript {
    repositories {
        maven {
            url 'https://dl.google.com/dl/android/maven2'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

所以我不知道为什么我必须更改库文件。你知道为什么吗? 谢谢

答案 1 :(得分:0)

基本上这是颤振的问题,但是the root cause is not flutter。 选中this answer,您可以通过切换到主频道轻松地使其正常工作。