Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADT Eclipse + Gradle: incomplete BuildConfig.java

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?

like image 879
ElPatzo Avatar asked Jun 27 '13 10:06

ElPatzo


3 Answers

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

like image 75
Paul Verest Avatar answered Nov 20 '22 20:11

Paul Verest


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.

like image 26
ZoFreX Avatar answered Nov 20 '22 20:11

ZoFreX


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

  1. Open Project Properties and navigate to Builders
  2. Add a "Program" Builder
    • Location: C:\Windows\System32\cmd.exe
    • Working Directory: Browse Workspace... and select your project,
      the result will be something like: ${workspace_loc:/YourProject}
    • Arguments: /c "xcopy build\generated\source\buildConfig\debug gen /S /I /Y"
    • Set up when to run
      • Refresh tab: "Specific resources" select gen folder
      • Build Options tab: "After Clean", "Manual", "Auto" and "Specify Resources" to be your project's root folder
  3. Make sure this new builder is placed between Android 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.

like image 1
TWiStErRob Avatar answered Nov 20 '22 20:11

TWiStErRob