flutter 项目升级到最新的名为 Ladybug 的 android studio IDE 后无法运行。我在使用 Pusher 客户端包时遇到错误

问题描述 投票:0回答:1

该错误仅发生在 Pusher 包中。我已经尝试了几个推送程序包,但它们在我的项目中似乎都有这个常见错误。

下面是我的 app/build.gradle 文件。

plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

android {
    namespace = "com.cartrackernigeria.ctntelematics"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.cartrackernigeria.ctntelematics"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = 21//flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    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
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

flutter {
    source = "../.."
}

下面是setting.gradle文件

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.3.2" apply false
//    id "com.android.application" version "8.1.0" apply false
    id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

include ":app"

下面是我的 android/build.gradle

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = "../build"
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

每次尝试运行 flutter 项目时都会出现以下错误。 我已尽我所能,但我不明白,而推送者则抱怨命名空间。我尝试过几个推送包版本,例如

  • pusher_client
  • pusher_client_fixed
  • pusher_client_x

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':pusher_client_x'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
   > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

     If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

* 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
Error: Gradle task assembleDebug failed with exit code 1
Error executing devicectl: ProcessException: Process exited abnormally with exit code 3:

User cancelled

ERROR: Error writing JSON results: The file “core_device_list.json” doesn’t exist. (NSCocoaErrorDomain error 4.)
         NSFilePath = /var/folders/9p/qyg46tks79g_66b7y5bk3f800000gn/T/flutter_tools.Hff1N6/core_devices.dnTZUa/core_device_list.json
       ----------------------------------------
       The operation couldn’t be completed. No such file or directory (NSPOSIXErrorDomain error 2.)
  Command: xcrun devicectl list devices --timeout 5 --json-output /var/folders/9p/qyg46tks79g_66b7y5bk3f800000gn/T/flutter_tools.Hff1N6/core_devices.dnTZUa/core_device_list.json
android flutter dart
1个回答
0
投票

如果您使用 Android Studio Ladybug,则至少需要 AGP 版本 8.7

要使用此版本,您必须在项目中至少进行两项更改。

更新setting.gradle文件以将com.android.application插件设置为

id "com.android.application" version "8.7.0" apply false

并检查您的 gradle-wrapper.properties 文件。在这里,您必须将 distributionUrl 设置为所需的最低 Gradle 版本。对于 AGP 版本 8.7,这至少是 Gradle 8.10

更新后的 distributionUrl 的示例可以是:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip

总而言之,以后遇到类似问题只需查看 Android Gradle 插件发行说明

© www.soinside.com 2019 - 2024. All rights reserved.