Build NDK Googletest based C++ tests with gradle and run them on an Android device. Can be used in Android studio.
It is important to have a compiling NDK configuration in place.
Simply apply the plugin and you're ready to go.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.fsbarata:ndktest-gradle-plugin:1.0.0
}
}
apply plugin: 'com.github.fsbarata.ndktest'
This will add multiple tasks to your project:
- compileVariantNdkTest
- connectedVariantNdkTest
Simply running the connectedVariantNdkTest will compile it and run on the device.
After configuring your NDK, you may configure NDK test plugin by the following:
android {
...
sourceSets {
test {
jni.srcDirs = ['src/test/jni']
}
}
}
ndktest {
cFlags = "-std=c++11"
ldLibs = ["log"]
abiFilters = ['x86','armeabi-v7a']
}
- Currently not compatible with gradle experimental plugin
- Does not run as a testing task
- Cannot debug on device using Android studio (some code is in place but I was unable to fix the gdb server)
- Does not support multiple devices
- Use abi filters to avoid compiling every architecture every time. Use the architecture of the device under test.
- Create a gradle task Android studio run configuration
- Disable jniDebuggable for faster builds and runs