Template with a minimal native Android application in C.
- C 99%
- Makefile 1%
| app/src/main | Refactoring code and several improvements. | |
| .clang-format | Refactoring code and add clangd LSP config files. | |
| .clangd | Refactoring code and add clangd LSP config files. | |
| .env.example | First commit: minimal (template) native application Android. | |
| .gitignore | First commit: minimal (template) native application Android. | |
| Makefile | First commit: minimal (template) native application Android. | |
| README.md | More resources and examples. | |
My Native Application (myna)
A Hobby project to learn about developing Native Applications in C for Android.
Here you can see a minimal template for develop Native Applications in C for Android.
Tools needed:
- Android SDK
- Android NDK
Keystore File
Ensure the keystore file mykeystore.jks exists in the directory where Makefileis, or create one with:
keytool -genkeypair -dname "cn=Mark Jones, ou=JavaSoft, o=Sun, c=US" -alias business -keypass your_password -keystore mykeystore.jks -storepass your_password -validity 20000 -keyalg RSA
Environment File
Copy and paste .env.example file to .env one, and complete the environment variables.
BUILD_TOOLS_VERSION and ANDROID_TARGET can be changed. If you need install new build tools versions use this command:
sdkmanager "platforms;android-30" "build-tools;30.0.3"
In the above command an Android 30 platform and build tools 30.0.3 versions are downloaded. And then you could use them for ANDROID_TARGET and BUILD_TOOLS_VERSION.
Build Process Overview
- Native Code Compilation: The NDK builds the C code into shared libraries for armeabi-v7a and arm64-v8a architectures
- APK Creation: An empty APK is created with the manifest, resources, and assets
- Library Inclusion: Native libraries are added to the APK in the correct location (
lib/<abi>/) - Alignment: The APK is aligned for better performance
- Signing: The APK is signed with the provided keystore
- Cleanup: Temporary files are removed
The project is ready to build/install/debug using Makefile. Read it to see targets. Basically, you can:
- Install in the device connected to your computer (
make install) - Debug the app from device connected to your computer (
make debug)
Resources
- NDK Oficial
- NDK Guías
- NDK Oficial Samples
- Inspiration: FlappyBird by Vadim Boev
- Native C Android App Create.
- Learn OpenGL book/web
- Open Game Art
- Socket and IPC Examples
Notes
android_native_app_glue.h/.cfiles simplify lifecyle management and they can be found on NDK foldersources/android/native_app_glue- All NDK headers can be found on NDK folder
toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include - All NDK libraries can be found on NDK folder
toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib