简体   繁体   中英

Gradle: How can I make one set of Java files target either Android and Oracle JVM?

I have a chunk of Java code that is cross platform in the sense that it works on both the Oracle JVM and Android. I prefer to develop and run my unit tests on the Oracle JVM but need to test and run on Android as well. Thoughts or suggestions?

Put the Java code that runs on JVM and Android into its own project - Java library. Then you can build its JAR and run unit tests against it. Add it as a dependency to your Android project. There are a few samples that will guide you in the gradle-samples-*.zip at the bottom of http://tools.android.com/tech-docs/new-build-system page.

There are other way where you can use one of existing libraries that enable unit testing of Android code but their set up is usually non-trivial so I would recommend you to start with the approach outlined above.

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