According to the documentation for "webview_flutter", the package requires Android SDK 20+. Immediately after running flutter pub add webview_flutter and restarting my app (without even attempting to use WebView yet), I'm greeted with the following error:
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
The device I'm testing on and compiling for is running version 31.
My android/app/build.gradle file:
...
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"
}
I've also attempted to change the minSdkVersion to what the docs suggest, to no avail:
android {
defaultConfig {
minSdkVersion 20
}
}
I'll happily use an older version of webkit if it allows the compile sdk version to be lower, but I've tried flutter_webview versions 1.0.7 and 2.8.0 with the same result. How do I avoid this seemingly restrictive behaviour?
Will changing the compileSdkVersion to 32 as it suggests, still allow me to support devices using 31 or lower?
I fixed this issue by increasing sdk version to 33. Refer below code:
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
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With