運行代碼時出現錯誤。
錯誤:
Launching lib\main.dart on Android SDK built for x86 in debug mode...
C:\Users\emiry\Desktop\KelimeOgren\kelimeogrenmeuygulamasi\android\app\src\debug\AndroidManifest.xml Error:
uses-sdk:minSdkVersion 18 cannot be smaller than version 19 declared in library [com.google.firebase:firebase-messaging:23.0.0] C:\Users\emiry\.gradle\caches\transforms-2\files-2.1\04fa4caba5dd20f8583ef52f1aeef9ee\jetified-firebase-messaging-23.0.0\AndroidManifest.xml as the library might be using APIs not available in 18
Suggestion: use a compatible library with a minSdk of at most 18,
or increase this project's minSdk version to at least 19,
or use tools:overrideLibrary="com.google.firebase.messaging" to force usage (may lead to runtime failures)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 18 cannot be smaller than version 19 declared in library [com.google.firebase:firebase-messaging:23.0.0] C:\Users\emiry\.gradle\caches\transforms-2\files-2.1\04fa4caba5dd20f8583ef52f1aeef9ee\jetified-firebase-messaging-23.0.0\AndroidManifest.xml as the library might be using APIs not available in 18
Suggestion: use a compatible library with a minSdk of at most 18,
or increase this project's minSdk version to at least 19,
or use tools:overrideLibrary="com.google.firebase.messaging" to force usage (may lead to runtime failures)
* 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
BU?LD FAILED in 10s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
主要飛鏢:
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:kelimeogrenmeuygulamasi/arayuzEkrani.dart';
import 'package:onesignal_flutter/onesignal_flutter.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
Firebase.initializeApp();
OneSignal.shared.setAppId("APP-ID");
runApp(mainApp());
}
class mainApp extends StatelessWidget {
const mainApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: arayuz(),
);
}
}
提到的AndroidManifest.xml檔案:
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.firebase.messaging" >
<uses-sdk android:minSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Required by older versions of Google Play services to create IID tokens -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application>
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
<!--
FirebaseMessagingService performs security checks at runtime,
but set to not exported to explicitly avoid allowing another app to call it.
-->
<service
android:name="com.google.firebase.messaging.FirebaseMessagingService"
android:directBootAware="true"
android:exported="false" >
<intent-filter android:priority="-500" >
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.google.firebase.components.ComponentDiscoveryService"
android:exported="false" >
<meta-data
android:name="com.google.firebase.components:com.google.firebase.messaging.FirebaseMessagingRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
</application>
</manifest>
我的目的是使用 OneSignal 向手機發送通知。我已將錯誤和上述檔案的內容放在上面。
作為指南,我在這里使用它:https ://dev.to/lordlamee/implementing-push-notifications-with-flutter-and-onesignal-part-1-3690 。我在這里做了同樣的程式。
問題是什么?我該如何解決?
最后一個錯誤:
Launching lib\main.dart on Android SDK built for x86 in debug mode...
e: C:/Users/emiry/.gradle/caches/transforms-2/files-2.1/1e3435b9bf2a9d121ad7aaa0ead8e64e/work-runtime-2.7.1-api.jar!/META-INF/work-runtime_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
* 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
BU?LD FAILED in 27s
[!] Your project requires a newer version of the Kotlin Gradle plugin.
Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then update C:\Users\emiry\Desktop\KelimeOgren\kelimeogrenmeuygulamasi\android\build.gradle:
ext.kotlin_version = '<latest-version>'
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
我得到的第二個錯誤:
Launching lib\main.dart on Android SDK built for x86 in debug mode...
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\emiry\Desktop\KelimeOgren\kelimeogrenmeuygulamasi\android\app\build.gradle' line: 74
* What went wrong:
A problem occurred evaluating project ':app'.
> path may not be null or empty string. path='null'
* 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
BU?LD FAILED in 24s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
uj5u.com熱心網友回復:
轉到專案的根路徑/android/app/build.gradle,然后在android -> defaultConfig塊內設定minSdkVersion to 19/21如下代碼。
defaultConfig {
applicationId "com.*****.*****"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
重新運行專案。我認為這將解決您的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/441242.html
