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
.classpathchangesrcvalue intosrc/main/java, that is
<classpathentry kind="src" path="src/main/java"/>
( Your project has red ! by now) - Create folder
main/javaundersrc -
Move source under
src/main/java, e.g. movecomfromsrcintosrc/main/javaNow 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.propertiesadd 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.gradlebuild file and wrapper files:gradlew,gradlew.batandgradle/wrapperfolder.Check/correct that your
sourceSetssection 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
gradlefolder, then insidebuild.gradleuse
apply from: 'gradle/feature-module.gradle'Hint 2: For Eclipse project with dependencies
build.gradlewill 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
.gitignorewith 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.gradlefrom the project.
Now you can apply power of Gradle in Eclipse with ADT and/or Android Studio
