Repository: flutter
Issue: Error resolving plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0'],  Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by settings file 'settings.gradle'
Labels: waiting for customer response,in triage

### Steps to reproduce

This is a follow-up to https://github.com/flutter/flutter/issues/144751 which still persist:

I created a fresh project, but was immediately warned that my Java version 21 doesn't work for Gradle version 8.3,  
and I'm offered to switch to the compatible Gradle version range: 8.4 - 8.7, which I did (I tried both 8.4 and 8.7),
but when I do that, I get the error 
```
* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0']
> Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by settings file 'settings.gradle'
```

Please see the full experiment below:

```
mh@mh-mbp flutter % flutter doctor                                                       
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.2, on macOS 15.2 24C101 darwin-x64, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.96.4)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

mh@mh-mbp flutter % flutter create test && cd test
Creating project test...
Resolving dependencies in `test`... 
Downloading packages... 
Got dependencies in `test`.
Wrote 130 files.

All done!
You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

In order to run your application, type:

  $ cd test
  $ flutter run

Your application code is in test/lib/main.dart.

The configured version of Java detected may conflict with the Gradle version in your new Flutter app.

To keep the default AGP version Gradle version 8.3, download a compatible Java version
(Java 17 <= (Java 17 <= compatible Java version < Java 21) Java version < Java 21). Configure this Java version
globally for Flutter by running:

  flutter config --jdk-dir=<JDK_DIRECTORY>


Alternatively, to continue using your configured Java version, update the Gradle
version specified in the following file to a compatible Gradle version (compatible Gradle version range: 8.4 - 8.7):
/Users/mh/flutter/test/android/gradle/wrapper/gradle-wrapper.properties

You may also update the Gradle version used by running
`./gradlew wrapper --gradle-version=<COMPATIBLE_GRADLE_VERSION>`.

See
https://docs.gradle.org/current/userguide/compatibility.html#java for details
on compatible Java/Gradle versions, and see
https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:upgrading_wrapper
for more details on using the Gradle Wrapper command to update the Gradle version
used.

mh@mh-mbp test % nano /Users/mh/flutter/test/android/gradle/wrapper/gradle-wrapper.properties

mh@mh-mbp test % cat /Users/mh/flutter/test/android/gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip

mh@mh-mbp test % flutter run
Launching lib/main.dart on Nexus 6P in debug mode...

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/mh/flutter/test/android/settings.gradle' line: 20

* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0']
> Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by settings file 'settings.gradle'

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 662ms
Running Gradle task 'assembleDebug'...                           1.519ms
Error: Gradle task assembleDebug failed with exit code 1
```

### Expected results

Build should work with Java Version 21 and Android Gradle Plugin 8.4 or 8.7

### Actual results

```
FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/mh/flutter/test/android/settings.gradle' line: 20

* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0']
> Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by settings file 'settings.gradle'
```

### Code sample

<details open><summary>Sample</summary>

```console
flutter create test
```

</details>


### Screenshots or Video

n/a

### Logs

<details open><summary>Logs</summary>

```console
mh@mh-mbp flutter % flutter doctor                                                       
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.2, on macOS 15.2 24C101 darwin-x64, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.96.4)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

mh@mh-mbp flutter % flutter create test && cd test
Creating project test...
Resolving dependencies in `test`... 
Downloading packages... 
Got dependencies in `test`.
Wrote 130 files.

All done!
You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

In order to run your application, type:

  $ cd test
  $ flutter run

Your application code is in test/lib/main.dart.

The configured version of Java detected may conflict with the Gradle version in your new Flutter app.

To keep the default AGP version Gradle version 8.3, download a compatible Java version
(Java 17 <= (Java 17 <= compatible Java version < Java 21) Java version < Java 21). Configure this Java version
globally for Flutter by running:

  flutter config --jdk-dir=<JDK_DIRECTORY>


Alternatively, to continue using your configured Java version, update the Gradle
version specified in the following file to a compatible Gradle version (compatible Gradle version range: 8.4 - 8.7):
/Users/mh/flutter/test/android/gradle/wrapper/gradle-wrapper.properties

You may also update the Gradle version used by running
`./gradlew wrapper --gradle-version=<COMPATIBLE_GRADLE_VERSION>`.

See
https://docs.gradle.org/current/userguide/compatibility.html#java for details
on compatible Java/Gradle versions, and see
https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:upgrading_wrapper
for more details on using the Gradle Wrapper command to update the Gradle version
used.

mh@mh-mbp test % nano /Users/mh/flutter/test/android/gradle/wrapper/gradle-wrapper.properties

mh@mh-mbp test % cat /Users/mh/flutter/test/android/gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip

mh@mh-mbp test % flutter run
Launching lib/main.dart on Nexus 6P in debug mode...

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/mh/flutter/test/android/settings.gradle' line: 20

* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0']
> Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by settings file 'settings.gradle'

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 662ms
Running Gradle task 'assembleDebug'...                           1.519ms
Error: Gradle task assembleDebug failed with exit code 1
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.2, on macOS 15.2 24C101 darwin-x64, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.96.4)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!
```

verbose:
```
[✓] Flutter (Channel stable, 3.27.2, on macOS 15.2 24C101 darwin-x64, locale de-DE)
    • Flutter version 3.27.2 on channel stable at /Users/mh/devtools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 68415ad1d9 (6 days ago), 2025-01-13 10:22:03 -0800
    • Engine revision e672b006cb
    • Dart version 3.6.1
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
    • Android SDK at /Users/mh/Library/Android/sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)

[✓] VS Code (version 1.96.4)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (4 available)

[✓] Network resources
    • All expected network resources are available.
```

</details>