How to Use the Gradle Build System for Android with Eclipse

Is it possible to use the Gradle build system for Android with Eclipse?

It is possible to use 2 build systems (Eclipse + gradle based). Just make sure output folders are different (bin for ADT, build for gradle).
(Update for TL;DR : check Nodeclipse/Enide Gradle for Eclipse
(marketplace) )

File -> Export -> Generate Gradle build files will just add build.gradle with content below (but check versions). No existing files are changed.

com.android.tools.build:gradle version should be the latest.
For gradle type gradle build as said in http://tools.android.com/tech-docs/new-build-system/user-guide. Try gradle tasks for more. (On my slow Internet connection it took 1 hour! for gradle to download all needed dependencies)

Vogella tutorial http://www.vogella.com/articles/AndroidBuild/article.html is not yet ready. Other online tutorials are not really finished http://www.jayway.com/2013/02/26/using-gradle-for-building-android-applications/

Eclipse ADT is not yet using gradle, I think it will be polished within Android Studio first. It would be not so wise to start using evolving technology in both IDEs at the same time.

See build.gradle example below. If you already mastered gradle, then maybe Wizards is not needed at all.
For the latest build.gradle template for classic Android project check gh.c/N/n-1/b/m/o.n.e.e.g/docs/android/build.gradle.

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}

android {
compileSdkVersion 8
buildToolsVersion "19.0.0"

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}

// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')

// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}

ADT-Bundle does not come with Eclipse Marketplace, so update site could be used.

Update p2 repository for Gradle Integration for Eclipse is

http://dist.springsource.com/release/TOOLS/gradle

But as of version 3.4.0 it does not provide Editor for .gradle files.
So there is no sense of having it for Android development.

I would go with default ADT build, having gradle as secondary build for experimentations
and keeping an eye when flow of bugs on http://tools.android.com/tech-docs/new-build-system becomes rare. (That should be around formal 1.0 version)

UPDATE: 2014-04-15

Alex Ruiz's (from Android team) Blog about Android, Gradle & ADT

Android’s Gradle Model

Instead of creating IDE-specific Android/Gradle models, we decided to have an IDE-agnostic representation of a Gradle project. This way, we have a single source of information that is easier to maintain. IDE integration will be implemented as a plug-in for each supported IDE (in our case, Eclipse and IDEA.) The main benefit of this approach is that we can release the Gradle plug-in independently of the IDE integration plug-ins. For example, we can ship a new version of the Eclipse plug-in that has several bug fixes, without affecting the Gradle side of Android.

As of April 2014 eclipse-gradle plugin is not compatible with android-gradle plugin:

As answered in Issue 57668 by Android team (raised by @arcone)

Project Member #2 x...@android.com

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.

There is effort at Nodeclipse to smooth the transition times. And continue to develop in Eclipse while still experimenting or fully using gradle.

Nodeclipse/Enide Gradle for Eclipse
(marketplace)

Some screenshots for Gradle for Eclipse:

Sample Image

Sample Image

How to run the 'gradle init' task in Eclipse Buildship plugin?

In the "Gradle Tasks" panel, expand the node of your project. Then expand the "build setup" node. Right click on "init" and select "Run Gradle Tasks".

Then in the project explorer, right click on your project and select "Gradle", then select "Refresh Gradle Project". And voila! You must be able to see your build.gradle now.

Using gradle project in both Eclipse and IDEA

You'll have to maintain the build separately in both Gradle and Eclipse; Eclipse can't use the Android Gradle builder natively. It's on our list of things to implement but we don't have a roadmap for it yet.

Things will go easiest if you use an Eclipse-like directory structure and adapt the Gradle build file to work with it. See Maintaining directory structure during Android Studio import for advice.

How to import eclipse project into android studio?

close your project first File -> Close project. Then on Main screen you will see option Import project(Eclipse ADT,Gradel,etc ). Choose this option to import your eclipse project. And then follow instructions as directed.

Sample Image

Which build system did eclipse use to build android apk?

I used it,but ,I think it is not stable

You are welcome to your opinion. I have not run into problems with it to date, and many major organizations are using it for production apps. If you are running into specific problems, ask questions here or on various Android developer support sites.

I want to know which build system did eclipse use?

Eclipse uses Eclipse-ADT.

Is it Ant?

No. Ant is a separate build system, as is Maven.

I just want to use command line instead of visual interface;How can I do that?

Use Gradle (Google-supported) or Maven (community-supported). Ant support, by pretty much all parties, is fading away.



Related Topics



Leave a reply



Submit