升级Android Studio Electric Eel后Gradle插件找不到求助
解决Android Studio Electric Eel构建错误的配置方案
核心问题分析
- Android Studio Electric Eel要求Android Gradle插件(AGP)版本≥7.4.0,你当前使用的7.1.2版本过低,且plugins块未配置Google仓库,导致插件无法被检索到。
- Gradle版本(8.0.2)与AGP版本(7.1.2)不兼容,同时存在配置冗余、依赖版本不匹配的问题。
正确配置文件
1. settings.gradle(需补充/修改)
pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } } rootProject.name = "connect_app" include ':app'
2. android/build.gradle
plugins { id 'com.android.application' version '7.4.2' apply false id 'com.android.library' version '7.4.2' apply false id 'org.jetbrains.kotlin.android' version '1.7.20' apply false id 'com.google.gms.google-services' version '4.4.0' apply false } allprojects { repositories { google() mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" project.evaluationDependsOn(':app') } task clean(type: Delete) { delete rootProject.buildDir }
3. app/build.gradle
def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } 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 = '2' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.1' } plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'com.google.gms.google-services' } apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion 33 defaultConfig { applicationId "com.elearning.connect" minSdkVersion 23 targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName multiDexEnabled true } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null storePassword keystoreProperties['storePassword'] } } buildTypes { release { signingConfig signingConfigs.release } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } buildFeatures { viewBinding true } } flutter { source '../..' } dependencies { implementation 'com.android.support:multidex:1.0.3' implementation platform('com.google.firebase:firebase-bom:32.7.0') implementation 'com.google.firebase:firebase-analytics' implementation 'com.google.firebase:firebase-messaging' }
关键修改说明
- 插件版本适配:将AGP升级到7.4.2(完全兼容Electric Eel),同步升级Kotlin和Google Services插件版本,避免版本冲突。
- 仓库配置:在settings.gradle中配置pluginManagement,确保Gradle能从Google仓库获取AGP插件,解决插件找不到的核心问题。
- 冗余清理:移除app/build.gradle中重复的插件应用、compileOptions配置,将属性配置移到文件开头,避免作用域异常。
- 依赖更新:升级Firebase BOM版本到32.7.0,确保与新版AGP兼容。
内容的提问来源于stack exchange,提问作者slackgate
相关产品推荐
相关产品推荐

