Android BuildConfig Problems Adding Properties Through Gradle

I am adding several properties to BuildConfig via build.gradle as below

release_prod{ buildConfig "public static final String ENVIRONMENT = \"prod\";" } release_dev{ buildConfig "public static final String ENVIRONMENT = \"dev\";" } 

The problem is when I create from gradle it works fine, but when I compile the project in eclipse I get errors because this variable is NOT present in the BuildConfig gene.

My question

  • Is there a way to add multiple variables to BuildConfig so that it is generated from eclipse during build
  • If not, I can still generate properties from gradle in a separate file other than BuildConfig.
+6
source share
1 answer
  • I have not found an easy way to get Eclipse to generate the BuildConfig class.

  • I mainly develop with Eclipse ADT and then release various options with Gradle, so I came up with the following solution:

    Create your own CustomBuildConfig class, add it to the Eclipse build path, and use Gradle sourceSets to select a different version of this class.


In Project/build.gradle define an additional flavor-specific source folder:

 android { sourceSets { release_prod { java.srcDirs = ['src', 'flavors/prod/src' ] } release_dev { java.srcDirs = ['src', 'flavors/dev/src' ] } } 

The production env is defined in Project/flavors/prod/src/CustomBuildConfig.java:

 package com.example.project; public class CustomBuildConfig { public static final String ENVIRONMENT = "prod"; } 

Env development is defined in Project/flavors/dev/src/CustomBuildConfig.java:

 package com.example.project; public class CustomBuildConfig { public static final String ENVIRONMENT = "dev"; } 

And finally, in Eclipse, I only add the Project/flavors/dev/src/ path to the build path.

+1
source

Source: https://habr.com/ru/post/954120/


All Articles