使用 Flutter,构建 gradle SdkVersion 时出错

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

我正在为 android 制作一个 flutter 应用程序,我正处于部署阶段,在尝试解决一些问题时,我面临着很多兼容性问题。这是我需要使用 ./gradlew clean build 构建 gradle 的最难的部分。干净的通过,但不是构建,经过几个小时的尝试但没有成功,你是我最后的希望。

这是完整的错误:

* What went wrong:
Execution failed for task ':device_info:checkDebugUnitTestAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > 2 issues were found when checking AAR metadata:

       1.  Dependency 'androidx.window:window-java:1.0.0-beta04' requires libraries and applications that
           depend on it to compile against version 31 or later of the
           Android APIs.

           :device_info is currently compiled against android-29.

           Recommended action: Update this project to use a newer compileSdkVersion
           of at least 31, for example 33.

           Note that updating a library or application's compileSdkVersion (which
           allows newer APIs to be used) can be done separately from updating
           targetSdkVersion (which opts the app in to new runtime behavior) and
           minSdkVersion (which determines which devices the app can be installed
           on).

       2.  Dependency 'androidx.window:window:1.0.0-beta04' requires libraries and applications that
           depend on it to compile against version 31 or later of the
           Android APIs.

           :device_info is currently compiled against android-29.

           Recommended action: Update this project to use a newer compileSdkVersion
           of at least 31, for example 33.

           Note that updating a library or application's compileSdkVersion (which
           allows newer APIs to be used) can be done separately from updating
           targetSdkVersion (which opts the app in to new runtime behavior) and
           minSdkVersion (which determines which devices the app can be installed
           on).

这是当前的 app/build.gradle (我已经尝试过 31 和 33 版本,甚至强制依赖,如你所见

plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader("UTF-8") { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) {
    flutterVersionCode = "1"
}

def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) {
    flutterVersionName = "1.0"
}

configurations.all {
resolutionStrategy { force 'androidx.window:window-java:1.0.0-beta04' }}

android {
    namespace = "com.example.s3nsa_app"
    compileSdk = 31

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.s3nsa_app"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdk = 21 
        targetSdk = 31
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig = signingConfigs.debug
        }
    }
}

flutter {
    source = "../.."
}



感谢您的帮助!

android flutter dependencies gradlew
1个回答
0
投票

更改代码中的以下行,记下 targetSdk 值。

注意: 删除 example 关键字宿舍捆绑包,因为在 Playstore 上发布 apk 时不接受它。

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.s3nsa_app"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdk = 21 
        targetSdk = 34
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName
    }
© www.soinside.com 2019 - 2024. All rights reserved.