[jme3-android-native] Refractor android build to use a single native module

While working with jme3-android-naitve module, i found multiple sub-modules (or source directories if you will) with a headers folder generated automatically using (compileargs+= -h)…okay what’s wrong with this ?

Redundancy and unfamiliarity of build scripts, it complicates simple stuff, for instance when i did implemented the feature NativeBufferAllocator it took me days to understand the building.

├── build.gradle
├── decode.gradle
├── openalsoft.gradle
├── src
│   └── native
│       ├── headers
│       │   ├── com_jme3_audio_android_AndroidALC.h
│       │   ├── com_jme3_audio_android_AndroidAL.h
│       │   ├── com_jme3_audio_android_AndroidEFX.h
│       │   ├── com_jme3_audio_plugins_NativeVorbisFile.h
│       │   ├── com_jme3_texture_plugins_AndroidNativeImageLoader.h
│       │   └── com_jme3_util_AndroidNativeBufferAllocator.h
│       ├── jme_bufferallocator
│       │   ├── Android.mk
│       │   ├── Application.mk
│       │   └── com_jme3_util_AndroidNativeBufferAllocator.c
│       ├── jme_decode
│       │   ├── Android.mk
│       │   ├── Application.mk
│       │   ├── com_jme3_audio_plugins_NativeVorbisFile.c
│       │   └── com_jme3_texture_plugins_AndroidNativeImageLoader.c
│       └── jme_openalsoft
│           ├── Android.mk
│           ├── Application.mk
│           ├── com_jme3_audio_android_AndroidAL.c
│           ├── com_jme3_audio_android_AndroidALC.c
│           ├── com_jme3_audio_android_AndroidEFX.c
│           ├── config.h
│           ├── util.h
│           └── version.h

as you can see Android.mk, Application.mk and build.gradle are repeated across all sources (and they have redundant code inside as well).

How to make it better ?

Migrate to the classic native style under src/main/native :

  • include dir for all headers.
  • lib dir for all sources.
  • Unifying Android.mk, Application.mk and gradle script.
  • Merge all android native object files into one single file libandroidjme.so (this will add some changes to the static initializers of jme3-android module).

By doing so, it will be easy to add new features on android natives (without even touching the build script or understanding it) and we will avoid build up of non-sense redundant build scripts over time when new features are added to the module.

These changes might take a lot of time to do, let me know your opinion even if you haven’t touched an android code before, but has worked before on native code.

we might able to use folders too under src/main/native/lib and ``src/main/native/include`, so :

  1. src/main/native/include/decode/..., src/main/native/lib/decode/...
  2. src/main/native/include/openalsoft/..., src/main/native/lib/openalsoft/...
  3. src/main/native/include/bufferallocator/..., src/main/native/lib/bufferallocator/...
    Much cleaner, isn’t it ?
1 Like

I’m fine with the proposed changes, as long as they work!

1 Like

Thank you, i will wait sometime and see the best i can do to reach these goals :

  • Avoid duplication of build scripts.
  • Make the new features can be added instantly without working with the build script.
  • Use jni standards (cannot find a good reference for this, so i suggested the classic natives style).

Currently, the best in mind is the classic native include/lib, although it has a downside that jni is a little different than natives include files…(that they are class oriented for example, so one include is for only one lib and so forth), if you have a good suggestion, let me know.