我想在 Android 手机上运行我的 FLUTTER 应用程序,但每次我都会收到新的错误。它在网络浏览器上运行良好,但当我尝试在通过 USB 连接的手机或 Android 模拟器上运行它时,会出现错误。
这是错误:
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file 'C:\Users\CW\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_local_notifications-16.3.0\android\build.gradle' line: ??
* What went wrong:
A problem occurred evaluating project ':flutter_local_notifications'.
> Could not find method namespace() for arguments [com.dexterous.flutterlocalnotifications] on extension 'android' of type com.android.build.gradle.LibraryExtension.
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* Where:
Script 'C:\src\flutter\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy' line: ???
* What went wrong:
A problem occurred configuring project ':flutter_local_notifications'.
> Failed to notify project evaluation listener.
> Cannot invoke method substring() on null object
> compileSdkVersion is not specified. Please add it to build.gradle
* 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.
==============================================================================
这是“build.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.")
}
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.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 33
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.ecommerce01"
minSdkVersion flutter.minSdkVersion
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
请帮我解决它。
您似乎错过了 Android 上 flutter_local_notifications 所需的步骤。 更多信息这里