I am adding few properties in BuildConfig through 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 build from gradle, it works fine but when I compile project in eclipse I get errors because this variable is NOT present in gen BuildConfig.
My question is
I didn't find a simple way to make Eclipse generate the BuildConfig class.
I develop mainly with Eclipse ADT and then release different flavors with Gradle so I came up with the following solution:
Create my own CustomBuildConfig
class, add it to Eclipse build path and use Gradle sourceSets
to select different version of this class.
In Project/build.gradle
, define an additional source folder, specific to a flavor:
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";
}
The development env 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 add only the Project/flavors/dev/src/
to the build path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With