// generate eclipse classpath for android projects - version for android plugin 3 and gradle 3 // currently we explode the aars with eclipseAar but throw away the class path entries from it apply plugin: 'eclipse' apply plugin: 'ch.poole.misc.eclipse.aar' // this needs classpath 'ch.poole.misc:gradle-eclipse-aar-plugin:0.1.0' in the main build file task setResoveable { // this is awlful but works ...... // both gradles and googles documentation of the changes wrt gradle 3.0 seems to not only be vague but outright wrong configurations.implementation.setCanBeResolved(true) configurations.testImplementation.setCanBeResolved(true) configurations.androidTestImplementation.setCanBeResolved(true) } // Configure eclipse-aar plugin eclipseAar { // See "Configurations" for details androidTarget = 'android-25' aarDependenciesDir = 'build/aarDependencies' // Set to true if you use Andmore. Default is false andmore = true targetConfigurations =['implementation', 'testImplementation', 'androidTestImplementation'] cleanLibsDirectoryEnabled=true; } eclipse { jdt { sourceCompatibility = 1.8 targetCompatibility = 1.8 } classpath { plusConfigurations += [ configurations.implementation, configurations.testImplementation, configurations.androidTestImplementation ] file { beforeMerged { classpath -> // classpath.entries.removeAll { it.kind.equals("src") } // throw everything added previously away // classpath.entries.add(new org.gradle.plugins.ide.eclipse.model.SourceFolder("src/main/java", "bin")) classpath.entries.add(new org.gradle.plugins.ide.eclipse.model.SourceFolder("src/test/java", "bin")) classpath.entries.add(new org.gradle.plugins.ide.eclipse.model.SourceFolder("src/androidTest/java", "bin")) // Hardcoded to use debug configuration classpath.entries.add(new org.gradle.plugins.ide.eclipse.model.SourceFolder("build/generated/source/r/debug", "bin")) classpath.entries.add(new org.gradle.plugins.ide.eclipse.model.SourceFolder("build/generated/source/buildConfig/debug", "bin")) } whenMerged { classpath -> def aars = [] classpath.entries.each { dep -> def pathString = dep.path.toString(); println "processing " + pathString if (pathString.endsWith(".aar")) { def explodedDir = new File(projectDir, "build/aarDependencies/" + dep.moduleVersion.group + "-" + dep.moduleVersion.name + "-" + dep.moduleVersion.version + "/libs/") if (explodedDir.exists()) { explodedDir.eachFileRecurse(groovy.io.FileType.FILES) { if (it.getName().endsWith("jar")) { def aarJar = new org.gradle.plugins.ide.eclipse.model.Library(fileReferenceFactory.fromFile(it)) aarJar.sourcePath = dep.sourcePath aars.add(aarJar) } } } else { println "Warning: Missing " + explodedDir } } else if (pathString.endsWith(".jar")) { def jarFile = fileReferenceFactory.fromFile(new File(dep.path)) def aJar = new org.gradle.plugins.ide.eclipse.model.Library(jarFile) aJar.sourcePath = jarFile aars.add(aJar) } } classpath.entries.removeAll { it.path.endsWith(".aar") } classpath.entries.removeAll { it.path.endsWith(".jar") } classpath.entries.addAll(aars) classpath.entries.add(new org.gradle.plugins.ide.eclipse.model.Library(fileReferenceFactory.fromFile(new File(projectDir, "build/intermediates/compile_r_class_jar/debug/R.jar")))) def androidJar = new org.gradle.plugins.ide.eclipse.model.Library( fileReferenceFactory.fromPath("${android.sdkDirectory}/platforms/" + android.compileSdkVersion + "/android.jar")) androidJar.sourcePath = fileReferenceFactory.fromPath("${android.sdkDirectory}/sources/" + android.compileSdkVersion) classpath.entries.add(androidJar) // this is a fudge, the eclipse plugin uses the project names for paths of subprojects, // which naturally breaks the real classpath if different from the actual directory names if (project != rootProject) { classpath.entries.each { sub -> def fudge = rootProject.name + '-' if (sub.kind == 'src' && sub.path.toString().startsWith('/' + fudge)) { def p = sub.path.toString().replace(fudge, ''); sub.path = new File(p) } } } } } } } generateEclipseDependencies.dependsOn "setResoveable" eclipseClasspath.dependsOn "generateEclipseDependencies" eclipseClasspath.dependsOn "generateDebugSources" // this assumes emulator is on your path // it would be nice if this could be generated dynamicalls [ "8.0" ].each { avd -> def name="avd${avd}" task (name,type: Exec) { if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) { commandLine 'cmd', '/c', 'start', '/b', 'emulator', '-avd', avd, '-ports', '5554,5555' } else { // untested assumes bash commandLine 'coproc', 'emulator', '-avd', avd, '-ports', '5554,5555' } group = 'emulators' } }