gradle无法在Android Studio中使用抖动 [英] gradle fails on using flutter in Android Studio

查看:67
本文介绍了gradle无法在Android Studio中使用抖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android Studio和Flutter的新手.我最近想尝试Flutter,因此在Android Studio中安装了该插件.我的Flutter代码没有错误,但是gradle失败了.

I'm a newbie to both Android Studio and Flutter. I recently wanted to try Flutter and hence installed the plugin in Android Studio. My Flutter code has no bugs, but the gradle fails.

应用程序级别构建gradle:

app level build gradle:

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'

模块级构建gradle

module level build gradle

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

我尝试包括一些依赖项,例如播放服务版本和Firebase分析版本,但此错误不会消失,并且Properties和GradleException仍会以红色突出显示为错误.这个问题.

I've tried including some dependencies such as the play-service version and the firebase analytics versions, but this error doesn't perish and the Properties and GradleException remain highlighted in red as errors.I don't understand how to solve this problem.

pubspec.yaml

pubspec.yaml

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

当我打开应用程序级别构建gradle时 图像抖动(表示无法解析Properties()和FileNotFoundException())

When I open app level build gradle image flutter (It says it cannot resolve Properties() and FileNotFoundException() )

但是,当我单击在Android Studio中打开以进行编辑"时,同一组错误得以解决并且gradle同步成功.图片androidStudio

But, the same set of errors are resolved and gradle sync is successful when I click the "Open for editing in Android Studio" image androidStudio

但是,在Android Studio案例中的成功并没有反映在Flutter案例中.它仍然有那些错误.

But,this success in Android Studio case, doesn't reflect in the Flutter one. It still has those errors.

推荐答案

您是否尝试过将google maven存储库添加到项目级别的build.gradle文件?

Have you tried adding the google maven repository to your project level build.gradle file?

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

buildscript部分或allprojects部分.

这篇关于gradle无法在Android Studio中使用抖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆