Dependency 'androidx.webkit:webkit:1.5.0' requires 'compileSdkVersion' to be set to 32 or higher - flutter

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
}
}
}

compileSdkVersion is the SDK version used to compile your app, has nothing to do with the Android version your device has.
Any compileSdkVersion will work on any device you have.
32 and 31 are almost the same, 31 is Android 12 and 32 is Android 12L, so if you are already using 31 is safe to use 32.

I am running into the same issue. I believe Android 10 (SDK 29) is required for non Google phones. Would it be possible to roll back to androidx.webkit:webkit:1.4.0 somewhere?
Currently running builds with:
flutter.minSdkVersion=29
flutter.targetSdkVersion=32
flutter.compileSdkVersion=33
With these:
ext.kotlin_version = '1.6.21'
classpath 'com.android.tools.build:gradle:7.1.2'

Related

Could not determine the dependencies of task ':agora_rtc_engine:compileReleaseKotlin'

After upgrading to agora_rtc_engine 5.0.0 I'm experiencing the following build error:
Command: flutter build appbundle
Error message:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':agora_rtc_engine:compileReleaseKotlin'.
> Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
This is the setup in my build gradle:
defaultConfig {
applicationId "com.MyPackage"
minSdkVersion 24
targetSdkVersion 32
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
I tried uninstalling and reinstalling build tools, upgrading gradle version, but no luck. Anyone experiencing the same issue?
In the meantime I'm downgrading to 4.2.1 as I'm not in need of any new feature, but eventually I'll need to update.
Try changing your targetSDKVersion to 31

Missing compileSdkVersion for google mobile ads

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.ringit2"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Here is what I found on my build.gradle and I can't find compileSdkVersion which I have to change to at least 28 in order for google mobile ads to operate.
After I added google_mobile_ads: ^1.1.0 on pubspec.yaml and imported the package to the main.dart, The app opens as I run the simulator but shuts down right away. Console shows me this message and it is stuck just like this forever.
Launching lib\main.dart on SM G950N in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Please note that my ext.kotlin_version is '1.6.10' because people have recommended to upgrade it
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
Also changed the distributionUrl...
Not sure why google mobile ads package is so hard to use even just to start but what should I change to use it?
I am also using kotlin version '1.6.10' and compilesdk version is inside android>app>build.gradle
The compileSdkVersion will be inside
android>app>build.gradle
inside that you can see compileSdkVersion in line 30
Also check your environment path of flutter

Flutter error: Execution failed for task ':app:compileDebugJavaWithJavac'

I try run on android and return this error.
I Aredy tried:
gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
build.gradle:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
my pubspec.yaml:
flutter_facebook_login: ^3.0.0
firebase_database: ^3.1.0
firebase_auth: ^0.15.0+1
cloud_firestore: ^0.12.11
url_launcher: ^5.2.7
google_maps_flutter: ^0.5.21+12
image_picker: ^0.6.2+1
firebase_storage: ^3.0.8
intl: ^0.16.0
What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 35s The built failed likely due to AndroidX
incompatibilities in a plugin. The tool is about to try using Jetfier
to solve the incompatibility. Building plugin cloud_firestore... The
plugin cloud_firestore could not be built due to the issue above.
SOLUTION:
When you created the new project, did you select "androidX"? And are those versions the latest versions? (meaning, androidX compatible/requiring). if not sure, create a new project and make sure to select androidX, and change the sdk settings to 23/29 as above.
Edit: Solution was a combination of creating a new project with AndroidX selected and add the proper SDK versions to the gradle file. Possibly with using correct dependency versions.
To migrate to AndroidX, you need to set the SDK versions to 21 or higher. I recommend 23 because that removes some other issues as well.
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example"
minSdkVersion 23
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
I recently encountered this error using Flutter 2.2.2, None of the above solutions worked for me.
First try basic commands like:
cd android && ./gradlew clean
flutter clean
If it doesn't work:
set distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip in android/gradle/wrapper/gradle-wrapper.properties
if your gradle version is <= 6.7 (refer gradle issue)
Try basic commands and build again!
Solution
flutter clean
delete android/.gradle and run
revert pubspec.lock and flutter pub get
flutter run
Change compileSdkVersion value to flutter.compileSdkVersion
also change minSdkVersion,targetSdkVersion values as shown below
android {
compileSdkVersion flutter.compileSdkVersion
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.example.octs"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
This worked for me.
None of answers above helped me. I use IntelliJ Idea as an IDE instead of Android Studio (because I develop other modules in other langs, not only Flutter app). I was able to run ./gradlew :app:compileDebugJavaWithJavac from command line, but flutter run failed. After long time I've realized that Flutter uses Android Studio to let it build android app. So if you use IntelliJ Idea, do check what Java you use not only in Idea (I use Java 11), but what Java you use in Android Studio! (mine AS used Java 8). After changing to Java 11, problem was solved.
I solved my problem by changing the version (reduced the gradle version), which caused me another problem, but related to one API and Kotlin plugin. Since I cannot delete Kotlin I took out the API and it came to life again! thanks for your help here!
Try this package flutter_stripe: ^3.2.0

Flutter appbundle building using older version

I want to upload the second version of my Flutter app to the internal test channel on Google Play (I am just working with the Android version for now).
I could upload the first version 1.0.0+1 but when trying to upload the second version 1.0.1+2 Google Play Console is rejecting my appbundle with error message
You need to use a different version code for your APK because you already have one with version code 1.
I have already tried the sequence:
flutter clean to delete build and temp folders.
Modifying version line on pubspec.yaml from 1.0.0+1 to 1.0.1+2.
flutter pub get to rebuild flutter needed files.
flutter build appbundle to get the bundle built.
Since I have been already able to build and publish the first version of the app I assume that the rest of the build configuration is OK.
Most of the solutions aim to clean project, modify pubspec.yaml and then rebuild but this seems not to be working for me.
EDIT:
tried to modify build.gradle file using values flutterVersionName = '1.0.1' and flutterVersionCode = '2' and I am still getting an appbundle with versionCode 1.
Android app version code and version name are defined in android/app/build.gradle. Take a look at this file and check if these lines are included
...
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
...
defaultConfig {
applicationId "net.myapp"
minSdkVersion 18
targetSdkVersion 28
versionCode flutterVersionCode.toInteger() //<-this line defines versionCode
versionName flutterVersionName
...
If everything is ok, take a look at android/local.properties file. This file is updated when Flutter build the app. It should have these lines, generated from your pubspec.yaml data:
flutter.versionName=1.1.1
flutter.versionCode=9
If both files are ok, run a flutter build apk to regenerate local.properties data.
Found a workaround good enough and that is building the appbundle not using Flutter sdk, but using Android Studio.
In order to achieve that do the following:
Open Android Studio > Open android project (android folder in your Flutter project)
Then modify your app level build.gradle as follows:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "<YOUR_APP_ID>"
minSdkVersion 21
targetSdkVersion 28
versionCode 2 // Manually add your desired version code
versionName "1.0.1" // Manually add your desired version name
// versionCode flutterVersionCode.toInteger()
// versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Then go to Build > Generate Signed Bundle / APK... to generate your bundle or APK as if you were building a native app (further instructions to generate a signed app bundle can be found here
Please note that this does not fully solve the issue since the bundle still cannot be correctly generated using Flutter sdk.

flutter firebase error "FAILURE: Build failed with an exception"

project/build.gradle
apply plugin: 'com.android.application'
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.3.2'
}
In app/build.gradle
line no.24 apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "blablabla.com"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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 '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
}
apply plugin: 'com.google.gms.google-services'
In pubspec.yaml
dependencies:
flutter:
sdk: flutter
firebase_database: ^2.0.2
firebase_core: ^0.3.1+1
timeago: ^2.0.10
Im getting this error
$ flutter run
Using hardware rendering with device Android SDK built for x86. If you
get graphics artifacts, consider enabling software rendering with
"--enable-software-rendering".
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle... 2.2s
Resolving dependencies...
* Error running Gradle:
ProcessException: Process
"C:\Users\Krishnaganesh\Desktop\flutter_blog_app-master\android\gradlew.bat" exited abnormally:
FAILURE: Build failed with an exception.
* Where:
Build file
'C:\Users\Krishnaganesh\Desktop\flutter_blog_app-master\android\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> ASCII
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or
--debug option to get more log output. Run with --scan to get full
insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
Command:
C:\Users\Krishnaganesh\Desktop\flutter_blog_app-master\android\gradlew .bat app:properties
Please review your Gradle project setup in the android/ folder.
How to solve this Error ...???
Bump dependencies versions:
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.google.gms:google-services:4.3.3'
firebase_database: ^3.1.0
firebase_core: ^0.4.2+1
In app/build.gradle add these:
android {
...
defaultConfig {
...
multiDexEnabled true // add this
}
}
dependencies {
...
implementation 'com.android.support:multidex:1.0.3' // add this
}
Don't forget to create google-services.json file in app/ folder and fill it with your data (docs link) or use some mock (like this one):
{
"project_info": {...},
"client": [...],
}