简体   繁体   中英

Gradle Android jar task not compiling .java files to .class files when creating the jar

I'm migrating a legacy perl build script for an android app over to Gradle. The build script takes a couple of .java files and turns them into a .jar.

However when I use a gradle task to make the .jar, if I examine the contents of it then it just contains the .java files, whereas the .jar built by the legacy perl script has compiled the .java files into .class files before placing them inside the .jar, additionally it has placed a classes.dex file in there also.

This is my current jar task:

task buildJar(type: Jar) {
    archiveName = "com.company.platform.jar"
    from sourceSets.platformJarSourceLocation.java
    destinationDir = file(platformGeneratedFilesDirectory)
}

How can I get the .jar to contain .class rather than .java and to include the classes.dex?

The jar task just creates a jar with everything you give to it. It doesn't compile at all. If you want to create a jar with class files, run compileDebug before, and then use the ouptput to create a jar. Same for classes.dex , the generating task is packageDebug .

You can ensure that a task is run before yours with dependsOn .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM