依赖项“androidx.webkit:webkit:1.5.0”要求“compileSdkVersion”设置为 32 或更高

Chr*_*oft 4 android-webview flutter webview-flutter

根据“webview_flutter”的文档,该包需要 Android SDK 20+。flutter pub add webview_flutter运行并重新启动我的应用程序(甚至还没有尝试使用)后WebView,我立即收到以下错误:

One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to /Users/chris/Projects/app/android/app/build.gradle:
android {
  compileSdkVersion 32
  ...
}


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > One or more issues found when checking AAR metadata values:

     Dependency 'androidx.webkit:webkit:1.5.0' requires 'compileSdkVersion' to be set to 32 or higher.
     Compilation target for module ':app' is 'android-31'

BUILD FAILED in 4s
Exception: Gradle task assembleDebug failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

我正在测试和编译的设备正在运行版本 31。

我的android/app/build.gradle文件:

...

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    ...

    defaultConfig {
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    ...
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Run Code Online (Sandbox Code Playgroud)

我还尝试将其更改minSdkVersion为文档建议的内容,但无济于事:

android {
    defaultConfig {
        minSdkVersion 20
    }
}
Run Code Online (Sandbox Code Playgroud)

如果旧版本的 webkit 允许编译 sdk 版本较低,我会很乐意使用它,但我尝试了 flutter_webview 版本 1.0.7 和 2.8.0,结果相同。我如何避免这种看似限制性的行为?

按照建议将其更改compileSdkVersion为 32 是否仍允许我支持使用 31 或更低版本的设备?

小智 5

我通过将 sdk 版本增加到 33 解决了这个问题。请参阅以下代码:

android {
ndkVersion "25.0.8775105"
compileSdkVersion 33
ndkVersion flutter.ndkVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.anncad.news_app_flutter"
    // You can update the following values to match your application needs.
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
    minSdkVersion 21
    targetSdkVersion 33
    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
    }
}
Run Code Online (Sandbox Code Playgroud)

}

  • 在哪里编辑这个脚本?这是什么文件? (2认同)