【问题标题】:Flutter "compileSdkVersion is not specified. Please add it to build.gradle" even though I have added itFlutter "compileSdkVersion is not specified. Please add it to build.gradle" 即使我已经添加了
【发布时间】:2021-08-27 17:13:15
【问题描述】:

在我的手机

上尝试调试我的颤振应用时出现以下错误

FAILURE:构建失败并出现异常。

  • 出了什么问题:配置根项目“android”时出现问题。

compileSdkVersion 未指定。请将其添加到 build.gradle

我的应用程序构建。 gradle 文件如下:

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 FileNotFoundException("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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 30

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.wizzcrete"
        minSdkVersion 23
        targetSdkVersion 30
        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 '../..'
}

我的android build.gradle文件如下:

buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}



apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

我检查了我的 SDK 版本,它确实是 30。我什至尝试使用 Android SDK 版本 29 并将 gradle 中的编译和目标 SDK 版本更新为 29,但仍然无法正常工作。我的 minSDK 版本是 23,因为要在 Flutter 中使用 Firebase,至少需要 23。我希望这些信息足以传达问题,有什么想法吗?

【问题讨论】:

  • 我注意到了一些事情,我的另一个应用程序没有使用 Firebase 等。所以我使用了具有 GradleException 而不是 FileNotFoundException 的原始 gradle(app build.gradle 的第 10 行)和该应用程序构建良好。所以我在这个应用程序中更改了它,并使用了其他应用程序中使用的原始设置。仍然得到同样的例外。那是我的 Firebase 造成的吗?

标签: android flutter gradle


【解决方案1】:

已解决

问题是我没有将所有必要的 firebase 依赖项添加到我的项目级 gradle 中。我添加的插件在应用程序级别的 gradle 中是错误的,它们应该在项目级别的 gradle 中。此外,我必须向我的项目级 gradle 添加缺少的依赖项,例如 firebase 核心 bom 和 firestore 和身份验证依赖项的实现,如下所示:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:28.4.0')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-firestore-ktx'
}

我添加这个答案是为了帮助另一个像我这样迷失的灵魂在这个问题上花了 6 个多小时绞尽脑汁。总结一下:检查两个 gradle 文件中的依赖关系,并确保所有内容都已整理好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 2022-12-02
    • 2021-03-24
    相关资源
    最近更新 更多