I’m trying to build a .aar library which contains native/C++ codes, so there is a jni folder at src\main\jni in the structure. One of the C++ function uses fopen to read a text file. The text file to be read is at src\main\jni along with other .cpp/.h as well. I’ve changed the file path for fopen to "/data/data/[package name]/files/XXX.txt" but it still fails. I’ve searched for some related posts but so far there’s no clear solution... thanks for any suggestions! (I'm using Android Studio 2.1.1)
Asked
Active
Viewed 813 times
0
-
The `src` folder will not be there at runtime. – user207421 May 26 '16 at 10:42
1 Answers
1
You should put the text file in the assets folder instead and use the AAssetManager API to read it at runtime. This is summarised in this post: Android read text file from asset folder using C (ndk)
-
Thanks! Where should I add the assets folder ? **src\main\jni** or **src\main** ? – Alison May 26 '16 at 10:56
-
The assets folder, which will be available at runtime in your app, must be placed in src/main. – gmetal May 26 '16 at 11:05
-