I\'ve an app that needs to be build multiple times with different resources for different customers (branding, configuration, and pre-loaded data change between customers).<
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:
e. Open command prompt and check gradle is set. May use gradle -version to check.
Install Gradle eclipse PlugIn: a. Launch Eclipse b. Help > Eclipse Market Place c. Search “gradle” d. In that choose “Nodeeclipse/enide” e. Select all listed, accept & install. f. Restart eclipse once installed.
Set Gradle & Java Homes : a. Launch eclipse. b. Window > Preferences > Gradle EnIDE c. Set these if not set : i. Gradle home to use is set ( Ex: D:\Graddle\gradle-2.1) ii. Alternate JAVA_HOME to use is set ( Ex : C:\Program Files (x86)\Java\jdk1.7.0_60) iii. JVM options for GRADLE_OPTS is set to “-XX:MaxPermSize=512m”
Build the Project: a. Expand APK in eclipse Java explorer. b. Right click on build.gradle c. Run As > Gradle GUI d. Comand Line : gradle clean build e. Wait for build to complete : First time build will take several minutes. f. If Build dex error or Java heap space error : i. Open build.gradle in editor. ii. For multi dex builds- Set appropriate javaMaxHeapSize based on your java (javaMaxHeapSize=1024M for 32bit Java,2048M for 64bit Java) iii. May comment signing (//apply from: "$rootProject.projectDir/jenkins_config/gradle/signing.gradle";) to avoid signing for debug build. iv. Build again after these fixes.
Install Build On device: a. Connect the device to m/c. b. Right click on build.gradle c. Run As > gradle installDebug Gradle Android start d. Wait for install to complete
Debug Build: a. Launch the app b. Attach the debugger (DDMS>Devices > App). c. We able to debug on few devices checked.