简体   繁体   English

Build.gradle不接受版本代码作为字符串

[英]Build.gradle not accepting version code as string

Version code updates for 1 to 9 as string but, when update to 10 gives compile time error : 版本代码将1到9更新为字符串,但是当更新为10时会出现编译时错误:

Cannot cast object '10' with class 'java.lang.String' to class 'java.lang.Integer'

    versionCode = "10"

If i make version code as integer 10, i am able to generate signed apk but not able to upload in play store. 如果我将版本代码设置为整数10,则能够生成带符号的apk,但无法在Play商店中上传。

project was initially made in eclipse later migrated to android studio 该项目最初是在Eclipse中制作的,后来又迁移到了android studio

buildscript {
repositories {
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    classpath 'io.fabric.tools:gradle:1.+'
}
}

android { compileSdkVersion 23 buildToolsVersion '23.0.2' useLibrary 'org.apache.http.legacy' android {compileSdkVersion 23 buildToolsVersion '23 .0.2'useLibrary'org.apache.http.legacy'

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 23
    versionCode = 10
    versionName = "1.1.12"
    multiDexEnabled true
}

lintOptions {
    // set to true to turn off analysis progress reporting by lint
    quiet true
    // if true, stop the gradle build if errors are found
    abortOnError false
    // if true, only report errors
    ignoreWarnings true
}
buildTypes {
    release {
        minifyEnabled false
        zipAlignEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}




sourceSets.main {
    jniLibs.srcDir 'libs'
    jni.srcDirs = [] //disable automatic ndk-build call
}

} }

Cannot cast object '10' with class 'java.lang.String' to class 'java.lang.Integer'
  1. versionCode must be integer value . versionCode必须为整数值。

  2. remove = 删除=

android:versionCode 安卓的versionCode

An integer value that represents the version of the application code, relative to other versions. 一个整数值,表示相对于其他版本的应用程序代码的版本。 The value is an integer so that other applications can programmatically evaluate it, for example to check an upgrade or downgrade relationship. 该值是一个整数,以便其他应用程序可以以编程方式对其进行求值,例如检查升级或降级关系。 You can set the value to any integer you want, however you should make sure that each successive release of your application uses a greater value. 您可以将值设置为所需的任何整数,但是应确保应用程序的每个后续发行版均使用更大的值。 The system does not enforce this behavior, but increasing the value with successive releases is normative. 系统不强制执行此行为,但是在后续发行中增加价值是正常的。

  minSdkVersion 16
    targetSdkVersion 23
    versionCode  10
    versionName "1.1.12"
    multiDexEnabled true

Then Clean-Rebuild-Run . 然后执行Clean-Rebuild-Run

FYI FYI

 versionCode Integer.parseInt("10") // String to Integer convert

I got a hunch that Gradle interpreted it as a char, and just assigned the ASCII code of the character 9 to the versionCode (and that's why it doesn't work with multiple characters, because then it is assumed as a string). 我有一种预感,Gradle会将其解释为一个字符,并且只是将字符9的ASCII码分配给了versionCode (这就是为什么它不能与多个字符一起使用的原因,因为它被假定为字符串)。

Since the ASCII code of the character 9 is 57, you should try uploading it with the versionCode 58 or higher (because Google Play does not allow downgrades). 由于字符9的ASCII码为57,因此您应尝试使用versionCode 58或更高版本上传它(因为Google Play不允许降级)。

Change the for versionCode = "10" to this versionCode 10 将for versionCode = "10"更改为此versionCode 10

Thats the default format 那是默认格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM