6

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

0

2 Answers 2

23

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

Sign up to request clarification or add additional context in comments.

2 Comments

UPD: Faced the issue in February 2022. The solution fixed it, but as it was stated in a warning, jcenter() got shut down, so it is removed from settings.gradle, and also should not be listed in allprojects {...} (step 2)
Instead of changing project settings remove the entire dependencyResolutionMangament, it'll solve the error.
-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

1 Comment

I created a new android app, after that, created a new flutter module using android studio. The problem reported appeared. After using your solution, I got a new error: Could not find method dependencyResolutionManagement() for arguments [settings_dc3nelhdckh73npb3p919kj3r$_run_closure1@58223593] on settings 'MyApplication' of type org.gradle.initialization.DefaultSettings I'm going to post later when I fix it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.