Reputation: 3054
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.
Is there anything else I need to do?
Upvotes: 33
Views: 22423
Reputation: 3054
I was able to resolve my issue:
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.
Upvotes: 57
Reputation: 173
A simple solution. follow the steps.
Add some lines in the android --> app --> build.gradle as follow, update the defaultConfig
minSdkVersion 19
targetSdkVersion 28
multiDexEnabled true
hope it works now ...
Upvotes: 0
Reputation: 81
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.
Go to "Project Structure" - (2nd icon on left of AVD Manager icon on top right corner of IDE)
On "Project Structure" dialog under left navigation click on Project Settings->Modules
After selecting Modules, on the right pane you should see 3 tabs Sources, Paths, Dependencies
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
Upvotes: 8
Reputation: 364
Go to "Project structure" in the Files menu. Clear out every issue you see there, like set the android sdk, fix the problems specified
Upvotes: 0
Reputation: 708
Try replacing the default in dependencies {...}
in app/build.gradle with this:
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
The replacement is similar to what is posted in the "Not recommended..." section from this link: https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
If you can explain why this works, please add a comment. Thank you!
Upvotes: 0
Reputation: 567
Click on Invalidate cache/Restart from file option worked for me
Upvotes: 0
Reputation: 1
I'm having exact same problem. Been trying to migrate since all the new firebase stuff is forcing it, but the current guides to upgrade are sparse. First I was trying on a backup of my project with a lot of addons and kept getting that error, then I created a brand new flutter project with all the latest (dev channel), followed every step, checked every detail, read every forum, but still getting "You need to have compileSdk set to at least 28 in your module build.gradle to migrate to AndroidX."... Matched the steps from https://androidxhackathon.blogspot.com/2018/05/refactor-to-android-x.html too and can't get it to refactor right. Even went to File>ProjectStructure>Project SDK and set to Android API 28 Platform. Anyone know what we might be missing? Did you have any luck Sam?
Upvotes: 0
Reputation: 1326
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
Upvotes: 4