更新至'com.android.tools.build:gradle:4.1.0'后缺少BuildConfig.VERSION_CODE [英] BuildConfig.VERSION_CODE is missing after update to 'com.android.tools.build:gradle:4.1.0'

查看:586
本文介绍了更新至'com.android.tools.build:gradle:4.1.0'后缺少BuildConfig.VERSION_CODE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多模块应用程序,由于某种原因,VERSION_CODE生成的字段已从除根目录之外的所有模块中消失,我已经在另一个项目上对其进行了测试,并且其行为相同.现在,我已经简单地降级到4.0.1,但这只是一个解决方法.

I have a multi modular app and for some reason VERSION_CODE generated field has disappeared from all modules except the root one, I have tested it on one more project and it behaves the same. Right now I have simply downgraded to 4.0.1, but thats just a workaround.

我需要使用gradle工具4.1.0恢复所有模块中的BuildConfig.VERSION_CODE

I need to restore BuildConfig.VERSION_CODE in all modules using gradle tools 4.1.0

非常感谢您的帮助.

defaultConfig示例:

defaultConfig example:

buildFeatures {
    buildConfig = true
}

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

    versionCode global["versionString"]

    javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }
}

这里是4.0.1上的BuildConfig代码

Here comes the BuildConfig code on 4.0.1

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;
}

推荐答案

我有一个多模块应用程序,由于某种原因,除了根目录之外,所有模块中都已消失了VERSION_CODE生成的字段

I have a multi modular app and for some reason VERSION_CODE generated field has disappeared from all modules except the root one

这似乎与此报告的问题有关.在这种情况下,库模块中缺少了VERSION_NAME.有关其依据,请参见此特定评论. 显然,他们修复了VERSION_NAME但没有修复VERSION_CODE.当我对此进行测试时,我没有得到VERSION_NAMEVERSION_CODE,所以我无法解释您的模块如何获得.

That appears to be related to this reported issue. In that case, it was VERSION_NAME that was missing from library modules. See this specific comment for their rationale. Apparently, they fixed VERSION_NAME but did not fix VERSION_CODE. When I test this, I do not get either VERSION_NAME or VERSION_CODE, so I cannot explain how your module gets VERSION_NAME.

您应该可以使用buildConfigField 切换到版本代码:

You should be able to switch to using buildConfigField to supply your version code:

 buildConfigField "long", "VERSION_CODE", global["versionString"]

这篇关于更新至'com.android.tools.build:gradle:4.1.0'后缺少BuildConfig.VERSION_CODE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆