I have been building a Flutter App in Android App, it was all working fine, as soon as I used GeoLocator Library, my app crashed stating it is incompatible with AndroidX. When I try to Migrate my code to AndroidX, it says "You need to have compiled SDK set to at least 28 in your module build. Gradle to migrate to AndroidX. I have already set it to 28, but it still doesn't work.
In order, to resolve this. I have tried all the steps mentioned in Flutter Documentation. Link: https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
1. In android/gradle/wrapper/gradle-wrapper.properties change the line starting with distributionUrl like this:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
2. In android/build.gradle, replace:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
by
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
3. In android/gradle.properties, append
android.enableJetifier=true
android.useAndroidX=true
4.In android/app/build.gradle:
Under android {, make sure compileSdkVersion and targetSdkVersion are at least 28
5.Replace all deprecated libraries with the AndroidX equivalents. For instance, if you’re using the default .gradle files make the following changes:
In android/app/build.gradle
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
by
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Finally, under dependencies {, replace
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
by
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
This is some of my build.grade file where I have set the SDK version :
enter code here compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "co.appbrewery.clima"
minSdkVersion 28
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Tried all the things above, still getting an error that changes your SDK version to at least 28 whenever I try to set it Migrate to Android X using the Android Studio feature.