0

I am trying to build a custom kernel with Renderscript in Android native development. But got stuck at the compilation step. I took reference with the https://github.com/rpattabi/renderscript-ndk-cmake. Below is my CMakeList.txt

cmake_minimum_required(VERSION 3.4.1)

if(${CMAKE_BUILD_TYPE} MATCHES Release)
 set (SRC_RS_GENERATED_PATH 
    build/generated/source/rs/release)
 else()
    set (SRC_RS_GENERATED_PATH 
    build/generated/source/rs/debug)
endif()
    set(RENDER_SCRIPT_HEADERS_PATH ${CMAKE_ANDROID_NDK}/toolchains/renderscript/prebuilt/${ANDROID_HOST_TAG}/platform/rs)

include_directories(
        ${RENDER_SCRIPT_HEADERS_PATH}/cpp
        ${RENDER_SCRIPT_HEADERS_PATH}/scriptc
        ${RENDER_SCRIPT_HEADERS_PATH}
        ${SRC_RS_GENERATED_PATH}
)

set(RENDER_SCRIPT_LIB_PATH ${CMAKE_ANDROID_NDK}/toolchains/renderscript/prebuilt/${ANDROID_HOST_TAG}/platform/${ANDROID_SYSROOT_ABI})
find_library(rscript
        NAMES RScpp_static libRScpp_static.a
        HINTS ${RENDER_SCRIPT_LIB_PATH}/
        )
find_library(blasv8
        NAMES blasV8 libblasV8.so
        HINTS ${RENDER_SCRIPT_LIB_PATH}/)
find_library(rssupport
        NAMES libRSSupport.so
        HINTS ${RENDER_SCRIPT_LIB_PATH}/)

add_library(
        renderscript
        SHARED
        RenderScript.cpp
        threshold.rs
    ${SRC_RS_GENERATED_PATH}/ScriptC_threshold.cpp #This file is missing <<<<<<<<<<<<<<<
)

target_link_libraries(
        renderscript
        log
        ${rscript}
        ${rssupport}
        ${blasv8}
        android
        jnigraphics
        )

The first few parts are just finding the headers for prebuilt library for renderscript in the Android NDK.

The error comes at building the renderscript library part. It suppose to build the threshold.rs file, and generate a header and cpp pair (ScriptC_threshold.h and ScriptC_threshold.cpp), which the source code for renderscript will include.

However, the build script does not generate the ScriptC_threshold.h headers. What is the procedure or CMakeList configuration that allows me to generate the header file from rs files?

Update 1 As suggested by Dan, I change the build script from cmakeList to Android.mk. However, I got another error

[x86] Compile RS     : renderscript <= threshold.rs

  error: error opening 'E:/dev/android/RenderScriptMk/app/E:/dev/android/RenderScriptMk/app/build/intermediates/ndkBuild/debug/obj/local/x86/objs-debug/renderscript/\threshold.bc': Invalid argument
  make: *** [E:/dev/android/RenderScriptMk/app/build/intermediates/ndkBuild/debug/obj/local/x86/objs-debug/renderscript/threshold.o] Error 1

It appears the build process failed to generate the .bc file from the .rs script. I am stuck again. I uploaded my code to Github, it should be able to reproduce.

HarryQ
  • 1,281
  • 2
  • 10
  • 25
  • Why not just use ndk-build where renderscript is actually supported? – Dan Albert Nov 01 '19 at 07:36
  • @Dan Albert Currently I am using Android Studio 3.5.1 and NDK r20. By default C++ support project uses CMake, so I went down this route. Also I believe CMake can do what ndk-build does. Actually I successfully linked to the prebuilt render script library, and used its blur kernel. It is when I want to write my custom kernel (threshold.rs) that got stuck – HarryQ Nov 01 '19 at 14:16
  • 1
    You're better off with ndk-build for renderscript. ndk-build actually supports it; you don't have to build all the support yourself. – Dan Albert Nov 01 '19 at 18:14
  • I converted my project to using ndk-build and Android.mk based. but now I got another error ```'E:/dev/android/RenderScriptMk/app/E:/dev/android/RenderScriptMk/app/build/intermediates/ndkBuild/debug/obj/local/x86/objs-debug/renderscript/\threshold.bc': Invalid argument make: *** [E:/dev/android/RenderScriptMk/app/build/intermediates/ndkBuild/debug/obj/local/x86/objs-debug/renderscript/threshold.o]``` – HarryQ Nov 02 '19 at 23:32
  • Seems that's a bug on Windows when `NDK_OUT` is set: https://github.com/android/ndk/issues/856. – Dan Albert Nov 04 '19 at 03:23

0 Answers0