skip to Main Content

I got strange bugs,

After I upgrade Android Studio :

enter image description here

I created an Android project, run it a success.

Then I tried to import Flutter Module to this Android project.

I had these exceptions,

Blockquote

Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin class ‘FlutterPlugin’.

Caused by: org.Gradle.API.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by plugin class ‘FlutterPlugin’

I searched but did not find the solution for that exception, even Clean project, Gradle clean build, and Restart & Invalidate Project.

Please help me to solve this,

Thanks,

p/s: At the previous Android Studio version, I did that normally. (very simple)

Run android project success before import flutter module

enter image description here

Project structure

Project structure

settings.Gradle after imported Flutter Module

enter image description here

Current Version

enter image description here

Gradle clean build command line

enter image description here

2

Answers


  1. For Flutter 2.2.3, downgrade gradle version. don’t use gradle 7. it’s not compatible with flutter.gradle.

    in android project build.gradle:

    dependencies {
     classpath 'com.android.tools.build:gradle:4.2.2'
     ...
    }
    

    in android project gradle-wrapper.properties:

    distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
    
    Login or Signup to reply.
  2. For Android Studio Arctic Fox | 2020.3.1 Patch 2 and Flutter 2.2.3 have the same issues,follow these steps fix it.

    1.open android project settings.gradle,change FAIL_ON_PROJECT_REPOS to PREFER_PROJECT

    dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
    

    }

    1. open android project build.gradle add these configs

      allprojects {
      repositories {
      google()
      jcenter()
      }
      }

    2. rebuild the project

    https://docs.gradle.org/current/javadoc/org/gradle/api/initialization/resolve/RepositoriesMode.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search