marvin ralph
marvin ralph

Reputation: 1280

Flutter Projects & Android X Migration Issues

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.

Upvotes: 32

Views: 49070

Answers (9)

Sachitha Ilayperuma
Sachitha Ilayperuma

Reputation: 43

Faced with the same issue.

In my build.gradle compileSdkVersion and targetSdkVersion were already set to 28. minSdkVersion was set to 23.

Had already added android.useAndroidX=true android.enableJetifier=true to my android/graddle.properties.

After adding all these still migrating to AndroidX was not possible. When doing so a message pop up saying "No usage found in this project"

Adding the following code to my app/build.gradle solved the issue.

android {

defaultConfig {
    ...
      minSdkVersion 23 
      targetSdkVersion 28
      multiDexEnabled true
}

}

dependencies {

implementation 'com.android.support:multidex:1.0.3'

}

Upvotes: 0

Renaud
Renaud

Reputation: 51

Add this to the end of your pubspec.yaml file, without any parent:

module:
  androidX: true

Then, at android/graddle.properties add:

android.useAndroidX=true
android.enableJetifier=true

Run at your CLI:

flutter clean

and rerun your code

flutter run

This may adjust your problem with AndroidX.

For your SDK, i think you may change inside android/app/build.gradle

minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true

the multiDexEnabled is optional (in case of some error related to it).

I think this may solve your problem, please give me a feedback about it.

Upvotes: 5

Rajath
Rajath

Reputation: 2981

I faced the similar problem.

This Medium article helped me to find 75% solution for my problem

I followed the steps mentioned in this article. and I'm stuck in the end

Android studio is not allowed me to open android module (folder) from the project structure directly. So I opend manually in the new window of android studio.

Android is not refactored the gradle testRunner classpath androidTestImplementation it is prompting like is dependent So then I manually replaced all the paths like.

  • 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

and at the end I added to android/gradle.properties

android.useAndroidX=true
android.enableJetifier=true

Then ran the application. ;) after that androidX warning disappeared.

Upvotes: 1

Robert Apikyan
Robert Apikyan

Reputation: 2092

After a lot of tries, I've just created a new Flutter project and just copy past the pubspec.yaml, lib and assets folder from the old project to the new one, and the problem solved

Upvotes: 4

Feu
Feu

Reputation: 5780

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

Upvotes: 81

kojo justine
kojo justine

Reputation: 113

it was still not working after I migrated to androidx

I simply install google play service on my sdk and it worked

Upvotes: 0

A Vyom
A Vyom

Reputation: 135

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.

Upvotes: 3

Luan Almeida
Luan Almeida

Reputation: 61

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.

Upvotes: 6

harsh
harsh

Reputation: 337

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

Upvotes: 1

Related Questions