Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Android Library on a Regular Java Project

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

like image 514
Dan Rivers Avatar asked Apr 09 '12 03:04

Dan Rivers


People also ask

Can you use any Java library on Android?

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.

What is the difference between AAR and jar?

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.

Does Android library have application class?

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.

How do I obfuscate an Android library project?

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.


1 Answers

  • 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.

like image 138
Tourki Avatar answered Sep 21 '22 21:09

Tourki