I am using the Android NDK to make an application primarily in C for performance reasons, but it appears that file operations such as fopen do not work correctly in Android. Whenever I try to use these functions, the application crashes.
How do I create/write to a file with the Android NDK?
You can open a file through the NDK using FILE and fopen , but don't forget to place a permission for it. In manifest developer.android.com/guide/topics/manifest/… Thanks, it works! And I also found out the updates on the manifest file will only take effect after you re-install the app.
The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.
JNI is just the way that Java handles calling into native/C++ code, and calling back into Java from there. It has nothing to say about Android - it is a Java language feature. The Android NDK is a way to write Android applications using code called by JNI.
The NDK itself invokes a customized cross-compiler built on the arm-eabi-gcc compiler.
Other answers are correct. You can open a file through the NDK using FILE
and fopen
, but don't forget to place a permission for it.
In the Android manifest place:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With