First Here\'s my Java Build Path in Eclipse:

These four jars \'common.jar,core
A updated and somewhat more future-proof answer (since bootclasspath compilerargs have been changing in more recent JDKs):
dependencies {
compileOnly fileTree(dir: 'system_libs', include: ['*.jar'])
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.bootstrapClasspath = files(
new File("./system_libs/framework.jar").path,
new File("./system_libs/libcore.jar").path
)
}
}
Add a task to put referring to the Android API Platform in the last position in app.iml, this way gradle will take into account your system libs first and Android SDK last:
preBuild {
doLast {
def imlFile = file(project.name + ".iml")
println 'Change ' + project.name + '.iml order'
try {
def parsedXml = (new XmlParser()).parse(imlFile)
def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
parsedXml.component[1].remove(jdkNode)
def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform"
new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])
groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
} catch (FileNotFoundException e) {
// nop, iml not found
}
}
}
Based on @Bertrand's answer