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

  • Home
  • SEARCH
  • 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 6039947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:26:38+00:00 2026-05-23T06:26:38+00:00

Morning! I’ve created a small NDK project which allows dynamic serialisation of objects between

  • 0

Morning!

I’ve created a small NDK project which allows dynamic serialisation of objects between Java and C++ through JNI. The logic works like this:

Bean -> JavaCInterface.Java -> JavaCInterface.cpp -> JavaCInterface.java -> Bean

The problem is I want to use this functionality in other projects. I separated out the test code from the project and created a “Tester” project. The tester project sends a Java object through to C++ which then echo’s it back to the Java layer.

I thought linking would be pretty simple – (“Simple” in terms of NDK/JNI is usually a day of frustration) I added the JNIBridge project as a source project and including the following lines to Android.mk:

NDK_MODULE_PATH=.../JNIBridge/jni/"

JNIBridge/jni/JavaCInterface/Android.mk:

...
include $(BUILD_STATIC_LIBRARY)

JNITester/jni/Android.mk:

...
include $(BUILD_SHARED_LIBRARY)
$(call import-module, JavaCInterface)

This all works fine. The C++ files which rely on headers from JavaCInterface module work fine. Also the Java classes can happily use interfaces from JNIBridge project. All the linking is happy.

Unfortunately JavaCInterface.java which contains the native method calls cannot see the JNI method located in the static library. (Logically they are in the same project but both are imported into the project where you wish to use them through the above mechanism).

My current solutions are are follows. I’m hoping someone can suggest something that will preserve the modular nature of what I’m trying to achieve:


My current solution would be to include the JavaCInterface cpp files in the calling project like so:

LOCAL_SRC_FILES := FunctionTable.cpp $(PATH_TO_SHARED_PROJECT)/JavaCInterface.cpp

But I’d rather not do this as it would lead to me needing to update each depending project if I changed the JavaCInterface architecture.


I could create a new set of JNI method signatures in each local project which then link to the imported modules. Again, this binds the implementations too tightly.

  • 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-05-23T06:26:38+00:00Added an answer on May 23, 2026 at 6:26 am

    After much blood sweat and tears I’ve figured this out.

    • Android JNI loads its binary from a SHARED_LIBRARY only.
    • JNI will try and link native calls to the appropriate method signatures/stubs from the loaded Shared Library (it will not look inside linked shared libraries).
    • You can create a Static Library with these methods and build it into the Shared Library used by your application.

    You can build your static library in your original project using the following code in your Andriod.xml:

    include $(CLEAR_VARS)
    LOCAL_CFLAGS    := -O0
    LOCAL_MODULE    := LibraryToBeUsedInsideSharedLib
    LOCAL_SRC_FILES := ...
    include $(BUILD_STATIC_LIBRARY) // This builds a "Static Object" here:
                                    // /Project/obj/local/armeabi/libLibraryToBeUsedInsideSharedLib.a
    
    include $(CLEAR_VARS)
    LOCAL_MODULE       := LibraryCalledFromJava
    LOCAL_SRC_FILES    := ...
    LOCAL_STATIC_LIBRARIES := LibraryToBeUsedInsideSharedLib
    include $(BUILD_SHARED_LIBRARY)
    

    LOCAL_STATIC_LIBRARIES includes the Static Library in your Shared Library. In your Java code you can now call this:

    System.loadLibrary("LibraryCalledFromJava");
    

    You should be able to call any native methods located inside the LibraryToBeUsedInsideSharedLib library from any point in your java code.

    You can export the libLibraryToBeUsedInsideSharedLib.a file and use it in other projects by adding this to the external project’s Android.xml:

    include $(CLEAR_VARS)
    LOCAL_MODULE            := LibraryToBeUsedInsideSharedLib
    LOCAL_LDLIBS            := -llog/
    LOCAL_SRC_FILES         := $(MY_PREBUILT_LIB_DIR)/libLibraryToBeUsedInsideSharedLib.a
    include $(PREBUILT_STATIC_LIBRARY)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Morning all, I've created a custom control with an image property. That image property
Good morning. I have an XML file which contains lists of warning and errors
Good morning, I work in a small shop (only two of us) and we
Morning. Issue: I have a class called Reports. Two constructors. One allows no parameters,
Morning all! My MySQL query returns a PHP variable name which I'd like to
Good morning, I've got an ASP.NET MVC VB2008 .NET 3.5 project I'm upgrading to
This morning, I was reading Steve Yegge's: When Polymorphism Fails , when I came
Good morning, I am about to start writing an Excel add-in for Excel 2002.
Every morning, after logging into your machine, you do a variety of routine stuffs.
This morning I ran into an issue with returning back a text string as

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.