如何在Android Studio上创建Renderscript脚本,并使它们运行? [英] How to create Renderscript scripts on Android Studio, and make them run?

查看:437
本文介绍了如何在Android Studio上创建Renderscript脚本,并使它们运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想研究一般在Android和Renderscript上创建Renderscript脚本的问题,并且在过去的一年中,Android-Studio成为Google唯一支持Android应用开发的IDE.

I want to research about creating Renderscript scripts on Android and Renderscript in general, and over the past year, Android-Studio became the only IDE that Google supports for Android apps development.

为此,我发现了多个网站,例如:

For this, I've found multiple websites, as such:

  • https://developer.android.com/guide/topics/renderscript/compute.html#writing-an-rs-kernel
  • How to use the Renderscript Support Library with Gradle
  • http://developer.android.com/guide/topics/renderscript/compute.html
  • https://futurestud.io/blog/how-to-use-the-renderscript-support-library-with-gradle-based-android-projects/
  • http://developer.android.com/guide/topics/renderscript/advanced.html

问题是,我看过的所有教程和示例都是针对Eclipse的,他们说,我要做的就是在原始"文件夹中创建一个"rs"文件(也在"src"文件夹中尝试过) ,在"MainActivity.java"文件的同一文件夹中),它将为我自动生成前缀为"ScriptC_"的所需Java文件.

Thing is, all the tutorials and samples I've seen are for Eclipse, and they say that all I need to do is create an "rs" file inside the "raw" folder (also tried in the "src" folder, in the same folder of the "MainActivity.java" file), and it will auto-generate the needed Java files for me, having a prefix of "ScriptC_".

但这对我不起作用.

我已经从我发现的一些示例(对于Eclipse)中创建了一个名为"julia.rs"的文件.这是代码:

I've created a file from some sample I've found (for Eclipse) called "julia.rs". Here's the code:

#pragma version(1)
#pragma rs java_package_name(lb.com.myapplication)

float cx;
float cy;
float width;
float height;
float zoom;
int precision;

uchar *color;

void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
    float fx = (x + 0.5f) / width * (4.f / zoom) - (2.f / zoom);
    float fy = (y + 0.5f) / height * (4.f / zoom) - (2.f / zoom);

    float t = 0;
    int k = 0;

    while(k < precision - 1) {
        t = fx * fx - fy * fy + cx;
        fy = 2 * fx * fy + cy;
        fx = t;
        if (fx * fx + fy * fy >= 4) {
           break;
        }
        k++;
    }
    out->b = color[k*3+0];
    out->g = color[k*3+1];
    out->r = color[k*3+2];
}

在Java文件中,我想访问新创建的文件,因此我开始编写"ScriptC",并期望它可以填充所需的额外字符,但事实并非如此.

In the java file, I wanted to access the newly created file, so I started to write "ScriptC", and expected it to fill the needed extra characters, but it doesn't.

例如,我不能使用这段代码:

I can't for example use this piece of code:

mScript=new ScriptC_julia(mRS,getResources(),R.raw.julia);

我还尝试为较旧的Android版本添加Renderscript支持,但这当然无济于事:

I've also tried to add Renderscript support for older Android versions, but this of course didn't help:

defaultConfig {
    renderscriptTargetApi 22
    renderscriptSupportModeEnabled true
    ...

我尝试过的另一件事是通过应用程序的上下文菜单使用New-> Folder-> RenderScript文件夹,但是随后出现此错误:

Another thing I've tried is to use New->Folder->RenderScript folder via the context menu of the app, but then I got this error:

Error:Execution failed for task ':app:compileDebugRenderscript'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\AppData\Local\Android\Sdk\build-tools\23.0.0-preview\llvm-rs-cc.exe'' finished with non-zero exit value -1073741515

问题

在Android-Studio上创建和运行Renderscript脚本的正确方法是什么?

The question

What's the correct way to create and run a Renderscript script on Android-Studio?

遗憾的是我又遇到了完全相同的问题,这一次,将renderscriptTargetApi设置为18并没有帮助.我还尝试了另一个使用Renderscript的项目, 此处 此处 ,但是两者都有相同的问题:

Sadly I have the exact same issue again, and this time, setting renderscriptTargetApi to 18 doesn't help. I've also tried another projects with Renderscript, here and here, but both have the same issues:

Error:Execution failed for task ':renderscript:compileArmDebugRenderscript'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\android\Sdk\build-tools\23.0.1\llvm-rs-cc.exe'' finished with non-zero exit value -1073741515

我现在添加了赏金,以一劳永逸地解决这个问题.

I've now added a bounty to solve this issue once and for all.

推荐答案

成功构建项目所需的唯一修改就是将renderscriptTargetApi的值从22更改为18.否则,Renderscript脚本编译会生成使用64位ABI的中间文件. ,其构建过程无法与使用32位ABI的22.0.01构建工具中的预编译中间体链接.

The only modification your project needed to build successfully was changing renderscriptTargetApi value from 22 to 18. Otherwise Renderscript script compilation produces intermediate files that use 64-bit ABI, which the build process fails to link with precompiled intermediates in 22.0.01 build tools that use 32-bit ABI.

更新:自2015年9月起,新版本的构建工具(23.0.0)不能与Renderscript支持库一起使用,因此您必须禁用它或将工具还原为22.0.01.

UPDATE: as of September 2015 the new version of build tools (23.0.0) does not work with Renderscript support library, so either you have to disable it or revert the tools to 22.0.01.

这篇关于如何在Android Studio上创建Renderscript脚本,并使它们运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆