libsndfile icon indicating copy to clipboard operation
libsndfile copied to clipboard

Add Android gradle build script with NDK cmake and prefab packaging (+ on device test script)

Open jg-hot opened this issue 1 year ago • 3 comments

Added an android subdirectory for building a prefab package and .aar with the Android NDK and gradle build system.

The build script supports building a ready-to-use android library (.aar) via: cd android/ && gradle assembleRelease

Tests may be run on a connected device or emulator via: cd android/ && gradle ndkTest

See the updated documentation in Building-for-Android.md for details.

jg-hot avatar Oct 31 '24 22:10 jg-hot

Cool, hey thanks.

I have limited experience with Gradle, very little with Android dev, so I don't think I can review this. @SoapGentoo @evpobr ?

Would you, @jg-hot , feel confident maintaining this build system?

arthurt avatar Nov 16 '24 18:11 arthurt

@arthurt Absolutely. I do feel comfortable with this build given that the tests are running and passing on:

  • x86_64 emulator
  • arm64-v8a physical device
  • Emulator running API 35 with 16KB page sizes: there was a recent change in the NDK which required all NDK code to be rebuilt with new flags. This is already supported and passing for libsndfile.

If it would be helpful, I can provide the test output (I know not everyone has access to the environment / devices to run the tests). I would also be fine merging changes from this branch into my fork, running the tests, and updating anything if necessary (although breaking changes should be unlikely).

I will probably migrate this build to eliminate the gradle dependency following the pattern that Oboe uses, at some point. You would still need the NDK installed (to build), prefab and mvn (to publish), and adb and a device or emulator to test.

I also have an open PR for an Android build for libsamplerate and I'm working on libmp3lame and a few other libraries as well.

jg-hot avatar Nov 16 '24 19:11 jg-hot

I added support for ENABLE_EXTERNAL_LIBS and ENABLE_MPEG, and this build now links to libogg, libvorbis, libopus, libflac, libmpg123, and libmp3lame.

I've published stable prefab releases of all these libraries to Github packages.

You can now simply add the dependencies and use them without building anything, similar to how oboe works:

Below is the output of ndk-test.sh showing passing tests on a physical Samsung device with arm64-v8a and armeabi-v7a ABIs. https://gist.github.com/jg-hot/25caea21b0dd1c40719a50121df1dcd8

The tests are also passing on x86 and x86_64 emulators, including those with 16KB page sizes.

There are a few things I'd still like to clean up in this PR:

  • Update build file to allow specifying whether or not to include Xiph / MPEG libs. This would be trivial, but in this case, the prefab .json files need to be updated based on the configuration
  • Publish libraries to maven central instead of github packages to make it easier for consumers to include them, without specifying additional repositories
  • Update Android documentation

But for anyone who wants to use this build today, it's basically ready to go! If you need help using it, feel free to leave a comment here until I have a chance to update the docs.

jg-hot avatar Jan 24 '25 18:01 jg-hot