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 8365607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:41:59+00:00 2026-06-09T12:41:59+00:00

I have a native shared library compiled using android-ndk one of the C API

  • 0

I have a native shared library compiled using android-ndk

one of the C API functions is:

int load_config(const char *fn, Config *cfg)

I have wrapped the function with JNI and successfuly called it from Java, e.g.

Config cfg = new Config();
my_shared_lib.load_config("test.gcf", cfg);
System.out.println("cfg.rx_id = " + cfg.getRx_id());

This prints the expected value from the Config data structure

But now that I have ported it on to an Android emulator I am confused as how to handle the string representing the filename of the configuration data

I have tried adding test.gcf to the $(PROJECT)/assets dir then:

Config cfg = new Config();
my_shared_lib.load_config("assets/test.gcf", cfg);
outputText.append("cfg.rx_id = " + cfg.getRx_id());

but this doesn’t work, i.e. the expected value from the Config data structure isn’t ouput (I just get a blank)

In other words, what do you do when your native library function expects a filename as a parameter?

  • 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-09T12:42:00+00:00Added an answer on June 9, 2026 at 12:42 pm

    Assets are not stored as files, neither on the device nor on the emulator. They’re stored in the APK, which is a ZIP archive; using C/C++ file access functions won’t ever work on them. For access to assets from JNI code, use AAssetManager.

    Now, the config file probably does not belong to the assets. Assets are by definition read-only; you want your config to be changeable, right? The writeable data folder on Android is retrieved on the Java side via the Context.getDir() function; you derive your filename from that, and pass it to the C side. Something like this:

    File Path = Ctxt.getDir("MyData", 0);
    File FileName = new File(Path, "test.gcf");
    my_shared_lib.load_config(FileName.toString(), cfg); 
    

    The said folder would map to the following path in the Android filesystem:
    /data/data/com.mypackagename/app_MyData . Different if moving the app to an SD card is enabled.

    If you want to ship a default config file in assets but keep it as writeable in the data folder as the app runs, you just have to copy it from assets to the data folder on the first run. Example here.

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

Sidebar

Related Questions

I have an Android app that includes a C library using NDK to execute
I'm using a Java wrapper for a native shared library on Unix ( JRI
i'm wrapping a native API to Android by NDK. But when building it don't
I have created a jar file to load a native library ( using System.loadlibrary()
I'm trying to debug some native code I built using the android ndk-build script
I am to create a shared library for Android OS. Although I have done
I have some codeigniter driven sub-domains and using native codeigniter session library. There is
Considering libevent vs. libev . Does the libev library have native support of IOCP
This is probably a multi-part question. Background: we have a native (c++) library that
I am developing a library for Android applications which does not use native code

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.