使用supabase_flutter时为何出现compileSdkVersion未指定的编译错误?
问题详情
- 编译错误:配置
:shared_preferences_android项目时失败
Failed to notify project evaluation listener.
Cannot invoke method substring() on null object
compileSdkVersion is not specified. Please add it to build.gradle
- 疑似触发场景:升级Flutter 3.19后出现(暂未完全确认)
解决方案
1. 替换动态compileSdkVersion为具体版本号
在app/build.gradle的android块中,将compileSdk flutter.compileSdkVersion替换为明确的版本号(Flutter 3.19对应推荐版本为34),同时同步targetSdkVersion:
android { // ...其他配置 compileSdk 34 ndkVersion flutter.ndkVersion defaultConfig { // ...其他配置 targetSdkVersion 34 // ...其他配置 } // ...其他配置 }
2. 确保根目录build.gradle配置匹配
检查项目根目录下的build.gradle,确保Gradle插件和Kotlin版本与Flutter 3.19兼容:
buildscript { ext.kotlin_version = '1.9.0' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }
3. 清理缓存后重新构建
执行以下命令清除缓存并重新编译:
flutter clean rm -rf android/.gradle flutter pub get flutter run
原app/build.gradle代码
plugins { id "com.android.application" id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" } def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } android { namespace "com.example.exp" compileSdk flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } 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.example.app" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } 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.debug } } } flutter { source '../..' } dependencies {}
内容的提问来源于stack exchange,提问作者A.Sanchez.SD
相关产品推荐
相关产品推荐

