我正在尝试在 Android 本机开发中使用 Renderscript 构建自定义内核。但卡在编译步骤。我参考了https://github.com/rpattabi/renderscript-ndk-cmake。下面是我的 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
)
前几部分只是在 Android NDK 中查找用于 renderscript 的预构建库的标头。
错误出现在构建renderscript
库部分。它假设构建threshold.rs
文件,并生成一个头文件和 cpp 对(ScriptC_threshold.h 和 ScriptC_threshold.cpp),源代码renderscript
将包含这些文件。
但是,构建脚本不会生成ScriptC_threshold.h
标头。允许我从rs
文件生成头文件的过程或 CMakeList 配置是什么?
更新 1 根据 Dan 的建议,我将构建脚本从 cmakeList 更改为 Android.mk。但是,我遇到了另一个错误
[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
构建过程似乎无法从 .rs 脚本生成 .bc 文件。我又被困住了。我将我的代码上传到Github,它应该能够重现。