I'm using renderscript for audio dsp processing. It works well until I decided to bump up renderscriptTargetApi
version from 19 to 24 in an attempt to make use of newer renderscript APIs in a backward compatible way.
There is no issue with the compilation, but at runtime, logcat shows error like this
05-31 19:40:23.097 8661-8734/com.example.audio.test E/RenderScript: Unable to open shared library (/data/user/0/com.example.audio.test//lib/librs.xx.so): dlopen failed: library "libRSSupportIO.so" not found
If I have renderscriptTargetApi
as 19 or 20, my apk has librs.xx.so
and there is no error. If I bump it to 21, 23, or 24, librs.xx.so
is not generated and thus I have this runtime error.
I'm using renderscript through NDK i.e. C++. Also using CMake. There aren't instructions I could find to make use of renderscript support library through NDK. All instructions assume that the support library is used through Java.
This is from build.gradle
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
renderscriptNdkModeEnabled true
CMakeLists.txt
has
add_library (dsp SHARED
${SRC_PATH}/dsp.cpp
${SRC_RS_PATH}/xx.rs ${SRC_RS_GENERATED_PATH}/ScriptC_xx.cpp)
target_compile_options(dsp PRIVATE
-std=c++11 -stdlib=libc++ -fno-rtti -fexceptions -Ofast)
target_link_libraries(dsp RScpp_static dl ${log-lib})
This is xx.rs
#pragma version(1)
#pragma rs java_package_name(com.example.audio)
#pragma rs_fp_relaxed
float RS_KERNEL my_kernel(float in, uint32_t x) {
// ...
}
This is how the kernel is called from C++
sp<RS> rs = new RS();
rs->init(app_cache_dir);
sp<const Element> e = Element::F32(rs);
sp<const Type> t = Type::create(rs, e, 44100*10, 0, 0);
sp<Allocation> inAlloc = Allocation::createTyped(rs, t);
inAlloc->copy1DFrom(input);
sp<Allocation> outAlloc = Allocation::createTyped(rs, t);
ScriptC_xx *script = new ScriptC_xx(rs);
script->forEach_xx(inAlloc, outAlloc);
outAlloc->copy1DTo(output);
As you see, it is pretty basic usage scenario of renderscript. It works well with renderscriptTargetApi
in 19 or 20. If I bump up the version, build is still successful, but librs.xx.so
file is not generated. At runtime, we see the above mentioned error about this .so file.
What am I missing here? I tried manipulating my minSdkVersion
which I think is unrelated to renderscript target api. It didn't help.
How can I use the newer renderscript APIs in the backward compatible manner from NDK? Any help is appreciated.
Repo to reproduce the issue
https://github.com/rpattabi/renderscript-ndk-cmake
I've filed a bug report on Android build system about this: https://issuetracker.google.com/issues/109578956