Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BuildConfig.VERSION_CODE is missing after update to 'com.android.tools.build:gradle:4.1.0'

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.

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

Would appreciate any help.

defaultConfig example:

buildFeatures {     buildConfig = true }  defaultConfig {     minSdkVersion global["androidMinSdkVersion"]     targetSdkVersion global["androidTargetSdkVersion"]      versionCode global["versionString"]      javaCompileOptions {         annotationProcessorOptions {             includeCompileClasspath true         }     } } 

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

And here is 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; } 
like image 870
Void Avatar asked Oct 13 '20 10:10

Void


People also ask

How do I find my Gradle version?

In Android Studio, go to File > Project Structure. Then select the "project" tab on the left. Your Gradle version will be displayed here.

What is Android Gradle plugin?

The Android Gradle plugin (AGP) is the official build system for Android applications. It includes support for compiling many different types of sources and linking them together into an application that you can run on a physical Android device or an emulator.

What is Gradle Android?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.


1 Answers

add buildConfigField to buildTypes in module build.gradle file

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

example,

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}\"")          //...     } } 

the defaultConfig.versionCode and defaultConfig.versionName value is

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

in your module build.gradle

you can create field in BuildConfig by writing buildConfigField method in module build.gradle. The method first parameter is create field type, second is field name, third is value.

Android Studio 4.1

like image 158
leeJB Avatar answered Sep 19 '22 11:09

leeJB