【问题标题】:How to solve Flutter error: Could not find method versionName()如何解决 Flutter 错误:找不到方法 versionName()
【发布时间】:2021-03-09 13:13:36
【问题描述】:

实际上,当我尝试为 Android 运行 Flutter 构建时,我遇到了一个非常奇怪的错误。 首先,我想向您展示错误。之后,我将向您展示我的项目的 Flutter doctor 结果和特定代码部分。

使用flutter run运行android项目后出错

  • 出了什么问题:评估项目 ':app' 时出现问题。

在 DefaultConfig_Decorated{name=main, dimension=null, 上找不到参数 [1.0.0, null] 的方法 versionName() minSdkVersion=DefaultApiVersion{mApiLevel=18, mCodename='null'}, targetSdkVersion=DefaultApiVersion{mApiLevel=28, mCodename='null'}, renderscriptTargetApi=null,renderscriptSupportModeEnabled=null, renderscriptSupportModeBlasEnabled=null, renderscriptNdkModeEnabled=null,versionCode=8,versionName=null, applicationId=de.danielederosa.virtualguestbook, testApplicationId=null,testInstrumentationRunner=null, testInstrumentationRunnerArguments={},testHandleProfiling=null, testFunctionalTest=null,signingConfig=null,resConfig=null, mBuildConfigFields={},mResValues={},mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}, mWearAppUnbundled=null} 类型 com.android.build.gradle.internal.dsl.DefaultConfig.

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 通过https://help.gradle.org获得更多帮助

在 6 秒内构建失败异常:Gradle 任务 assembleDebug 失败 退出代码 1 退出 (sigterm)

build.gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

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

gradle.wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

pubspec.yaml

version: 1.0.0+8

有趣的是它显示versionName=null,如果我这样覆盖变量:

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "de.danielederosa.virtualguestbook"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName '1.0.0',
        multiDexEnabled true
    }

您知道可能是什么问题吗?也许与 gradle 版本有些不兼容?

【问题讨论】:

    标签: android flutter gradle


    【解决方案1】:

    将其设置为默认设置,看看它是否有效:

    这是我默认的flutter build.gradle (app)

    def flutterVersionName = localProperties.getProperty('flutter.versionName')
    if (flutterVersionName == null) {
        flutterVersionName = '1.0'
    }
    

    和

    defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.teddichiiwa.example"
            minSdkVersion 16
            targetSdkVersion 28
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
        }
    

    【讨论】:

      【解决方案2】:

      我认为您在“versionName '1.0.0'”这一行上犯了一个错误,” 有一个不应该存在的逗号。 换行为versionName '1.0.0' 我希望我对您有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-19
        • 2021-04-07
        • 2021-08-31
        • 2014-09-24
        • 2012-03-02
        • 2020-07-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多