flutter 构建 apk 时构建失败

问题描述 投票:0回答:1

当我运行

flutter build apk
时,我收到此错误:

FAILURE: Build failed with an exception.
* What went wrong:
  Could not resolve all files for configuration 'classpath'.
> Could not find lint-model-30.3.0.jar (com.android.tools.lint:lint-model:30.3.0).
> Searched in the following locations:
> https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-model/30.3.0/lint-model-30.3.0.jar

android/buid.gradle:

    ext.kotlin_version = '1.9.20'
    repositories {
    google()
    jcenter()

    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
    google()
    jcenter()

    }
}

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

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

扑医生:

[√] Flutter (Channel stable, 3.16.0, on Microsoft Windows [Version 10.0.19044.3324], locale fa-IR)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.0)
[√] Android Studio (version 2022.2)
[√] VS Code, 64-bit edition (version 1.81.0)
[√] Connected device (4 available)
[√] Network resources

我的fluter SDK版本是3.16.0,我也尝试过3.24.3,但结果是相同的。

我尝试创建新项目,但错误仍然存在,Windows 构建没问题。

我还尝试删除 gradle 缓存和 pub 缓存,但没有成功。

android flutter dart gradle
1个回答
0
投票

我遇到了这个问题,并通过将此代码添加到 app/build.gradle 来解决它

allprojects {
           .
           .
           .       
      } // keep all project and under it add this code
ext {
    compileSdkVersion   = 34
    targetSdkVersion    = 34
    appCompatVersion    = "1.7.0" }

并在:

rootProject.buildDir = '../build'

添加这行代码:

subprojects {
    afterEvaluate {
        android {
            compileSdkVersion 34
        }
    }
}

然后再次运行

flutter build apk
© www.soinside.com 2019 - 2024. All rights reserved.