java在实现Firebase(flatter)通知时,我遇到了一个错误
首先,我为自己不是以英语为母语的人而道歉
但我遇到的问题如下
1)我正在按照教程(Youtube/文档)在颤振中实现通知
2)根据文件指示,我进行了所有建议设置。详情如下:
生成谷歌服务。控制台颤振中的json文件
添加应用插件:“com。谷歌。gms。谷歌服务公司将建立。应用程序中的渐变文件夹
添加classpath'com。谷歌。gms:googleservices:4.2.0'内置。渐变到安卓文件夹的根目录
向AndroidManifest添加意图过滤器(颤振通知点击)。xml文件
这就是构建。安卓文件夹的渐变
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.安卓.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.2.0'
}
}
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
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.安卓.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.1.0"
}
}
}
}
这就是构建。应用程序文件夹的渐变
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.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.安卓.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
安卓 {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.安卓.com/studio/build/application-id.html).
applicationId "com.example.tccversao2"
minSdkVersion 16
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "安卓.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
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 {
testImplementation 'junit:junit:4.12'
安卓TestImplementation 'com.安卓.support.test:runner:1.0.2'
安卓TestImplementation 'com.安卓.support.test.espresso:espresso-core:3.0.2'
}
安卓 {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
apply plugin: 'com.google.gms.google-services'
这是我的密码
@immutable
class Message {
final String title;
final String body;
const Message({
@required this.title,
@required this.body,
});
}
class MessagingWidget extends StatefulWidget {
@override
_MessagingWidgetState createState() => _MessagingWidgetState();
}
class _MessagingWidgetState extends State<MessagingWidget> {
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
final List<Message> messages = [];
@override
void initState() {
super.initState();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
final notification = message['notification'];
setState(() {
messages.add(Message(
title: notification['title'], body: notification['body']));
});
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
final notification = message['data'];
setState(() {
messages.add(Message(
title: '${notification['title']}',
body: '${notification['body']}',
));
});
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
}
@override
Widget build(BuildContext context) => ListView(
children: messages.map(buildMessage).toList(),
);
Widget buildMessage(Message message) => ListTile(
title: Text(message.title),
subtitle: Text(message.body),
);
}
我在用图书馆 firebase_消息:^4.0.0+1 firebase_核心:^0.3.0
我收到以下错误消息:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'com.安卓.support:support-fragment' has different version for the compile (26.1.0) and runtime (27.1.1) classpath. You should manually set the same version via DependencyResolution
* 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 6s
Gradle task assembleDebug failed with exit code 1
我已经尝试在我的构建中使用。gradle(在安卓文件夹中)类路径的com。谷歌。gms:google services:4.3.0',但在本例中,我得到另一个错误,即:
* Error running Gradle:
ProcessException: Process "E:\Flutter\projetos\tcc_versao2\tcc_versao2\安卓\gradlew.bat" exited abnormally:
FAILURE: Build failed with an exception.
* Where:
Build file 'E:\Flutter\projetos\tcc_versao2\tcc_versao2\安卓\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> ASCII
* 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 3s
Command: E:\Flutter\projetos\tcc_versao2\tcc_versao2\安卓\gradlew.bat app:properties
Please review your Gradle project setup in the 安卓/ folder.
*也许有一点很重要:我正在调试我的手机(小米Note 3 pro)
我完全被这个错误迷住了,如果有人能帮助我,我将非常高兴
# 1 楼答案
你应该看看你正在使用的库
错误表示它找到了
com.android.support:support-fragment
的两个不同版本。打开你的android/build。gradle并检查这里是否存在这种依赖关系,并将其更新到27.1.1版如果你没有在你的应用程序中直接找到依赖项,那么它可能来自另一个过时的依赖项或flatter插件。在pubspec上验证所有插件依赖项的更新。亚马尔也是