I’m trying to build a .so shared library for Android with gradle cpp plugin on Mac OS X. It seems like gradle cpp plugin forces linker options to generate a .dylib file. Since I’m using Android’s NDK toolchain (gcc), the toolchain’s linker doesn’t understand those options. I’m assuming it is passing -install_name option which is unrecognized the ‘ld’. I’m getting the following error. I tried removing the linker option by using args.remove “-install_name” but I still get the same error. Note that using ndk-build is not an option for me. Key question is how do I generate a .so shared library using gradle cpp plugin.
:CoreLib:compileCoreLibDebugSharedLibraryCoreLibCpp
:CoreLib:linkCoreLibDebugSharedLibrary
/Users/UNKNOWN/Library/Android/toolchain/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: -install_name: unknown option
/Users/UNKNOWN/Library/Android/toolchain/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
:CoreLib:linkCoreLibDebugSharedLibrary FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':CoreLib:linkCoreLibDebugSharedLibrary'.
> A build operation failed.
Linker failed while linking libCoreLib.dylib.
Here is my build.gradle file:
apply plugin: 'cpp'
model {
components {
CoreLib(NativeLibrarySpec) {
targetPlatform "arm"
sources {
cpp {
source {
srcDirs "src"
}
}
}
}
}
toolChains {
gcc(Gcc) {
target("arm"){
path "$NDK_TOOLCHAIN/arm-linux-androideabi-4.9/arm-linux-androideabi/bin"
cppCompiler.withArguments { args ->
args << "-marm"
args << "-mandroid"
args << "-march=armv7-a"
args << "-mabi=aapcs-linux"
args << "-std=c++11"
}
linker.withArguments { args ->
args << "-marm"
args << "-mandroid"
args << "-march=armv7-a"
args << "-mabi=aapcs-linux"
args << "-std=c++11"
}
}
}
}
platforms {
arm {
architecture "arm"
}
}
buildTypes {
debug
release
}
}