【问题标题】:Cannot invoke method allprojects() on null object. A problem occurred evaluating root project 'android'无法在空对象上调用方法 allprojects()。评估根项目“android”时出现问题
【发布时间】:2020-03-11 21:10:37
【问题描述】:

我在运行我的 Flutter 应用程序时遇到以下错误

  • 出了什么问题:

评估根项目“android”时出现问题。

无法在空对象上调用方法 allprojects()

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 通过https://help.gradle.org获得更多帮助

0 秒内构建失败

无法在空对象上调用方法 allprojects()

打开文件 20:26:40:任务执行完毕。

应用 build.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 plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.emart.emart_app"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    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 {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation "com.android.support-v4:27.1.1"
    implementation 'com.google.firebase:firebase-core:17.2.1'
    implementation 'com.google.firebase:firebase-analytics:17.2.1'
}

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

build.gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        jcenter()
        google()
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.3.2'
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}.

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

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

我已更新所有依赖项。使用命令 Flutter upgrade 然后使用颤振医生,它没有显示任何问题。但是当我运行该应用程序时,我在终端中收到上述错误。谢谢您的帮助。

【问题讨论】:

  • 使用命令颤振医生。它表明没有问题。 flutter doctor 医生总结(要查看所有详细信息,请运行 flutter doctor -v):[√] Flutter(Channel stable, v1.9.1+hotfix.6, on Microsoft Windows [Version 10.0.17763.864], locale en-IN)[√ ] Android 工具链 - 为 Android 设备开发(Android SDK 版本 29.0.2) [√] Android Studio(版本 3.5) [√] VS Code(版本 1.40.0) [√] 已连接设备(1 个可用) • 未发现问题!
  • allprojects 块之前有一个错字。 }.中有一个点
  • 非常感谢加布里埃尔先生的帮助。

标签: android gradle flutter dart build


【解决方案1】:

如前所述,项目的 build.gradle 文件中有一个意外字符。删除它应该有望解决问题。您可以尝试在 Android 上解决构建问题的另一个选项是重新生成特定于平台的项目文件。为此,您可以删除android 文件夹,然后在终端上运行flutter create --platforms=android 重新生成项目文件。

【讨论】:

    猜你喜欢
    • 2022-10-17
    • 2020-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 2022-08-09
    • 2022-01-07
    • 2020-08-11
    相关资源
    最近更新 更多