问题
I just created a new flutter project, added a few plugins and I'm getting the plugin switched to android x therefore i need to switch to android x. I've tried all the different ways of moving to android x and none has worked for me so far. Right now i don't even know what to do anymore, its so frustrating, why wouldn't flutter handle that when creating new projects automatically. Might be using ionic for the project.
回答1:
As you are creating a new project, just follow @harsh 's answer and you're done.
However, as I recently upgraded my existing app to use new plugins, I had to migrate to AndroidX as well... and the default procedure in the official instructions didn't work, which is using Android Studio to migrate the project - it said "No usages found!".
So what I did was:
- updated Android Studio to 3.3
- tried menu Refactor > Migrate to AndroidX
- got "No usages found" (if you manage to do it here instead, stop! you're done! ... actually, you can give this answer a try before continuing)
- opened
android/gradle.properties
and added
android.useAndroidX=true
android.enableJetifier=true
opened
android/build.gradle
and changedcom.android.tools.build:gradle
to version3.3.0
com.google.gms:google-services
to version4.2.0
opened
android/app/build.gradle
and- changed
compileSdkVersion
to28
- replaced
android.support.test.runner.AndroidJUnitRunner
toandroidx.test.runner.AndroidJUnitRunner
- replaced
com.android.support.test:runner
toandroidx.test:runner:1.1.0
- replaced
com.android.support.test.espresso:espresso-core
toandroidx.test.espresso:espresso-core:3.1.0
- in my case that was it, but here's the complete list of required replacements
- changed
opened
android/gradle/wrapper/gradle-wrapper.properties
and changeddistributionUrl
tohttps\://services.gradle.org/distributions/gradle-4.10.2-all.zip
(you might have to use 5.4.1, please see update below)executed
flutter clean
And contrary to what I expected, IT WORKED! :)
UPDATE (2019 October 27th)
When updating my app to flutter v1.9.1+hotfix.5
, as I use app signing, I was stuck with the error SigningConfig "release" is missing required property "storePassword"
and in the end it was the gradle version from step 7 above. So now I'm using 5.4.1 as suggested in this wiki.
[android/gradle/wrapper/gradle-wrapper.properties]
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
回答2:
I've made the migration successfully by using Sam's answer!
1. Open the Flutter project into Android Studio
2. Right click on the android directory and 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 chek the Goolge Play Services.
回答3:
When you update your Android Studio version from 3.2 to 3.3. Android Studio version 3.3 onwards you can either use either android libraries or androidx libraries but
In flutter platform, flutter will always take the newest configuration of android studio.
This is the main reason why users get an error to use dependency according to androidx.
To migrate the flutter project to AndroidX, check this link: https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
回答4:
I Faced this problem recently. After looking for many hours I came across this medium page https://medium.com/@swhussain110/how-to-migrate-your-flutter-app-to-androidx-9a78eaaa924b
Follow these steps
- In project level build.gradle change classpath to
com.android.tools.build:gradle:3.3.1
. - In app level build.gradle change your
compileSdkVersion
andtargetSdkVersion
to 28. - Now right click on android directory in your flutter project go to Flutter and click on Open Android module in Android Studio. Open project in a new window.
- Now go to Refactor in the toolbar and click Migrate to AndroidX.
- Then click Do Refactor and wait for gradle to build.
回答5:
it was still not working after I migrated to androidx
I simply install google play service on my sdk and it worked
来源:https://stackoverflow.com/questions/54851489/flutter-projects-android-x-migration-issues