Flutter 启动时 gradle 的错误

Flutter 启动时 gradle 的错误

错误内容

在启动一个 Flutter 项目时,遇到了 gradle 相关的错误,具体错误信息如下:

* What went wrong:
Could not open settings remapped class cache for 3gvp67rxesfd2nfkbvtuzjg3o (C:\Users\&unser_name%\.gradle\caches\5.6.2\scripts-remapped\settings_3j4cktj76tcwqa3p6pnijdwdi\3gvp67rxesfd2nfkbvtuzjg3o\settings8410a2d21ed2f87c8a0398566330ee52).
> Could not open settings generic class cache for settings file 'C:\Users\Administrator\AndroidStudioProjects\flutter_app\android\settings.gradle' (C:\Users\Administrator\.gradle\caches\5.6.2\scripts\3gvp67rxesfd2nfkbvtuzjg3o\settings\settings8410a2d21ed2f87c8a0398566330ee52).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 57

* 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 1s
Finished with error: Gradle task assembleDebug failed with exit code 1

对我无效的解决方案

有的资料说删除.gradle/caches可以解决问题,没用。

有的说删除项目文件夹下andoird/build.gradleandroid/settings.gradle以及android/app/build.gradle三个文件中关于package的行。然而我的这三个文件中并没有相关行……当然也就没有任何卵用。

有效的解决方案

看了很多资料后尝试将现在使用的 JDK 从java 13改为java 8,问题得到了解决。

运行得到正确的结果:

Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with
"--enable-software-rendering".
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                        68.0s
√ Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...                         1.8s
D/FlutterActivity( 8673): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate( 8673): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate( 8673): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate( 8673): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView( 8673): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@4bf553e
D/FlutterActivityAndFragmentDelegate( 8673): Executing Dart entrypoint: main, and sending initial route: /
D/EGL_emulation( 8673): eglMakeCurrent: 0xeed7fbe0: ver 2 0 (tinfo 0xe3bd5bb0)
D/eglCodecCommon( 8673): setVertexArrayObject: set vao to 0 (0) 1 0     
I/m.example.myap( 8673): NativeAlloc concurrent copying GC freed 1908(215KB) AllocSpace objects, 3(60KB) LOS objects, 57% free, 1114KB/2650KB, paused 653us total 486.487ms
I/OpenGLRenderer( 8673): Davey! duration=1832ms; Flags=1, IntendedVsync=4010927657182, Vsync=4010994323846, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=4010999132700, AnimationStart=4010999214400, PerformTraversalsStart=4010999287600, DrawStart=4012168475900, SyncQueued=4012173764500, SyncStart=4012175660200, IssueDrawCommandsStart=4012179313100, SwapBuffers=4012455218300, FrameCompleted=4012761766600, DequeueBufferDuration=161026000, QueueBufferDuration=513000,
I/Choreographer( 8673): Skipped 107 frames!  The application may be doing too much work on its main thread.
D/EGL_emulation( 8673): eglMakeCurrent: 0xe3b242a0: ver 2 0 (tinfo 0xe3b8cb90)
Syncing files to device Android SDK built for x86...
D/eglCodecCommon( 8673): setVertexArrayObject: set vao to 0 (0) 1 0
Syncing files to device Android SDK built for x86...             9,633ms (!)

�🔥  To hot reload changes while running, press "r". To hot restart (and rebuild state), press "R
An Observatory debugger and profiler on Android SDK built for x86 is available at: http://127.0.0.1:5083/tkseS6ZWRSc=/
For a more detailed help message, press "h". To detach, press "d"; to quit, press "q".

解决办法:使用较低版本的 JDK,比如java 8

顺便解决了Android license的问题

在此前,执行命令flutter doctor时,会提示Android license status unknown的问题,具体信息如下:

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    ✗ Android license status unknown.
      Try re-installing or updating your Android SDK Manager.
      See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed instructions.

在 JDK 从java 13改为java 8之后,相关信息也随之变成了:

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

按照提示信息,执行flutter doctor --android-licenses,然后会弹出数个相关许可:

6 of 7 SDK package licenses not accepted. 100% Computing updates...
Review licenses that have not been accepted (y/N)? y

1/6: License android-googletv-license:
---------------------------------------
Terms and Conditions
...
August 15, 2011
---------------------------------------
Accept? (y/N): y

2/6: License android-sdk-arm-dbt-license:
---------------------------------------
Terms and Conditions
...
January 16, 2019
---------------------------------------
Accept? (y/N): y

3/6: License android-sdk-preview-license:
---------------------------------------
To get started with the Android SDK Preview, ...
...

June 2014.
---------------------------------------
Accept? (y/N): y

4/6: License google-gdk-license:
---------------------------------------
This is a Developer Preview of the GDK that is subject to change.

Terms and Conditions
...
November 19, 2013
---------------------------------------
Accept? (y/N): y

5/6: License intel-android-extra-license:
---------------------------------------
Intel (R) Hardware Accelerated Execution Manager End-User License Agreement

Copyright (c) 2012 Intel Corporation. All rights reserved.
...
---------------------------------------
Accept? (y/N): y
All SDK package licenses accepted

逐个同意之后,得到提示All SDK package licenses accepted

此时再次执行命令flutter doctor,相关信息就变成了:

[] Android toolchain - develop for Android devices (Android SDK version 29.0.3)

使用命令flutter doctor -v查看更详细的信息如下:

[] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at C:\Users\%user_name%\AppData\Local\Android\Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.3
    • Java binary at: C:\Program Files\Java\java-1.8.0-openjdk-1.8.0.212-3.b04.redhat.windows.x86_64\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-3-redhat-b04)
    • All Android licenses accepted.
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值