Android studio 更新android studio后的渐变生成错误:versionCode的NumberFormatException
我犯了一个以前从未犯过的错误:Android studio 更新android studio后的渐变生成错误:versionCode的NumberFormatException,android-studio,gradle,Android Studio,Gradle,我犯了一个以前从未犯过的错误: Execution failed for task ':app:generateDebugBuildConfig'. > Failed to calculate the value of task ':app:generateDebugBuildConfig' property 'buildConfigPackageName'. > Failed to query the value of property 'packageName'.
Execution failed for task ':app:generateDebugBuildConfig'.
> Failed to calculate the value of task ':app:generateDebugBuildConfig' property 'buildConfigPackageName'.
> Failed to query the value of property 'packageName'.
> java.lang.NumberFormatException: For input string: "${versionCode}"
android studio版本为:
Android Studio 4.1.1
Build #AI-201.8743.12.41.6953283, built on November 5, 2020
Runtime version: 1.8.0_242-release-1644-b3-6222593 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
build.gradle(:app)文件包含以下内容:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' //< for image visualization with glide
//Serialization
apply plugin: 'kotlinx-serialization'
android {
signingConfigs {
release {
storeFile file('xxxx.jks')
storePassword 'xxxxxxx'
keyPassword 'xxxxxxxx'
keyAlias 'my-app'
}
}
compileSdkVersion propCompileSdkVersion
buildToolsVersion propBuildToolsVersion
defaultConfig {
applicationId "com.user.myapp"
minSdkVersion propMinSdkVersion
targetSdkVersion propTargetSdkVersion
versionCode 3
versionName "2.0-beta.26"
manifestPlaceholders = [versionCode:"3", versionName:"2.0-beta.26"]
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable true
resValue "string", "app_name", "myapp-dev"
}
optimizedDebug {
initWith debug
minifyEnabled false
applicationIdSuffix ".optimizedDebug"
debuggable false
resValue "string", "app_name", "myapp-optimized-dev"
}
debugProd {
initWith debug
minifyEnabled false
applicationIdSuffix ".debugProd"
debuggable true
resValue "string", "app_name", "myapp-logs-in-prod"
}
release {
minifyEnabled false
resValue "string", "app_name", "myapp"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
applicationVariants.all { variant ->
variant.resValue "string", 'images_file_path', "Android/data/\"${applicationId}\"/files/Pictures"
}
/* Necessary to have Parcelable / @Parcelize functionalities */
androidExtensions {
experimental = true
}
lintOptions {
checkReleaseBuilds false
abortOnError true
}
}
dependencies {
...
}
repositories {
mavenCentral()
}
apply插件:“com.android.application”
应用插件:“kotlin android”
应用插件:“kotlin android扩展”
应用插件:“kotlin kapt”/<进行glide图像可视化
//系列化
应用插件:“kotlinx序列化”
安卓{
签名配置{
释放{
storeFile文件('xxxx.jks')
存储密码“xxxxxxx”
密钥密码“xxxxxxxx”
keyAlias“我的应用程序”
}
}
CompileSDK版本PropCompileSDK版本
buildToolsVersion propBuildToolsVersion
默认配置{
applicationId“com.user.myapp”
明斯克版本
targetSdkVersion propTargetSdkVersion
版本代码3
版本名称“2.0-beta.26”
manifestPlaceholders=[versionCode:“3”,versionName:“2.0-beta.26”]
TestInstrumentRunner“androidx.test.runner.AndroidJUnitRunner”
}
建筑类型{
调试{
applicationIdSuffix“.debug”
可调试真
resValue“字符串”、“应用程序名称”、“myapp开发”
}
优化缺陷{
带调试的初始化
minifyEnabled false
applicationIdSuffix“.optimizedDebug”
可调试错误
resValue“字符串”、“应用程序名称”、“myapp优化开发”
}
调试产品{
带调试的初始化
minifyEnabled false
applicationIdSuffix“.debugProd”
可调试真
resValue“字符串”、“应用程序名称”、“myapp登录产品”
}
释放{
minifyEnabled false
resValue“字符串”、“应用程序名称”、“myapp”
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard rules.pro'
signingConfig signingConfigs.release
}
}
applicationVariants.all{variant->
variant.resValue“string”、“images\u file\u path”、“Android/data/\”${applicationId}\“/files/Pictures”
}
/*需要具备Parcelable/@Parcelize功能*/
androidExtensions{
实验=真实
}
林特选项{
checkReleaseBuilds为false
异常错误为真
}
}
依赖关系{
...
}
存储库{
mavenCentral()
}
我已经使缓存失效并重新启动了好几次,没有任何变化。
我想精确地指出到底发生了什么,至少能够理解是什么导致gradle感到困惑。
有人能告诉我gradle的一步一步运行来找出问题所在吗?我发现在清单中,android studio注释了以下错误:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.user.myapp"
android:versionCode={$versionCode}
android:versionName={$versionName}
>
...
</manifest>
在清单中,删除引用android:versionXXXX:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.user.myapp"
>
...
</manifest>
在那之后,它工作得很好。注意:它在android studio 4.1.0上工作得很好
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.user.myapp"
>
...
</manifest>
val versionCode = BuildConfig.MYAPP_VERSION_CODE.toString()
val versionName = BuildConfig.MYAPP_VERSION_NAME