android - Android 4.1.x 手机上的 Renderscript 运行时错误 "failed to read script metadata"

标签 android renderscript android-sdk-tools

我有三个 Renderscript 函数(在三个单独的 RS 文件中)过去在 Adroid 4.1.x 手机上运行良好。然而,在我升级到 ADK 18 之后,它们开始出现运行时错误,并在同一部手机上崩溃。错误是这样的:

V/RenderScript( 3644): rsContextCreate dev=0x5a2f0fc0
V/RenderScript( 3644): 0x40051010 Launching thread(s), CPUs 0
V/ScriptC ( 3644): Create script for resource = levels
E/bcc     ( 3644): CPU is krait2
E/bcc     ( 3644): Cache dependency levels sha1 mismatch:
E/bcc     ( 3644):   given:  4144ab455aa71df31932ff5baf15583cf1775d72
E/bcc     ( 3644):   cached: d2ab2c2b568810d8ca0c39d730cb2494cae89106
V/ScriptC ( 3644): Create script for resource = sepia
E/bcc     ( 3644): Cache dependency sepia sha1 mismatch:
E/bcc     ( 3644):   given:  6b15396c900dd23c700b8c13e7d5019fb72fcb0e
E/bcc     ( 3644):   cached: 8d011a42147f8d3895db549e0b3fe4a43ed49fe2
V/ScriptC ( 3644): Create script for resource = flip
E/bcinfo  ( 3644): Could not parse bitcode file
E/bcinfo  ( 3644): Invalid SWITCH record
E/RenderScript( 3644): bcinfo: failed to read script metadata
W/dalvikvm( 3644): threadid=1: thread exiting with uncaught exception (group=0x410f4498)
E/AndroidRuntime( 3644): FATAL EXCEPTION: main

值得注意的是,在 4.2.x 和更新的设备上,Renderscript 函数仍然有效。

在“project.properties”文件中,我尝试了 sdk.buildtools = 17.0.0、18.0.1、18.1.0、18.1.1 和 19.0.0。它们都不能在 4.1.x 手机上运行,​​尽管错误消息在 19.0.0 上略有变化。我用谷歌搜索了错误消息“无法读取脚本元数据”。显然 it was added by Stephen Hines .我不太了解斯蒂芬的变化,所以我想问以下问题:

  1. 为什么要进行更改?
  2. 我的 Renderscript 函数在 4.1.x 设备上停止工作的最可能原因是什么?
  3. 如何修复崩溃?

下面列出了导致崩溃的 flip.rs。欢迎提出建议和意见。谢谢!

#pragma version(1)
#pragma rs java_package_name(com.xxxx.yyyy.zzzz)
#include "rs_time.rsh"

rs_script flipScript;
rs_allocation gIn;
rs_allocation gOut;
int width;
int height;
int direction = 0;

void root(const uchar4 *v_in, uchar4 *v_out, const void *usrData, uint32_t x, uint32_t y) {
    if(direction == 0) { // flip horizontally
        const uchar4 *element = rsGetElementAt(gIn, width - x, y);
        float4 color = rsUnpackColor8888(*element);
        float4 output = {color.r, color.g, color.b};
        *v_out = rsPackColorTo8888(output);
    }
    else if(direction == 1) { // flip vertically
        const uchar4 *element = rsGetElementAt(gIn, x, height - y);
        float4 color = rsUnpackColor8888(*element);
        float4 output = {color.r, color.g, color.b};
        *v_out = rsPackColorTo8888(output);
    }
    else if(direction == 2) { // rotate left
        const uchar4 *element = rsGetElementAt(gIn, width - y, x);
        float4 color = rsUnpackColor8888(*element);
        float4 output = {color.r, color.g, color.b};
        *v_out = rsPackColorTo8888(output);
    }
    else if(direction == 3) { // rotate right
        const uchar4 *element = rsGetElementAt(gIn, y, height - x);
        float4 color = rsUnpackColor8888(*element);
        float4 output = {color.r, color.g, color.b};
        *v_out = rsPackColorTo8888(output);
    }
}

void flip(int testIdx) {
    int64_t  t0, t1;
    int64_t  t;
    t0 = rsUptimeNanos();
    rsForEach(flipScript, gIn, gOut);
    t1 = rsUptimeNanos();
    t = t1 - t0;
    rsDebug("  flip: timer on RS side: ", t);
    timeNanoSec[testIdx] = (float)t;
}

最佳答案

您要针对什么目标 API 进行编译?你能给我一个 apk 或至少 3 个失败的 .bc 文件吗?

这看起来像是仅适用于 v16 (JellyBean) 设备的位码编码问题。它与您提到的更改列表无关,但实际上与 switch 语句中范围值的合并有关。这是编译器前端 llvm-rs-cc 中的错误。 Libbcc(设备上的编译器)正确地拒绝了 v16 设备无法读取的错误位码(即,合并的大小写范围)。我将提交一个错误以在内部修复此问题,并希望在未来的 SDK 更新中发布它。同时,我建议您使用 RenderScript 支持库,它可以绕过这个特定的错误(因为它不会生成 v16 位代码)。

关于android - Android 4.1.x 手机上的 Renderscript 运行时错误 "failed to read script metadata",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20577674/

相关文章:

android - 无法加载 memtrack 模块(没有这样的文件或目录)

android - 如何从 JSON 数组中获取单个随机 JSONObject

java - Renderscript 未在反射层中创建 ScriptField 类

使用 calabash-android 时的 Android SDK 路径问题

android - 支持库中带有 ScriptIntrinsicBlur 的图像缺陷

android - 使用渲染脚本支持库时出现多个 dex 错误

android - 如何通过android studio安装旧的android sdk?

android - 如何将Android ROM源码导入Android Studio?

android - 不生成apk

android - 将 Facebook sdk 添加为库项目时,eclipse 无法识别其他库