【问题标题】:Error in running flutter project on using firebase messaging package使用 firebase 消息包运行颤振项目时出错
【发布时间】:2018-11-01 06:26:40
【问题描述】:

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

在调试模式下在 ZUK Z2132 上启动 lib\main.dart... 正在初始化梯度... 解决依赖关系... * 运行 Gradle 时出错: 退出代码 1:C:\Users\Ada3\AndroidStudioProjects\fast_pos_tester\android\gradlew.bat 应用程序:属性: 项目 ':app' 中的配置 'compile' 已弃用。请改用“实施”。

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

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

【问题讨论】:

    标签: flutter


    【解决方案1】:

    尝试运行flutter clean,然后flutter run。如果它没有运行,你应该尝试在 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'
    }
    

    【讨论】:

      【解决方案2】:

      请检查您编写的库依赖项/api 键是否正确

      您需要发布您的颤振 pubspec.yaml 和 gradle 代码,以便我们告诉您那里出了什么问题 :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-13
        • 2021-03-18
        • 2020-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-14
        相关资源
        最近更新 更多