I am looking to use an android class on a regular non-android java project. Specifically I want to use FaceDetector from android.media I know that there are OpenCV and other libraries I can use to detect a face in an image but I am looking to use androids library. Is there a way to link androids library to a java project? Thanks
Android library projects and Java librariesIf you want to use libraries, these must only use API available in Android. For example, the java. awt and javax. swing packages are not available on Android.
Unlike JAR files, AAR files offer the following functionality for Android applications: AAR files can contain Android resources and a manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to Java classes and methods.
The Application class in Android is the base class within an Android app that contains all other components such as activities and services. The Application class, or any subclass of the Application class, is instantiated before any other class when the process for your application/package is created.
In order to obfuscate your library what you need to do is: Make sure gradle settings for lib module state minifyEnabled true . run ./gradlew assemble{flavor}Release.
Go to build path of your java project
Add a new external jar
Browse to the location of your android platform installation (usually C:\Program Files (x86)\Android)
Under android-sdk\platforms\android-x (where x is the version of android you have) select the android.jar file to add to the project.
Now you have the android library under the referenced libraries, and you can use whatever android classes you want in your java project.
Another way of doing that is to use the android source, get only the java files you need from the android library and put them into your java project. The good thing when you do it this way is that you can modify the code and make it more compatible with your java work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With