Appeared in the Flutter project: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper solution

My environment is as follows:

  • gradle version:

      gradle -v //java version is also output directly.

Gradle 5.6.2
------------------------------------------------------------

Build time:   2019-09-05 16:13:54 UTC
Revision:     55a5e53d855db8fc7b0e494412fc624051a8e781

Kotlin:       1.3.41
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM:          11.0.11 (Oracle Corporation 11.0.11+9-LTS-194)
OS:           Windows 10 10.0 amd64

C:\Users\nothing>java -version
java version "11.0.11" 2021-04-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode)
  • Flutte version

flutter doctor -v //The red × inside can be ignored because I don’t use android studio for development because it is too stuck.

C:\Users\Nothing>flutter doctor -v
[√] Flutter (Channel stable, 1.20.3, on Microsoft Windows [Version 10.0.19045.3086], locale zh-CN)
    • Flutter version 1.20.3 at E:\flutter_windows_1.20.3-stable\flutter
    • Framework revision 216dee60c0 (2 years, 9 months ago), 2020-09-01 12:24:47 -0700
    • Engine revision d1bc06f032
    • Dart version 2.9.2
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn


[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\Liu Shaoting\AppData\Local\Android\Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: E:\AndroidStudio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[!] Android Studio
    • Android Studio at E:\AndroidStudio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • android-studio-dir = E:\AndroidStudio
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] Connected device (1 available)
    • Amazon Fire Phone (mobile) • emulator-5554 • android-x64 • Android 9 (API 28)

! Doctor found issues in 1 category.

The process of building and running the Flutter project will not be described again. Since I need to reproduce other people's issues, I need to use these very old versions. For versions of Flutter 1.22.0 or above, just create the project directly and then run the project. But after Flutter version 1.22.0, you need to do some configuration operations (this is not sure, according to my experience.). OK, when I used flutter run in the project created by Flutter 1.20.3, an accident occurred. The accident was as follows:

 I looked for a solution to this error on stackflow, and everyone said it was caused by a mismatch between the gradle version and the java version. But I changed from java8 to java17, and from gradle2.14 to gradle7.5.1. Still hasn't solved my problem. The gradle and java version comparison table can be viewed here . Then I explored on my own, tried various methods, and finally got the answer.

Here's the solution (worked for me):

 1. In your project, find the gradle.properties file in the android folder and open this file. The content is as follows, and the content inside is automatically generated during the project construction process.

org.gradle.jvmargs=-Xmx1536M

android.enableR8=true

android.useAndroidX=true

android.enableJetifier=true

 2. Add your java path in this gradle.properties file. The format is org.gradle.java.home=C:\\Program Files\\Java\\jdk-11.0.11. As a result, the contents of the gradle.properties file become.

org.gradle.jvmargs=-Xmx1536M

android.enableR8=true

android.useAndroidX=true

android.enableJetifier=true

org.gradle.java.home=C:\\Program Files\\Java\\jdk-11.0.11

3. Save the file. Finally, flutter run is OK.

Note: This method is effective for me and we can communicate together.

Guess you like

Origin blog.csdn.net/csdn9874123/article/details/131213760