Flutter 升级到 3.27.3 版本,然后升级 Android 构建工具到最新的 AGP 8.8.0 版本,然后编译报错:
1 2 3 |
Launching lib/main.dart on sdk gphone64 arm64 in debug mode... Running Gradle task 'assembleDebug'... Error: Gradle build failed to produce an .apk file. It's likely that this file was generated under /xxxx/build, but the tool couldn't find it. |
于是在项目的配置文件中寻找配置 "build" 目录的地方,于是在 Flutter 项目的 Android 工程根目录下找到,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
buildscript { ext.kotlin_version = '1.9.22' repositories { maven { url "https://maven.aliyun.com/nexus/content/groups/public/" } maven { url "https://maven.aliyun.com/nexus/content/repositories/google" } google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:8.8.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { maven { url "https://maven.aliyun.com/nexus/content/groups/public" } maven { url "https://maven.aliyun.com/nexus/content/repositories/google" } google() mavenCentral() } } getLayout().setBuildDirectory('../build') subprojects { getLayout().setBuildDirectory("${getLayout().getBuildDirectory()}/${project.name}") } subprojects { project.evaluationDependsOn(':app') } tasks.register("clean", Delete) { delete getLayout().getBuildDirectory() } |
注意 getLayout().setBuildDirectory('../build') ,以前的 Gradle 版本是可以正常编译的,现在的版本需要需要改为 rootProject.buildDir = "../build" 。
修改后的结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
buildscript { ext.kotlin_version = '1.9.22' repositories { maven { url "https://maven.aliyun.com/nexus/content/groups/public/" } maven { url "https://maven.aliyun.com/nexus/content/repositories/google" } google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:8.8.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { maven { url "https://maven.aliyun.com/nexus/content/groups/public" } maven { url "https://maven.aliyun.com/nexus/content/repositories/google" } google() mavenCentral() } } rootProject.buildDir = "../build" subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(":app") } tasks.register("clean", Delete) { delete rootProject.buildDir } |