依赖项 'androidx.webkit:webkit:1.5.0' 要求将 'compileSdkVersion' 设置为 32 或更高版本



根据"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

我正在测试和编译的设备正在运行版本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"
}

我还试图将minSdkVersion更改为文档建议的内容,但没有成功:

android {
defaultConfig {
minSdkVersion 20
}
}

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

compileSdkVersion更改为32是否仍然允许我支持使用31或更低版本的设备?

我通过将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
}
}

}

compileSdkVersion是用于编译应用程序的SDK版本,与设备的Android版本无关。

任何compileSdkVersion都可以在您拥有的任何设备上工作。32和31几乎相同,31是安卓12,32是安卓12L,所以如果你已经在使用31,那么使用32是安全的。

我遇到了同样的问题。我相信Android 10(SDK 29(是非谷歌手机所必需的。有可能在某个地方回滚到androidx.webkit:webkit:1.4.0吗?

当前正在使用以下版本运行构建:

flutter.minSdkVersion=29
flutter.targetSdkVersion=32
flutter.compileSdkVersion=33

有了这些:

ext.kotlin_version = '1.6.21'
classpath 'com.android.tools.build:gradle:7.1.2'

相关内容

最新更新