Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:46:07+00:00 2026-06-12T13:46:07+00:00

Intro : I have a native library (C++) with Java (JNI) wrapper. The library

  • 0

Intro: I have a native library (C++) with Java (JNI) wrapper. The library engine is cpu intensive, we don’t want more than one app linking this lib to be running at the same time, and complex objects should be returned by the lib engine.

The question: What is the best way to engineer such an Android library?

So far, I could find just find 2 valuable examples: OpenCV manager and Connectbot ssh-agent.

I can think of a few solutions:

  • Solution 1: Make a (bound or AIDL) service that wraps the library functionality. (should the service run in its own space? or in the space of the application that links to it? how can the native lib be loaded if it’s in a different app space(System.load("/data/data/com.company.myLib/lib.so")). How to return complex objects in AIDL?). This should be the Connectbot way.

  • Solution 2: Divide the lib into 2 components:

    1. A standalone package which keeps the native libs + a manager service
    2. An android lib-project which only contains Java wrappers which users can use to build their apps.

    This should be the OpenCV manager way. I don’t know exactly the details, but this way one does not need a service to interface with and can just import com.company.myLib.LibWrapper. On the other side the LibWrapper class should perform System.load("/data/data/com.company.myLib/lib.so"). Correct?

I would personally go for solution 2. Unfortunately Android is a new land and there are not many models yet on how to develop a library. Is there any other/better solutions? Is there other considerations to make?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:46:08+00:00Added an answer on June 12, 2026 at 1:46 pm

    Consider the following scheme: you build an “empty” app that contains no activities, no settings – only the manifest, the icon for “manage apps” list and the native lib that is installed by the system in /data/data/package/lib directory.

    This native library may, but doesn’t have to expose JNI functions. In a typical situation, this lib will be a straightforward port of an opensource LGPL library – e.g. libdmtx.so.

    The “client” apps will call loadLibrary() for the “external” lib, and after that it will call the usual load() for its JNI wrapper. This lib has the only purpose to translate Java methods to the public C APIs of the external lib.

    The JNI wrapper and the corresponding Java class may be distributed as a .jar or as sources, they are not bound by LGPL license of the external lib.

    Such scheme is, IMHO, the only way to ensure LGPL compliance on Android: anybody can recompile the “external” lib from the open source, package it as an “empty” app and install it on their device.

    Regarding your concern about concurrent access to the lib, I actually doubt that it is so important: the high end devices have four cores more powerful each than one core on cheaper devices. OTOH, it’s easy to use Linux synchronisation methods, e.g. named pipes, to keep track of active instances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a managed wrapper over a native library, I have to accomplish certain operations
I have a slider with 3 slides - Intro, Question, Submit. Now I want
I have a native library for Android that has some files that include NEON
I have a native dynamic link library written in VC++6 and I do not
I have an native C++ library which makes use of a large static buffer
I have an native C++ dll, some header files and the import library. Is
I have a managed dll that calls into a native library. This native library
I have two applications and am turning one into a Library so I can
Intro I have an issue with the SqlClient in .Net 4.0.30319 SP1Rel, in which
Intro I work in a facility where we have microscopes. These guys can be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.