Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android gradle runtimeClasspath equivalent

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?

like image 781
Tez Avatar asked May 17 '16 02:05

Tez


People also ask

What is compileJava in Gradle?

compileJava — JavaCompile. Depends on: All tasks which contribute to the compilation classpath, including jar tasks from projects that are on the classpath via project dependencies. Compiles production Java source files using the JDK compiler. processResources — ProcessResources.

What is runtimeOnly in Gradle?

implementation configuration is used for compile and runtime classpath but it is only exposed to the consumers for their runtime classpath. runtimeOnly configuration is only used for the runtime classpath and it is also exposed to the consumers for their runtime classpath.

What is the difference between API and implementation scopes?

The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component.


1 Answers

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

like image 92
Tez Avatar answered Oct 10 '22 23:10

Tez