I am using the Android Developer Tools 22, Eclipse Indigo and the current Gradle Plugin for Eclipse.
Now I would like to use different Flavors by defining in the build.gradle file:
productFlavors{
A {
packageName "com.test.A"
buildConfig "public final static String FLAVOR = \"A\";"
}
B {
packageName "com.test.B"
buildConfig "public final static String FLAVOR = \"B\";"
}
}
As far as I know i can access to this variables using BuildConfig.FLAVOR, but the definition of FLAVOR is missing in the generated BuildConfig.java in gen folder.
If I assemble my Project via Gradle the correct and complete BuildConfig.java is generated in the folder build/source/buildConfig/[A|B]/[debug|release]/com/test/.
It works if I build the project over gradle, but I can't work with Eclipse, because it expects that the variables are defined in the BuildConfig.java in gen folder
Can I force gradle or the adt to generate the correct BuildConfig.java in the gen folder?
Android Studio is bleeding edge (not yet beta).
As answered in Issue 57668 by Android team (raised by @arcone)
Project Member #2 [email protected]
The eclipse plugin is not compatible with the android plugin.
You will not be able to import an Android gradle project into Eclipse using the default Gradle support in Eclipse.
To make it work in Eclipse we will have to change the Gradle plugin for Eclipse, the same way we are modifying the Gradle support in IntelliJ
That is Android team is working on gradle plugin for IntelliJ and gradle plugin for Eclipse needs to be updated too.
You can develop in Eclipse with ADT and run Gradle build using Nodeclipse/Enide Gradle for Eclipse (marketplace)
Some screenshots for Gradle for Eclipse:
There are some plans for Android with Gradle Development in Eclipse
Using Eclipse with the new Gradle plugin isn't supported, you should use Android Studio instead.
Also, since you have asked this, the plugin has had this functionality added to it. From the release notes for version 0.7.0 of the Android Gradle plugin:
Build Config now automatically contain more constants for PACKAGE_NAME, VERSION_CODE, VERSION_NAME, BUILD_TYPE, FLAVOR as well as FLAVOR_ if there are several flavor dimensions.
Can I force gradle or the adt to generate the correct BuildConfig.java in the gen folder?
Yes, with a hack: once :generateDebugBuildConfig
(replace Debug
with the variant you need) has run in gradle, you'll have the BuildConfig.java
what you need.
I made this on Windows, but should be the same for Unix with your favorite shell and cp
C:\Windows\System32\cmd.exe
${workspace_loc:/YourProject}
/c "xcopy build\generated\source\buildConfig\debug gen /S /I /Y"
gen
folderAndroid Pre Compiler
and Java Builder
Note: this is really working against ADT and probably there'll be other missing pieces you may find hard to handle (applicationIdSuffix
, resValue
, variant source folders, just to name a few). It may be easier giving up on Eclipse ADT and transitioning to Android Studio, Google seems to want this anyway without publicly admitting it. There has been no real progress on ADT since they said they'll maintain it at I/O 2013.
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