背景
我想研究如何在 Android 上创建 Renderscript 脚本以及一般的 Renderscript,在过去的一年里,Android-Studio 成为 Google 支持 Android 应用程序开发的唯一 IDE。
问题
为此,我找到了多个网站,例如:
- https://developer.android.com/guide/topics/renderscript/compute.html#writing-an-rs-kernel https://developer.android.com/guide/topics/renderscript/compute.html#writing-an-rs-kernel
- 如何将 Renderscript 支持库与 Gradle 结合使用 https://stackoverflow.com/questions/19658145/how-to-use-the-renderscript-support-library-with-gradle
- http://developer.android.com/guide/topics/renderscript/compute.html 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/ 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 http://developer.android.com/guide/topics/renderscript/advanced.html
事实是,我见过的所有教程和示例都是针对 Eclipse 的,他们说我需要做的就是在“raw”文件夹中创建一个“rs”文件(也在“src”文件夹中尝试过) “MainActivity.java”文件的同一文件夹),它会自动为我生成所需的 Java 文件,前缀为“ScriptC_”。
但这对我不起作用。
我尝试过的
我从我找到的一些示例(针对 Eclipse)创建了一个名为“julia.rs”的文件。这是代码:
#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”,并期望它填充所需的额外字符,但它没有。
例如,我不能使用这段代码:
mScript=new ScriptC_julia(mRS,getResources(),R.raw.julia);
我还尝试添加对旧 Android 版本的 Renderscript 支持,但这当然没有帮助:
defaultConfig {
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
...
我尝试过的另一件事是通过应用程序的上下文菜单使用 New->Folder->RenderScript 文件夹,但后来出现此错误:
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 脚本的正确方法是什么?
编辑:遗憾的是我再次遇到了完全相同的问题,这一次,将 renderscriptTargetApi 设置为 18 没有帮助。我还尝试过使用 Renderscript 的另一个项目,here https://github.com/mrmike/RenderScriptPlayground and here https://android.googlesource.com/platform/frameworks/rs/+/master/java/tests/HealingBrush/,但两者都有相同的问题:
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
我现在添加了赏金来一劳永逸地解决这个问题。