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

StackOverflow https://stackoverflow.com/questions/23417821

  •  13-07-2023
  •  | 
  •  

Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top