11

The gradle java plugin has a FileCollection property which contains the runtime classes - sourcesets.main.runtimeClasspath.

Is there an equivalent within the com.android.application plugin?

Tez
  • 743
  • 6
  • 18

1 Answers1

2

What I've found is that the destinationDir property of applicationVariants can be appended to the javaCompile.classpath property, which will result in a FileCollection which contains the dependency classpaths and the compiled classes.

My use case is trying to run a java executable post-compile:

afterEvaluate {
    android.applicationVariants.each { variant ->
        variant.javaCompile.doLast {
            javaexec {
                classpath += variant.javaCompile.classpath
                classpath += files(variant.javaCompile.destinationDir)
                main = 'com.mydomain.Main'
            }
        }
    }
}

Tested on Android Studio 2.1.1 running 'com.android.tools.build:gradle:2.1.0' and gradle 2.10.

Reference: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Shrinking-Resources

Tez
  • 743
  • 6
  • 18
  • since `javaCompile` is now deprected, you can use `variant.javaCompileProvider.get().classpath` (kotlin syntax, might be slightly different in groovy). Also note though that this will cause a task dependency on compiling the sourcecode, which is sometimes problematic for code generation. In that case you can add a `doFirst {}` block around setting the classpath. – Leon S. Aug 04 '22 at 08:25