Gradle 更新应用程序版本时未找到 DSL 方法

Gradle DSL method not found when updating application version

我想在 google play store 更新我的应用程序,它不能接受相同版本的更新文件。

我是否更改了 build.gradle 文件的版本:

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "net.koorasudan.app"
    minSdkVersion 14
    targetSdkVersion 21
    versionCode 5.1
    versionName "5.1"
}
buildTypes {
    release {
           minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

但是当我同步 gradle 时它显示了这个错误:

Error:(23, 0) Gradle DSL method not found: 'versionCode()' Possible causes:

  • The project 'SmartView 3' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • 如何解决这个问题?

    您是否在 gradle 文件之上添加了 android 插件?

    apply plugin: 'android'
    

    顺便说一下,版本号需要是一个整数!从 5.1 切换到 5 就可以了!

    versionCode是一个整数。

    您不能在 build.gradle

    中使用 versionCode 5.1

    此外,您还必须在脚本的开头添加这一行。

    apply plugin: 'com.android.application'
    

    您应该将您的版本代码设置为整数。在您的应用程序发布后,您必须增加版本代码,以便 android OS 发现此版本是更新的版本。

    但在版本名称中,您可以将任何您想要的字符串格式放入。

    希望有用

    FWIW:我在测试大版本代码(>= 10 位)时遇到过这个问题。 Gradle 错误?

    只使用版本代码 2,不要使用版本代码 2.0 或任何浮点值

    版本代码 2

        versionName "2.0"
    

    像这样重新构建应用程序,它会解决你的问题

    版本代码应为整数格式。

    请使用以下代码:

    <i>
    android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "net.koorasudan.app"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 5
        versionName "5.1"
    }
    buildTypes {
        release {
               minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        }
    }
    </i>