首页 > 解决方案 > Flutter build appbundle 错误找不到参数的方法 androidExtensions()

问题描述

我正在尝试使用 Flutter 为 Andriod 应用程序构建发布 appbundle,

当我运行时:

flutter build appbundle

我得到:

* What went wrong:
A problem occurred evaluating project ':app'.
> No signature of method: build_9z8dp8vvjumdxnixrakr4imyg.android() is applicable for argument 
types: (build_9z8dp8vvjumdxnixrakr4imyg$_run_closure3) values: [buil
d_9z8dp8vvjumdxnixrakr4imyg$_run_closure3@775a0064]

我试图清理+修复缓存,但它仍然无法正常工作。颤振医生工作正常。

app\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'
}


def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

apply plugin: 'org.jetbrains.kotlin.android.extensions'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"


androidExtensions {
    experimental = true
}

android {

    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "com.example.Application"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName

    }
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile']
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release

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

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    // Import the Firebase BoM
    implementation platform('com.google.firebase:firebase-bom:27.1.0')

    // Add the dependency for the Firebase SDK for Google Analytics
    // When using the BoM, don't specify versions in Firebase dependencies
    implementation 'com.google.firebase:firebase-analytics'

    // Declare the dependency for the Firebase Authentication library
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-auth'

    // Add the dependencies for any other desired Firebase products
    // https://firebase.google.com/docs/android/setup#available-libraries

    implementation 'com.facebook.android:facebook-login:[8.1)'
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'

    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.fragment:fragment:1.0.0'

}

apply plugin: 'com.google.gms.google-services'

android\build.gradle 文件:

buildscript {
    ext.kotlin_version = '1.3.50'

    repositories {
        google()
        jcenter()
        mavenCentral()
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.3.5'
        classpath 'com.android.tools.build:gradle:4.2.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()  // Google's Maven repository
        jcenter()
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

android\key.properties 文件:

storePassword=123456789
keyPassword=123456789
keyAlias=upload
storeFile=C:\\Users\\User\\Documents\\Application\\upload-keystore.jks

完整输出:

C:\Users\User\Documents\Application>flutter build appbundle
The plugin `flutter_open_whatsapp` uses a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since
a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Kotlin plugin should be enabled before 'kotlin-android-extensions'

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\User\Documents\Application\android\app\build.gradle' line: 41

* What went wrong:
A problem occurred evaluating project ':app'.
> No signature of method: build_9z8dp8vvjumdxnixrakr4imyg.android() is applicable for argument types: (build_9z8dp8vvjumdxnixrakr4imyg$_run_closure3) values: [buil
d_9z8dp8vvjumdxnixrakr4imyg$_run_closure3@27144de8]

* 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 2s
Running Gradle task 'bundleRelease'...                           2,990ms
Gradle task bundleRelease failed with exit code 1

标签: androidflutterbuildbuild.gradleandroid-app-bundle

解决方案


尝试在 android studio 中将 /android 目录作为项目打开,并在不使用 Flutter 的情况下构建版本。

甚至尝试在项目中使用 Java,看看它是否有效?

如果它有效,那么您的 Kotlin 版本可能存在一些问题。


推荐阅读