问题描述
我在previous文章中提到(),我尝试在运行时编译renderscript code。
正如Kietz建议我需要改变,从所有生成的Java类的派生类ScriptC。
使我自己的类扩展,因为我不能调用此超类的构造函数脚本失败。
As I mentioned in my previous post (Compiling renderscript code at runtime), I try to compile renderscript code at runtime.As suggested by Kietz I need to alter the ScriptC class from which all generated java classes derive.Making my own class that extends Script fails because I cannot invoke the constructor of this super class.
在code的这段代码
public class RuntimeScriptC extends Script {
private static final String TAG = "RuntimeScriptC";
protected RuntimeScriptC(int id, RenderScript rs) {
super(id, rs);
}
给我这个错误:
The constructor Script(int, RenderScript) is undefined
我的下一个想法是我自己的类添加到renderscript源$ C $ c和编译它来创建
一个新的.jar。我发现但不知道如何只建立renderscript包。
My next idea was to add my own class to the renderscript source code and compile it to createa new .jar. I found the source code on git but have no idea how to only build the renderscript package.
编辑:
我刚刚发现 Script.java
的构造函数是包专用。这就是为什么我不能在我自己的类访问的构造函数。如果我可以编译renderscript来源自己,我可以把我自己的类到包和访问它。
I just found out that the constructor of Script.java
is package private. That's why I can't access the constructor in my own class. If I can compile the renderscript sources myself I could place my own class into the package and access it.
新的问题:我在哪里可以找到renderscript来源,我怎么能编译它们
推荐答案
RenderScript的源代码可以在 android.googlesource.com ,与Android的其余部分一起。如果要重建Android或它的一部分,可能是一个好地方启动。
RenderScript's source can be found at android.googlesource.com, along with that of the rest of Android. If you want to rebuild Android or a part of it, here is probably a good place to start.
然而,这是矫枉过正。如果你不能修改 ScriptC
直接,只是继承它。因为您从 ScriptC
是其受保护的构造需要的唯一方法这是可能的。比如,我写了 HackedScriptC
它什么都不做,但提出其论点 ScriptC()
:
However, that is overkill. If you can't modify ScriptC
directly, just inherit from it. This is possible because the only methods you need from ScriptC
are its protected constructors. For example, I wrote HackedScriptC
which does nothing but forward its arguments to ScriptC()
:
package com.example.android.rs.extremehax;
import android.content.res.Resources;
import android.renderscript.RenderScript;
import android.renderscript.ScriptC;
public class HackedScriptC extends ScriptC {
public HackedScriptC(RenderScript rs, Resources resources, int id) {
// simple passthru to the only constructor that ScriptC_mono uses
super(rs, resources, id);
}
}
它现在可以在胶类代替 ScriptC
:
package com.example.android.rs.extremehax;
// ...
public class ScriptC_mono extends HackedScriptC {
// otherwise identical glue class...
在你的情况,你就不会调用超级构造 ScriptC(RenderScript,资源,INT)
,因为调用 internalCreate
,要重写。相反,调用 ScriptC(INT,RenderScript)
。
In your case, you would not invoke the super constructor ScriptC(RenderScript,Resources,int)
because that invokes internalCreate
, which you want to override. Instead, invoke ScriptC(int,RenderScript)
.
这篇关于编译renderscript源$ C $ C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!