gpt4 book ai didi

android - 更新到 'com.android.tools.build:gradle:4.1.0' 后缺少 BuildConfig.VERSION_CODE

转载 作者:行者123 更新时间:2023-12-03 02:38:49 27 4
gpt4 key购买 nike

我有一个多模块应用程序,由于某种原因,VERSION_CODE 生成的字段已从除根模块之外的所有模块中消失,我已经在另一个项目上对其进行了测试,并且它的行为相同。现在我只是降级到 4.0.1,但这只是一种解决方法。
我需要使用 gradle tools 4.1.0 在所有模块中恢复 BuildConfig.VERSION_CODE
将不胜感激任何帮助。
默认配置示例:

buildFeatures {
buildConfig = true
}

defaultConfig {
minSdkVersion global["androidMinSdkVersion"]
targetSdkVersion global["androidTargetSdkVersion"]

versionCode global["versionString"]

javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
这是 4.0.1 上的 BuildConfig 代码
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "app";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "flavour";
public static final int VERSION_CODE = 107;
public static final String VERSION_NAME = "6.0.0";
// Field from build type: debug
public static final String AMQP_URL = "url";
// Field from build type: debug
public static final String API_VERSION_SUFFIX = "V_04_04_09";
// Field from build type: debug
public static final String BASE_URL = "url";
// Field from product flavor: flavour
public static final String BUILD_FLAVOR = "flavour";
// Field from build type: debug
public static final int DB_VERSION = 53;
}
这里是 4.1.0
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "app";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "flavour";
public static final String VERSION_NAME = "6.0.0";
// Field from build type: debug
public static final String AMQP_URL = "url";
// Field from build type: debug
public static final String API_VERSION_SUFFIX = "V_04_04_09";
// Field from build type: debug
public static final String BASE_URL = "url";
// Field from product flavor: flavour
public static final String BUILD_FLAVOR = "flavour";
// Field from build type: debug
public static final int DB_VERSION = 53;
}

最佳答案

添加 buildConfigFieldbuildTypes在模块 build.gradle 文件中

buildConfigField("long", "VERSION_CODE", "${defaultConfig.versionCode}")        
buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"")
例子,
buildTypes {
debug{
buildConfigField("long", "VERSION_CODE", "${defaultConfig.versionCode}")
buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"")

//..
}
release {
buildConfigField("long", "VERSION_CODE", "${defaultConfig.versionCode}")
buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"")

//...
}
}
defaultConfig.versionCodedefaultConfig.versionName值为
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"

//..
}
在你的模块 build.gradle
您可以在 BuildConfig 中创建字段通过写 buildConfigField模块 build.gradle 中的方法。该方法第一个参数是创建字段类型,第二个是字段名,第三个是值。
安卓工作室 4.1

关于android - 更新到 'com.android.tools.build:gradle:4.1.0' 后缺少 BuildConfig.VERSION_CODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64333763/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com