Androidx error creating new flutter project in Android Studio

First, update the Gradle version in build.gradle file in the root of android folder to 3.5.1.

Then update test dependencies in build.gradle file in the android/app/ directory to androidx as follws.

androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

And update distributionUrl in android/gradle/wrapper/gradle-wrapper.properties to

distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

Download a newver version of Flutter SDK from the Flutter official website and replace the old version on your hard drive with it. I worked for me.


Due to no upgrade for a long while, I need to upgrade the flutter by running the following command in terminal:

flutter upgrade --force

There's an accepted answer already but to me the way to solve that was very different, so I still post it hoping for it to be useful to someone.

In my case, I just had to update flutter. To do so, I ran

flutter upgrade

from the command line. That took a few minutes. Afterwards I was able to create a Flutter project from Android Studio flawlessly.