Flutter - 构建失败,评估项目时出现问题

时间:2021-02-27 17:05:59

标签: flutter dart

当我运行这个应用程序时,它告诉我:- 评估项目“:app”时出现问题。 但我根据我正在关注的教程添加了所有插件。

这是代码:- (app\buil.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 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 = '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.example.earthquake_app"
        minSdkVersion 16
        targetSdkVersion 29
        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 {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    
}
apply plugin: 'com.google.gms.google-services'

显示我的 IDE 的问题:- enter image description here

1 个答案:

答案 0 :(得分:0)

我找到了我自己的问题答案......!!! 一开始,我确实把项目级的build.gradle(依赖顺序和google服务版本'4.3.5'改为'4.3.3'):-

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

然后对app级build.gradle(defaultConfig)做了第二次修改:-

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.earthquake_app"
    minSdkVersion 16
    targetSdkVersion 29
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    //This 2 line here...
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}

然后在 main.dart 上进行更改(如下所示):-

import 'package:flutter/material.dart';
import 'board_firestore/board_app.dart';
import 'package:firebase_core/firebase_core.dart';

void main() async {
  // these 2 lines
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  runApp(new MaterialApp(
    home: BoardApp(),
  ));
}

然后我更改应用程序主体(在 return Scaffold() 中):-

body: StreamBuilder(
    //future: FirebaseFirestore.initializeApp(),
    stream: firestoreDb,
    builder: (context, snapshot) {
      if (!snapshot.hasData) return CircularProgressIndicator();
      return ListView.builder(
        itemCount: snapshot.data.docs.length, //documents will be docs
        itemBuilder: (context, int index) {
          return Text(snapshot.data.docs[index]['title']);  //documents will be docs
        },
      );
    },
  ),

然后在终端 flutter cleanflutter run

我搜索了很多,找到了很多解决方案,但尽管每个人都有同样的问题,但他们中的许多人给出了许多不同的解决方案。