Anyone have a "simple" way for running android nat...
# kotlin-native
m
Anyone have a "simple" way for running android native tests on an emulator? I've got a kmp library and want to support android native, but to ensure things work properly, there is some minimal platform specific code that needs to be put under test on a device/emulator.
j
How simple? Seems like you can adb push the kexe and then execute with adb shell
Just gotta be careful on older emulators the exit code wasn't propagated across the bridge, but that's probably not a problem for anything modern anymore
Here's a thing I wrote a long time ago
Copy code
// The exit code of a command is not available through ddmlib. Additionally, on older devices,
// 'adb shell' always returns 0 as an exit code even when the real value was non-zero. // We print the exit code so it can be read from stdout to work around both problems. val output = device.executeShellCommand( "dalvikvm $extraArgs -classpath $DEVICE_DEX_PATH $entryPoint; echo $?") // Those problematic older devices also write exceptions to stdout instead of stderr. Take the // last non-empty stdout line to parse as the exit code. val exitCodeString = output.trim().lines().last() return exitCodeString == "0"
(Sorry Slack mobile hates user input)
h
Depends on your definition of simple, but the Android Gradle Plugin supports integration tests (Gradle Managed Devices) out of the box, including downloading.
m
Thanks @jw! I modified your setup to compile android native test binaries and packaged them into
jniLibs
such that my instrumentation tests on the emulator run em via
java.lang.Process
after locating them in
Context.applicationInfo.nativeLibraryDir
. Am able to pass in expected test values via process environment variables and what not, too. Check it out! https://github.com/05nelsonm/kmp-file/pull/85/commits/390f40e9749bff7d679567127c883b206ab00dc0