在使用 Firebase 消息传递包时运行颤振项目时出错



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

调试模式下在 ZUK Z2132 上启动 lib\main.dart... 正在初始化分级... 正在解析依赖项... * 运行 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:UsersAda3AndroidStudioProjectsfast_pos_testerandroidbuild.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 代码(在应用程序文件夹中(

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

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

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

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

尝试运行颤振干净,然后颤振运行。如果它没有运行,你应该尝试在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'
}

最新更新