【问题标题】:Couldn't sync after adding depenency to gradle in VScode在 VScode 中将依赖项添加到 gradle 后无法同步
【发布时间】:2020-08-22 08:49:46
【问题描述】:

我尝试配置我的颤振项目以使用 firebase。在将firebase中提到的行添加到Gradle构建后,我添加了所有依赖项并且无法同步。 如何在 vscode 中同步。

增加了对 firebase 的依赖:

在项目中 -> android -> 应用程序 -> build.gradle :

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

在项目中 -> gradle -> build.gradle:

 dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        **classpath 'com.google.gms:google-services:4.3.3'**
    }

IN 项目 -> pubspec.yaml

firebase_auth: ^0.14.0+5

还跑了flutter pub get

错误日志:

* Error running Gradle:
ProcessException: Process "C:\Users\LENOVO\Documents\flutter_apps\time_tracker_flutter_course\android\gradlew.bat" exited abnormally:
Starting a Gradle Daemon (subsequent builds will be faster)


FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\LENOVO\Documents\flutter_apps\time_tracker_flutter_course\android\app\build.gradle' line: 24

* What went wrong:
A problem occurred evaluating project ':app'.
> ASCII

* 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 2m 23s
  Command: C:\Users\LENOVO\Documents\flutter_apps\time_tracker_flutter_course\android\gradlew.bat app:properties

Please review your Gradle project setup in the android/ folder.
Exited (sigterm)

【问题讨论】:

  • 添加你的 build.gradle 和 pubspec.yaml
  • 我已经按照 firebase 文档中的说明添加了它们。如何同步它们?
  • 我的意思是将它们添加到问题中以查看问题所在
  • Done 添加了它们...!!!在android studio中,右上角会弹出在android studio中打开android模块并同步文件。但是我该如何在 VScode 中做到这一点??

标签: firebase flutter dart


【解决方案1】:

使用 Firebase 时,您需要下载 google-services.json 文件并将其添加到您的项目中:

Where do I place Googleservices.json in Flutter app in order to solve 'google-services.json is missing'

然后在android/build.gradle,需要添加google() maven仓库:

buildscript {
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
  }
  dependencies {
    ...
    // Add this line
    classpath 'com.google.gms:google-services:4.3.3'
  }
}

allprojects {
  ...
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
    ...
  }
}

android\app\build.gradle里面,你需要添加google-service插件:

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

检查一下:

https://firebase.google.com/docs/flutter/setup?platform=android

【讨论】:

  • 是的,既然你使用的是flutter,那么pubspec.yaml就相当于原生android开发中的build.gradle,当你在pubspec.yaml中添加一个依赖并保存时,它会自动得到那个依赖,但再次按照步骤添加 firebase 以确保一切正确,并且不要忘记使用 minSdkVersion 21 而不是 minSdkVersion 16
  • 错误日志是我得到的完整错误,并在问题中提到
  • 现在工作 :) 我搞砸了 firebase 和 google 服务版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-10
  • 2018-11-22
  • 2019-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多