flutter run 时遇到报错:
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeDebugJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> File 'com.android.builder.files.ZipCentralDirectory@29112a16' was deleted, but previous version not found in cache
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> File 'com.android.builder.files.ZipCentralDirectory@12aad2db' was deleted, but previous version not found in cache
* 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.
尝试修改 gradle 版本
打开 vhiphop/android/build.gradle
文件发现,版本号是 3.5.3
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
提示我最新版本为 3.6.1
,于是修改为 3.6.1
修改 gradle 版本后重新 flutter run
重新执行 flutter run
后,又发现了新的报错:
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\office\android\vhiphop\android\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.internal.version-check']
> Minimum supported Gradle version is 5.6.4. Current version is 5.6.2. If using the gradle wrapper, try editing the distributionUrl in D:\office\android\vhiphop\android\gradle\wrapper\gradle-wrapper.properties to gradle-5.6.4-all.zip
* 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.
提示我最新版本是 5.6.4
,而我使用的是 5.6.2
。
于是打开 vhiphop\android\gradle\wrapper\gradle-wrapper.properties
文件,找到如下代码:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
将版本更改为 5.6.4
:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
修改版本后再次 flutter run
又发现如下报错:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> java.io.IOException: Unable to delete file: D:\office\android\vhiphop\build\app\intermediates\flutter\debug\libs.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.
重建项目
真的发现这种 BUG 是没完没了的,和 npm run serve
遇到的那些 BUG 就是一回事,真的太浪费时间了,干脆直接重建项目。
更改原项目名称
重启系统,并修改项目名为 vhiphop_back
。
创建项目
打开 Andorid Studio,新建 Flutter Project
:
Project name: vhiphop
Description:An app for dancing video.
点击 Next
按钮,进入下一步:
Package name:com.vhiphop.app
最后点击 Finish
按钮,等待进度条,创建完成后选择 New Window
打开新项目。
测试新项目
在新项目中执行 flutter run
,一步点亮。
替换 build.gradle
在 Windows 中复制 D:\office\android\vhiphop_back\android\app\build.gradle
文件。
打开 Android Studio,删除 vhiphop\android\app\build.gradle
文件,并将复制的相同文件粘贴进来。
替换 AndroidManifest.xml
在 Windows 中复制 D:\office\android\vhiphop_back\android\app\src\main\AndroidManifest.xml
文件。
打开 Android Studio,删除 vhiphop\android\app\src\main\AndroidManifest.xml
文件,并将复制的相同文件粘贴进来。
并替换 vhiphop\android\app\src\debug\AndroidManifest.xml
、vhiphop\android\app\src\profile\AndroidManifest.xml
两个文件。
添加 VhiphopKey
在 Windows 中复制 D:\office\android\vhiphop_back\android\vhiphopKey
文件。
打开 Android Studio,将文件粘贴至 vhiphop\android\
目录下。
替换 pubspec.yaml
在 Windows 中复制 D:\office\android\vhiphop_back\pubspec.yaml
文件。
打开 Android Studio,将文件粘贴至 vhiphop\
目录下。
点击 Package get
按钮,下载依赖插件
复制原项目逻辑文件
注意一定要使用 Windows 复制,不要直接粘贴进 Android Studio,垃圾编辑器会直接卡死,👴🏻 的 24 G 内存容量,加上花了 3000 块买的三星970PRO SSD 都带不动这个废物编辑器。
lib
、image
、fonts
、jsons
4 个文件夹复制进新项目中,重新执行 flutter run
。
一步点亮。
总结
Flutter 这构建工具就 NM 离谱,这事不是一次两次了,我项目什么都没动,晚上睡觉前还能运行,睡了一觉起来,打开休眠中的电脑,就运行不动了,瞎整半天,最后还是重建项目方便。
网上搜了十几分钟问题,未能解决,最后 3 分钟重建项目解决了,呵呵,⑧说了,辣🐔 Flutter 就完事了。