In android, how to access file in assets or raw in c++ via url?

257 Views Asked by At
  • I want to use the url of the files in assets or raw in C++ (JNI).
  • However, I don't know how to obtain the url of these files, since I cann't use getAssets().open() in C++ code.
1

There are 1 best solutions below

0
Mobin jafari On

it is possible to load a C++ file from a URL and load it in android

but it's illegal and google play doesn't let apps load codes dynamically in the google play store

  1. first you should create a new android-ndk project with the same package name

  2. then run

    ./ndk build
    
  3. in the intermediate folder you will get .so files which are compiled files from c++

  4. put files for x86, x64 , arm64, x86_64, or other ABIs files in your main project or serve it in the cloud server

  5. you can download it in phone storage

  6. add "lib" before SO file name and add the .so extension

    EXAMPLE -> libexample. so
    
  7. simply call

    static {
        System.load("PATH_TO_THE_FILE/libfile.so");
    }
    

or call loading from ndk with

dlopen("PATH_TO_THE_FILE/libfile.so")