Flutter 升级后 Android gradle 构建失败

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

升级到Flutter 3.24.3后 我被要求迁移到 Gradle 的声明性插件 {} 块。

按照 gradle 模块的迁移过程进行操作后: https://docs.flutter.dev/release/writing-changes/flutter-gradle-plugin-apply

我开始出现以下错误:

Gradle build error: Cannot find module entity for 'Module: 'android.audioplayers_android.unitTest''

build.gradle(应用程序级别):

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
    id "com.google.firebase.crashlytics"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = "31"

def flutterVersionName = "3.1.1"


android {
    compileSdk 34
    namespace 'com.claivoyance.claivoyance'

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.clairvoyance.clairvoyance"
        minSdkVersion 22
        targetSdkVersion 34
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.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
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}

设置.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 "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.7.10" apply false
    id "com.google.gms.google-services" version "4.3.14" apply false
    id "com.google.firebase.crashlytics" version "2.8.1" apply false
}

include ":app"

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
}
android flutter dart gradle build
1个回答
0
投票

我通过将

apply false
添加到 settings.gradle 插件加载器解决了这个问题: 这是相应的行:

    id "dev.flutter.flutter-plugin-loader" version "1.0.0" apply false
© www.soinside.com 2019 - 2024. All rights reserved.