Firebase gradle在Android Studio中使用颤振失败
我是Android Studio和Flatter的新手。我最近想试试颤振,因此在Android Studio中安装了这个插件。我的flatter代码没有bug,但是gradle失败了 应用程序级构建梯度:Firebase gradle在Android Studio中使用颤振失败,firebase,android-studio,dart,build.gradle,flutter,Firebase,Android Studio,Dart,Build.gradle,Flutter,我是Android Studio和Flatter的新手。我最近想试试颤振,因此在Android Studio中安装了这个插件。我的flatter代码没有bug,但是gradle失败了 应用程序级构建梯度: def localProperties = new Properties() //here, Properties gets highlighted as error def localPropertiesFile = rootProject.file('local.properties')
def localProperties = new Properties() //here, Properties gets highlighted as error
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.") //here,GradleException gets highlighted as error
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.mee.createevent"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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 {
compile 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.android.gms:play-services-analytics:16.0.1'
implementation 'com.google.firebase:firebase-analytics:16.0.1'
implementation 'com.google.firebase:firebase-firestore:17.0.2'
implementation 'com.google.firebase:firebase-functions:16.0.1'
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'
}
apply plugin: 'com.google.gms.google-services'
模块级构建梯度
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:4.0.1'
}
}
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
}
我的错误:
FAILURE: Build failed with an exception.
* What went wrong:
Failed to notify dependency resolution listener.
> The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[16.0.0,16.0.0]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
> The library com.google.firebase:firebase-analytics is being requested by various other libraries at [[16.0.1,16.0.1]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
* 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 20s
Finished with error: Gradle build failed: 1
我尝试过包含一些依赖项,如play service版本和firebase analytics版本,但此错误不会消失,属性和GradleException仍然以红色突出显示为错误。我不知道如何解决此问题
公开发行
name: create_event
description: A new Flutter application.
dependencies:
cloud_firestore:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages
当我打开应用程序级构建渐变时
(它表示无法解析Properties()和FileNotFoundException())
但是,当我单击“在Android Studio中打开以进行编辑”时,相同的一组错误被解决,gradle同步成功
但是,Android Studio案例中的这一成功并不反映在Flitter案例中。它仍然存在这些错误。您是否尝试将google maven存储库添加到您的项目级build.gradle文件中
buildscript {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
buildscript
部分或allprojects
部分。在android/build.gradle中仅使用此依赖项,并删除任何其他依赖项
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.1'
在pubspec.yaml中,仅使用以下版本以避免渐变错误:
cloud_firestore: 0.7.3
firebase_admob: 0.5.5
firebase_auth: 0.5.11
google_sign_in: 3.0.4
firebase_analytic: 1.0.1
firebase_core: 0.2.4
firebase_database: 1.0.1
firebase_dynamic_links: 0.02
firebase_messaging: 1.0.2
firebase_performance: 0.0.3
firebase_remote_config: 0.0.4
firebase_storage: 0.3.7
我创建了另一个应用程序,并替换了所有.dart文件和pubspec.yaml。这是我发现的最快的方法当我遇到同样的问题时,我能找到的唯一解决方法是更新gradle版本: 在android/gradle/wrapper/gradle wrapper.properties中 发送至
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
及
在android/build.gradle中
到依赖项{
classpath'com.android.tools.build:gradle:3.5.3'
classpath'com.google.gms:googleservices:4.3.2'
在android/build.gradle中
buildscript {
ext.kotlin_version = '1.3.61'
在公共规范yaml中
我希望它能帮助您。更改classpath'com.google.gms:googleservices:4.3.2'
到classpath'com.google.gms:google services:4.2.0'可以通过以下步骤删除此错误:
我希望您的问题现在得到解决。鉴于您粘贴的失败,我建议您阅读此链接。它也与Android项目相关。错误显示了依赖性问题,但其他内容,如Properties()和FileNotFoundException()在实际代码中被突出显示为错误(我刚刚将该图像附加到突出显示的位置)老实说,我对Flitter应用不太熟悉。属性是必需的吗?试着把它放在你的根build.gradle中。另外,不要把IDE高亮显示看得太重。重要的是当你尝试构建时会发生什么。我肯定会建议解决所有构建错误,看看你会得到什么。你是对的,那个高亮显示没有atter.Thx:)很高兴听到这个消息!在这种情况下,这只是工具(您的IDE)的一个限制。我的build.gradle中也有“红色”代码,但所有构建都很好,所以我有一条评论“不要删除此!!!!”:)你有没有试过降低依赖项的级别?在找出哪个版本会给你带来错误之前,也要做一些检查。ESS,这绝对有效,thxx:)使用统一版本(如15.0.2)导致不正确的同步。我按照另一位朋友的建议使用了“+”,最终解决了问题。我如何关闭这个问题?@Aivi这解释了这一点埃蒂·威尔:
firebase_core: ^0.4.2+1
cloud_firestore: ^0.12.11