Skip to content

Commit 3cdbabe

Browse files
author
Paul Verest
committed
Update README.md
1 parent 72ebdfc commit 3cdbabe

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

org.nodeclipse.enide.editors.gradle/README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,104 @@ and [src/org/nodeclipse/enide/editors/gradle/highlight/Words.java](src/org/nodec
1010

1111
Read first at <http://www.nodeclipse.org/projects/gradle>
1212

13+
### AAR
14+
15+
Taken from <http://stackoverflow.com/questions/16709305/add-dependencies-via-gradle-to-eclipse-in-android-project?rq=1>
16+
17+
My solution is based off Rafael's above in that it copies dependencies to the libs directory which is only used by Android. However I go further to completely explode the referenced AAR's for use in Eclipse.
18+
19+
#Gradle Build File
20+
21+
Add the following to the end of your Android projects build.gradle :
22+
23+
task copyJarDependencies(type: Copy) {
24+
description = 'Used for Eclipse. Copies all dependencies to the libs directory. If there are any AAR files it will extract the classes.jar and rename it the same as the AAR file but with a .jar on the end.'
25+
libDir = new File(project.projectDir, '/libs')
26+
println libDir
27+
println 'Adding dependencies from compile configuration'
28+
configurations.compile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
29+
println 'Adding dependencies from releaseCompile configuration'
30+
configurations.releaseCompile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
31+
println 'Adding dependencies from debugCompile configuration'
32+
configurations.debugCompile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
33+
println 'Adding dependencies from instrumentTestCompile configuration'
34+
configurations.instrumentTestCompile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
35+
println 'Extracting dependencies from compile configuration'
36+
configurations.compile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }
37+
println 'Extracting dependencies from releaseCompile configuration'
38+
configurations.releaseCompile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }
39+
println 'Extracting dependencies from debugCompile configuration'
40+
configurations.debugCompile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }
41+
println 'Extracting AAR dependencies from instrumentTestCompile configuration'
42+
configurations.instrumentTestCompile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }
43+
}
44+
45+
void moveJarIntoLibs(File file){
46+
println 'Added jar ' + file
47+
copy{
48+
from file
49+
into 'libs'
50+
}
51+
}
52+
53+
void moveAndRenameAar(File file){
54+
println 'Added aar ' + file
55+
def baseFilename = file.name.lastIndexOf('.').with {it != -1 ? file.name[0..<it] : file.name}
56+
57+
// directory excluding the classes.jar
58+
copy{
59+
from zipTree(file)
60+
exclude 'classes.jar'
61+
into 'libs/'+baseFilename
62+
}
63+
64+
// Copies the classes.jar into the libs directory of the expoded AAR.
65+
// In Eclipse you can then import this exploded ar as an Android project
66+
// and then reference not only the classes but also the android resources :D
67+
copy{
68+
from zipTree(file)
69+
include 'classes.jar'
70+
into 'libs/' + baseFilename +'/libs'
71+
rename { String fileName ->
72+
fileName.replace('classes.jar', baseFilename + '.jar')
73+
}
74+
}
75+
}
76+
77+
#Building with Gradle
78+
79+
Run :
80+
81+
`"gradle clean build"`
82+
83+
You should find all dependencies and exploded AARs in your libs directory. This is all Eclipse should need.
84+
85+
# Importing in Eclipse #
86+
Now this is where the real benefit begins. After you've generated the libs directory from the gradle step above you'll notice there are folders in there too. Those new folders are the exploded AAR dependencies from your build.gradle file.
87+
88+
Now the cool part is that when you import your existing Android project into Eclipse it will also detect the exploded AAR folders as projects it can import too!
89+
90+
**1.** Import those folders under your project's **libs** directory, *don't import any 'build' folders, they're generated by Gradle*
91+
92+
**2.** Ensure you perform a ***Project -> Clean*** on all AAR projects you've added. In your workspace check that each AAR exploded project has the following in the project.properties :
93+
94+
target=android-<YOUR INSTALLED SKD VERSION GOES HERE>
95+
android.library=true
96+
97+
**3.** Now in your main Android project you can just add the library references with either ADT or you can just edit the project.properties file and add
98+
99+
`android.libraries.reference.1=libs/someExplodedAAR/`
100+
101+
**4.** Now you can right-click on your main Android project and **Run as -> Android Application**.
102+
103+
104+
#But what does this even mean?
105+
1. Well it means you don't need the source code for any of your Android AAR Gradle dependencies in order to reference both it's classes and resources in Eclipse.
106+
107+
2. The gradle build script above takes the AAR file and prepares it for use in Eclipse. Once you add it to your workspace you're ready to just focus on your actual main Android project.
108+
109+
3. You can now debug and develop using Eclipse and deploy using ADT with AAR dependencies being properly bundled in the APK. When you need to make some specific builds then you can use gradle.
110+
13111
## To Develop
14112

15113
- Import `org.nodeclipse.enide.editors.gradle` as existing Eclipse project in Eclipse with PDE (e.g. Eclipse Standard or Enide Studio)

0 commit comments

Comments
 (0)