0

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.

Siddharth Mehra
  • 1,691
  • 1
  • 9
  • 32
Anant Jain
  • 29
  • 8
  • Can please add your full build.gradle? – Taym95 Jun 14 '19 at 07:55
  • Possible duplicate of [Unable to migrate Flutter project to AndroidX](https://stackoverflow.com/questions/54395491/unable-to-migrate-flutter-project-to-androidx) – Zoe Jun 14 '19 at 10:45

2 Answers2

0

I would recommend using android studio feature to migrate the project to android X, instead of doing it manually.

From the source: Migrate the project to android X using android studio

With Android Studio 3.2 and higher, you can quickly migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

Harshvardhan Joshi
  • 2,855
  • 2
  • 18
  • 31
0

Do it with android studio.

Open the project in the studio and change the minSdk version to 23. You need to update the gradle version also and make it to more than 3.6.0. than go to refractor. There you will get the option of migrate to Android x .and do refractor. It will ask you to take the backup. And after that at the bottom you will get the popup of "Do Refractor". and that's it.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Raju Gupta
  • 752
  • 5
  • 10