Unable to migrate Flutter project to AndroidX

20,408

Solution 1

I was able to resolve my issue:

  1. Open the Flutter project into Android Studio
  2. Right click on the android directory, click on Flutter -> Open Android module in Android Studio. It asked me to upgrade my gradle plugin.
  3. Then I installed Google Play Services. Tools -> SDK Manager -> SDK Tools and check the Google Play Services.

After the Google Play Services Installed, I did Refactor -> Migrate to AndroidX. It started working.

Note: Do the refactor from the project window you opened in the step 2.

Solution 2

Here is how I got rid of "compileSdkVersion 28" error. But before I solved it this way, I upgraded Android Studio IDE from 3.4.1 -> 3.5.1. I am not sure if this was really needed. So whatever version of IDE you have, see if you can use following steps to solve it.

  1. Go to "Project Structure" - (2nd icon on left of AVD Manager icon on top right corner of IDE)

  2. On "Project Structure" dialog under left navigation click on Project Settings->Modules

  3. After selecting Modules, on the right pane you should see 3 tabs Sources, Paths, Dependencies

  4. Click on Dependencies, if you are getting compileSdkVersion 28 error the SDK version under Dependencies is pointing to version lower than 28 -> Select 28 or higher

Project Structure -> Modules -> Dependencies 5. Click OK

  1. Now Refactor->Migrate to AndroidX worked for me

Solution 3

In gradle.build (app) add this

 compileSdkVersion 28
    defaultConfig {
        ......
        minSdkVersion 21
        targetSdkVersion 28
        ......
    }

And there are some implementations required to use androidx :-

implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

And add these given two lines(below) to gradle.properties:-

android.useAndroidX=true
android.enableJetifier=true
Share:
20,408
Sam
Author by

Sam

Updated on October 07, 2021

Comments

  • Sam
    Sam over 2 years

    I have a Flutter project in Android Studio. I am planning to migrate to AndroidX. Whenever I do Refactor -> Migrate to AndroidX, Android Studio shows error message:

    You need to have compileSdk set to at least 28 in your module build.gradle to migrate to AndroidX.

    However I have already set the compileSdkVersion 28 in my app/gradle.build file.

    enter image description here

    Is there anything else I need to do?