I have an existing Flutter project and have resolved several issues so far. However, a new issue has arisen:
Build was configured to prefer settings repositories over project
repositories but repository ‘Gradle Libs’ was added by settings file
‘settings.gradle’
This error occurs when I open the project in Android Studio. Interestingly, when I run the project from Visual Studio Code, the error does not appear, and I am able to run the project on an emulator without any issues.
build.gradle (Project:android)
// buildscript {
// ext.kotlin_version = '1.8.0'
// repositories {
// google()
// jcenter()
// mavenCentral() // Add this repository
// }
// dependencies {
// classpath 'com.android.tools.build:gradle:7.1.3'
// classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// // Add the google services classpath
// classpath 'com.google.gms:google-services:4.3.10'
// //
// // // Add the Flutter plugin classpath
// // classpath 'dev.flutter:flutter-gradle-plugin:1.0.0' // Add this line
// }
// }
allprojects {
repositories {
google()
jcenter()
mavenCentral() // Add this repository
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
build.gradle(project.app)
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin" // Ensure this line is correct
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
// def flutterRoot = localProperties.getProperty('flutter.sdk')
// if (flutterRoot == null) {
// throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
// }
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
// apply plugin: 'com.android.application'
// apply plugin: 'kotlin-android'
// apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
// apply plugin: 'com.google.gms.google-services'
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
compileSdkVersion 33
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.mbi.MyAduanApp"
minSdkVersion 30
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs{
release{
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
}
}
lint {
disable 'InvalidPackage'
}
}
//flutter {
// source '../..'
//}
dependencies {
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20"
implementation 'com.google.firebase:firebase-messaging:21.0.1'
implementation platform('com.google.firebase:firebase-bom:26.1.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.4.0'
}
settings.gradle
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.2.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.20" apply false
}
include ":app"
I’m not sure what mistake I have made. I would greatly appreciate any help in resolving this problem.
Thank you in advance!