2

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.

2 Answers 2

3

This is due to a bug in ndk-build which doesn't pass "-target-api 19" to llvm-rs-cc. Since the first RS support in NDK r9b, the RenderScript host tools (bcc_compat, llvm-rs-c, etc, compiled from K branch, API 19) weren't updated until r10c when they were rebuilt from L branch (API 21). Without the explicit option "-target-api N", llvm-rs-cc in r10c+ uses the default API which is 21, and fail version check in Kitkat's bcinfo as seen in logcat.

Fix is submitted and will be available in NDK r10e or later: https://android-review.googlesource.com/#/c/124641

1
  • That explains it. Thanks.
    – aschmied
    Commented Jan 28, 2015 at 15:32
1

There is a separate property you need to set for the Renderscript API version to target. If you wish to target API 19, then edit your project.properties file and add these:

renderscript.target=19
renderscript.support.mode=true

That will build your Renderscript binaries for API 19 and fall back to a compatible bitcode version if it is run on a different version.

5
  • Thanks for the answer. I forgot to mention that I had tried this as well and it doesn't solve the problem. I've updated the question.
    – aschmied
    Commented Jan 21, 2015 at 15:11
  • I don't see an update to the question. It shows that only the main target API was set, not the renderscript target. Commented Jan 21, 2015 at 15:15
  • Ah sorry. I commented before writing the update... should have done that the other way around. It's updated now.
    – aschmied
    Commented Jan 21, 2015 at 15:20
  • Try removing the renderscript.mode.support=true line but leave in the renderscript.target line. Commented Jan 21, 2015 at 15:22
  • 1
    That gets it building, but I get the same crash. Also, I believe it's pulling in the correct libRSSupport.so when I do it Android.mk because I see this output from ndk-build: "[armeabi-v7a] Prebuilt : libRSSupport.so <= <NDK>/platforms/android-19/arch-arm/usr/lib/rs/"
    – aschmied
    Commented Jan 21, 2015 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.