Gradle for Eclipse - Android
Back to Android page
Make Android Eclipse project ready for Android Studio, yet keeping it accessible for Eclipse use too
In short: use src/main/java
.
Welcome to raise issue on GitHub.
- Create project in Eclipse
- In
.classpath
changesrc
value intosrc/main/java
, that is
<classpathentry kind="src" path="src/main/java"/>
( Your project has red ! by now) - Create folder
main/java
undersrc
-
Move source under
src/main/java
, e.g. movecom
fromsrc
intosrc/main/java
Now project compiles well.
-
Way 1: add
build.gradle
, e.g. with such minimal content:buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.1.+' } } apply plugin: 'com.android.application' dependencies { compile fileTree(dir: 'libs', include: '*.jar', exclude: 'android-support-*.jar') } android { compileSdkVersion 22 buildToolsVersion "22" sourceSets { main { manifest.srcFile 'AndroidManifest.xml' res.srcDirs = ['res'] assets.srcDirs = ['assets'] } androidTest.setRoot('tests') } }
Note that with gradle you are to specify
buildToolsVersion
. If you want to specify for Eclipse ADT (e.g. to make them similar) inproject.properties
add line likesdk.buildtools=19.1.0
. ref -
Way 2: Right-click on the project Export… -> Android / Generate Gradle build files.
In wizard select only project (and its dependencies except for Android support libraries)
This will add
build.gradle
build file and wrapper files:gradlew
,gradlew.bat
andgradle/wrapper
folder.Check/correct that your
sourceSets
section is like below:sourceSets { main { manifest.srcFile 'AndroidManifest.xml' res.srcDirs = ['res'] assets.srcDirs = ['assets'] } }
Hint 1: when you Gradle build file becomes long, define some modules and put them into
gradle
folder, then insidebuild.gradle
use
apply from: 'gradle/feature-module.gradle'
Hint 2: For Eclipse project with dependencies
build.gradle
will be added in every of them, and main project will getsettings.gradle
. Instead of Android support library addcompile 'com.android.support:appcompat-v7:19.0.+'
-
(optional) If you are using git, add
.gitignore
with content:/gen/ /bin/ /.gradle/ /build/ /gradle-app.setting .*.md.html .DS_Store .idea/workspace.xml /local.properties
-
In Android Studio File -> Import Project… and select locate
build.gradle
from the project.
Now you can apply power of Gradle in Eclipse with ADT and/or Android Studio