Help with transitioning from Android gradle JNI build to OSX gradle JNI build


(Maxime) #1

Hello,
First off, sorry if my question comes as stupid or anything, I’m a bit lost with Gradle. We’re using Gradle for our project (with runs with LibGDX, it’s a multi-platform game). So we’ve got an android module, a desktop (OSX + Windows) module and an iOS module. Everything is coded in Java.

Now we’ve integrated the Superpowered SDK, which is a C++ SDK for audio processing. This led to me adding JNI to the android module (with some C++ sources, some tweaks to the build.gradle to compile the JNI C++ with Cmake for android). Overall it works fine, however I’d like to also make this work for our desktop module (so ideally OSX and Windows, although just OSX would be enough for now).

And I’m utterly lost, I have no idea how to do that, quite frankly. Here’s what our build.gradle for Android does in defaultConfig :

ndk {
        abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' // these platforms cover 99% percent of all Android devices
    }

    externalNativeBuild {
        cmake {
            arguments '-DANDROID_PLATFORM=android-16', '-DANDROID_TOOLCHAIN=clang', '-DANDROID_ARM_NEON=TRUE', '-DANDROID_STL=gnustl_static', "-DPATH_TO_SUPERPOWERED:STRING=${superpowered_sdk_path}"
            cFlags '-O3', '-fsigned-char' // full optimization, char data type is signed
            cppFlags '-fsigned-char', "-I${superpowered_sdk_path}"
        }
    } 

And a bit lower :

sourceSets {
    main {
        jniLibs.srcDirs = ['src/main/jni', 'libs']
    }
}

externalNativeBuild {
    cmake {
        path 'src/main/jni/CMakeLists.txt'
    }
} 

And in the Java code that’s android-specific, I just have to do the standard JNI stuff (so System.loadLibrary(), and declare my native methods that point to the C++ methods).

Now, in my desktop module I have no idea how to set up the build.gradle to do that. Can I even use cmake for that ? Or should I directly use g++ ? Basically, how to “translate” this build.gradle from Android to a desktop environment ?

Any help would be greatly appreciated !