Flutter Projects & Android X Migration Issues

做~自己de王妃 提交于 2019-12-17 06:41:45

问题


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:

  1. updated Android Studio to 3.3
  2. tried menu Refactor > Migrate to AndroidX
  3. 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)
  4. opened android/gradle.properties and added
android.useAndroidX=true
android.enableJetifier=true
  1. opened android/build.gradle and changed

    • com.android.tools.build:gradle to version 3.3.0
    • com.google.gms:google-services to version 4.2.0
  2. opened android/app/build.gradle and

    • changed compileSdkVersion to 28
    • replaced android.support.test.runner.AndroidJUnitRunner to androidx.test.runner.AndroidJUnitRunner
    • replaced com.android.support.test:runner to androidx.test:runner:1.1.0
    • replaced com.android.support.test.espresso:espresso-core to androidx.test.espresso:espresso-core:3.1.0
    • in my case that was it, but here's the complete list of required replacements
  3. opened android/gradle/wrapper/gradle-wrapper.properties and changed distributionUrl to https\://services.gradle.org/distributions/gradle-4.10.2-all.zip (you might have to use 5.4.1, please see update below)

  4. 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

  1. In project level build.gradle change classpath to com.android.tools.build:gradle:3.3.1.
  2. In app level build.gradle change your compileSdkVersion and targetSdkVersion to 28.
  3. 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.
  4. Now go to Refactor in the toolbar and click Migrate to AndroidX.
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!