Flutter项目执行gradlew构建时遭遇插件缺失与compileSdkVersion未指定问题求助
Flutter项目执行gradlew构建时遭遇插件缺失与compileSdkVersion未指定问题求助
各位Flutter/Gradle大佬好,我最近在给我的Flutter项目做Android构建时卡壳了,执行构建命令后直接报了两个错误,试了GPT和Claude给的方案都不管用,实在没辙了来这儿求助!
我执行的构建命令是:
./gradlew clean assembleDebug
得到的完整构建失败日志如下:
FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * Where: Build file '/Users/kb/trial_app/android/app/build.gradle' line: 6 * What went wrong: A problem occurred evaluating project ':app'. > Plugin with id 'io.flutter.flutter-gradle-plugin' not found. * 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. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: A problem occurred configuring project ':app'. > compileSdkVersion is not specified. Please add it to build.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 486ms
我已经尝试过的解决方案:
- 更换过不同的Gradle分发URL
- 尝试把compileSdkVersion放到defaultConfig节点里(现在是在android根节点下)
- 已经将Flutter更新到最新版本
我的相关Gradle配置文件:
android/build.gradle
buildscript { // 1. Kotlin plugin version for Android builds ext.kotlin_version = '1.8.20' repositories { google() mavenCentral() } dependencies { // 2. Android Gradle Plugin classpath 'com.android.tools.build:gradle:7.3.0' // 3. Kotlin Gradle plugin classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // 4. Google Services plugin for Firebase classpath 'com.google.gms:google-services:4.3.15' } } // 5. Shared repositories for all subprojects allprojects { repositories { google() mavenCentral() } } // 6. Clean task to remove the build directory task clean(type: Delete) { delete rootProject.buildDir }
android/app/build.gradle
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' // 2. Apply the Google Services plugin for Firebase apply plugin: 'com.google.gms.google-services' // 3. Apply Flutter's Gradle plugin apply plugin: 'io.flutter.flutter-gradle-plugin' android { // 4. Your application namespace namespace 'com.kk.g_app' compileSdkVersion 33 defaultConfig { applicationId 'com.kk.g_app' minSdkVersion 23 targetSdkVersion 33 versionCode 1 versionName '1.0' } // 5. Java/Kotlin compatibility compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = '11' } buildTypes { release { // No code shrinking by default minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { // 6. Firebase BOM and Analytics implementation platform('com.google.firebase:firebase-bom:33.10.0') implementation 'com.google.firebase:firebase-analytics' }
现在我特别困惑:明明我已经在app/build.gradle的android节点下明确写了compileSdkVersion 33,但构建还是提示未指定;另外Flutter的Gradle插件找不到的问题也一直存在。有没有大佬能帮我排查下问题到底出在哪?
内容来源于stack exchange
相关产品推荐
相关产品推荐

