使用firebase消息包运行flutter项目时出错

时间:2018-05-22 13:04:14

标签: flutter

尝试在Android Studio中运行我的Flutter项目时,使用flutter包进行firebase云消息传递时出现以下错误:

  

在调试模式下在ZUK Z2132上启动lib \ main.dart ...       初始化gradle ...       解决依赖关系......       *运行Gradle时出错:       退出代码1来自:C:\ Users \ Ada3 \ AndroidStudioProjects \ fast_pos_tester \ android \ gradlew.bat   应用:特性:       配置'编译'在项目':app'已弃用。使用'实施'代替。

FAILURE: Build failed with an exception.

* Where:
Finished with error: Please review your Gradle project setup in the android/ folder.
Build file 'C:\Users\Ada3\AndroidStudioProjects\fast_pos_tester\android\build.gradle'
     

行:25

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > Could not resolve all dependencies for configuration ':app:debugCompileClasspath'.
      > More than one variant of project :firebase_messaging matches the consumer attributes:
          - Configuration ':firebase_messaging:debugApiElements' variant android-aidl:
              - Found artifactType 'android-aidl' but wasn't required.

这里是gradle代码(在app文件夹中)

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.")
}

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.witbybit.fastpostester"
        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 {
    implementation 'com.google.firebase:firebase-core:15.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'

这是pubspec.yaml

name: fast_pos_tester
description: A new Flutter application.

dependencies:
  flutter:
    sdk: flutter
  firebase_messaging: "^1.0.0"



  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.0

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

我无法弄清楚发生了什么。

2 个答案:

答案 0 :(得分:0)

请检查您是否编写了库依赖项/ api密钥正确

你需要发布你的flutter pubspec.yaml和gradle代码,这样我们才能告诉你那里有什么错误:))

答案 1 :(得分:0)

尝试干净地运行颤振,然后运行颤振。如果未运行,则应尝试在android / build gradle中添加以下代码:(必须将子项目放在文件的最后)

...

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

...

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if(details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex')) {
                details.useVersion "26.1.0"
            }
        }
    }
}

在android / app / build.gradle中,您应该需要这个

dependencies {
    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'
}