Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Android library package including external (Native or Java) package

I have developed an application for computer vision algorithms that uses Native C++ library like OpenCV to capture camera frame and do image processing. My whole implementation resides in a native function which is called through an activity.

Let's say:

public native int MYMETHOD(int width, int height,int[] rgba);

I also load my library like this:

static {
    System.loadLibrary("MYNativeLIB");
}

Now my question is how can I deploy my application as a library package. Something deliverable that I can share it and the clients can import it to their project without installing any other libraries like OpenCV. Do I need to build a .so package? I have read this article. But I do not know how can I link against OpenCV library as well. Thanks for your help in advance.

like image 252
Hamid Bazargani Avatar asked Mar 20 '14 18:03

Hamid Bazargani


People also ask

Can I use Android library in Java?

An Android library module can contain Java classes, Android components and resources. Only assets are not supported. The code and resources of the library project are compiled and packaged together with the application.

What is the difference between AAR and JAR?

The main difference is aar is splitted inside android to jar. If your app will be used only in user app only in android studio then aar is preferred. If you are planning for app to communicate with c/c++ compiled lib.so file jar is preferred.

What is external libraries in Android Studio?

You are developing an Android app on Android Studio, sometimes you want to use an external library for your project, such as a jar file. Common langs is an java library with open source code which is provided by the Apache, it has utility methods for working with String, numbers, concurrency ...

How do I create a Java library in Android Studio?

Click File > New > New Module. In the Create New Module window that appears, click Android Library, then click Next . There's also an option to create a Java Library, which builds a traditional JAR file.

How do I use an Android library in another project?

To use your new Android library's code in another app or library module within the same project, add a project-level dependency: Navigate to File > Project Structure > Dependencies. Select the Module in which you’ll use the library. In the Declared Dependencies tab, click and select Module Dependency in the dropdown.

How to create a library module for Android?

Create a library module. 1 Click File > New > New Module. 2 In the Create New Module window that appears, click Android Library, then click Next . 3 Give your library a name and select a minimum SDK version for the code in the library, then click Finish.

How to create a JAR file project in Android?

Let us have an external library that we want to use in our project i.e a jar file. Create a new project named GFGAddLib. Now, our project has been created. Now click on the Android drop-down and change to Project files. Click on Project files.


1 Answers

You should have a look at the static initialization for OpenCV4andorid. You then can add the Open CV lib into your /libs directory of your Library project without the need to install any third party app when using it.

like image 51
Khaled Zarrad Avatar answered Sep 21 '22 03:09

Khaled Zarrad