I would like to use Renderscript from C++ code that I compile using the Android NDK. I built the "HelloComputeNDK" sample that ships with the NDK. It runs fine on Lollipop devices, but crashes on KitKat (4.4.4) with the following message on adb logcat
:
E/bcinfo (28302): Invalid API version: 21 is out of range ('11' - '19')
E/RenderScript(28302): Failed to translate bitcode from version: 21
E/rsC++ (28302): Internal error: Object id 0.
F/libc (28302): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 28317 (hellocomputendk)
I/DEBUG ( 363): Build fingerprint: 'htc/bm/htc_m8:4.4.4/KTU84P/401507.4:user/release-keys'
I/DEBUG ( 363): Revision: '0'
I/DEBUG ( 363): pid: 28302, tid: 28317, name: hellocomputendk >>> com.example.android.rs.hellocomputendk <<<
I/DEBUG ( 363): debuggerd: checkTellHTCSettings
I/DEBUG ( 363): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
I have set minSdkVersion="14"
in AndroidManifest.xml, APP_PLATFORM := android-19
in Application.mk, and TARGET_PLATFORM := android-19
in Android.mk. I build the sample using:
android update project --name HelloComputeNDK --path . --target android-19
ndk-build clean
ndk-build -d
ant -verbose debug install
I have seen similar crashes discussed elsewhere, but the problem in those cases was a missing APP_PLATFORM
or TARGET_PLATFORM
. This does does not appear to be the problem here.
I believe I have the same problem as this person: https://stackoverflow.com/questions/27704847/ndk-sample-project-hellocomputendk-crashes, https://stackoverflow.com/questions/27705350/ndk-sample-project-hellocomputendk-problems. I think that question got downvoted because the user posted two that appeared to be duplicates. I have the same problem and I believe it is a legitimate question so I am asking it here.
Edit
I am using SDK build tools version 21.1.2 and NDK r10d.
Edit after Larry Schiefer answer
I also tried adding the following in project.properties:
renderscript.target=19
renderscript.support.mode=true
This gives the error "sdklib.build.DuplicateFileException: Duplicate files at the same path inside the APK" because the HelloComputeNDK example explictly includes the RenderScript support library in "Android.mk":
include $(CLEAR_VARS)
LOCAL_MODULE := RSSupport
LOCAL_SRC_FILES := $(SYSROOT_LINK)/usr/lib/rs/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION)
include $(PREBUILT_SHARED_LIBRARY)
If I remove those lines from Android.mk the example builds and install successfully and I get the same API 21 crash as before.