First Here\'s my Java Build Path in Eclipse:
These four jars \'common.jar,core
Following script works for me:
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs.add('-Xbootclasspath/p:/mylib.jar')
}
}
}
I use the following scenario, the perfect solution!
XXX.jar
to LibraryFind this in your project .gradle
:
allprojects {
repositories {
jcenter()
}
}
Change it to:
allprojects {
repositories {
jcenter()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs.add('-Xbootclasspath/p:app\\libs\\XXX.jar')
}
}
}
In YourApplicationName.iml
file, adjust the XXX.jar
to top, like this
so, it's ok!
You can't do what you want in Gradle(*), at least for the foreseeable future at the time this is written. A few problems are getting in your way:
android.jar
. Gradle has the philosophy that you should be explicit about dependencies in your build so what's going on is understandable and repeatable; systems that rely on classpath ordering tend to be subtle and fragile. So what you would need to do is to tell Gradle that your project depends on your custom classes and not android.jar
, but the plugin's DSL doesn't give you the means to do that. There's some discussion at http://forums.gradle.org/gradle/topics/classpath_ordering_again and http://www.gradle.org/docs/current/userguide/dependency_management.htmlandroid.jar
is hardcoded into the Android Gradle plugin, so you can't get at that dependency and replace it with something else.(*) Having said all that, nothing is impossible -- you could make it work, but you're going to have to hack something together, so it's going to be more trouble-prone than the Eclipse approach, and tougher to maintain in the face of SDK and tooling updates. And when something goes wrong you'll be on your own.
android.jar
. I hesitate to offer much more insight into either of those approaches, partly because I don't know a lot about it and could pretty easily give you bad advice, and partly because I don't want inexperienced developers seeing this to think it's an awesome thing to do. But if you figure it out, it would be very much worthy of writing up, because I've seen this sort of question before, so you're not the only one.