使用renderscript v8支持模式构建一个jar

时间:2017-10-31 03:34:49

标签: android renderscript

我已经将项目添加到github: https://github.com/akbarxie/testRenderScriptSupportModel

在我们的项目中,我们想使用renderscript支持模式来创建一个Android SDK,而这个sdk需要支持android 4.0。我们使用支持“android.support.v8.renderscript”。在我们将它传送到jar模块之后,当我在android 4.0上运行它时,我们得到这样的运行时错误,

Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0

at android.content.res.Resources.getValue(Resources.java:1048)

at android.content.res.Resources.openRawResource(Resources.java:967)

at android.content.res.Resources.openRawResource(Resources.java:949)

at android.support.v8.renderscript.ScriptC.internalCreate(ScriptC.java:91)

at android.support.v8.renderscript.ScriptC.<init>(ScriptC.java:59)

at albin.imperialvision.com.testsr.ScriptC_merge4Images.<init>(ScriptC_merge4Images.java:42)

at albin.imperialvision.com.testsr.ScriptC_merge4Images.<init>(ScriptC_merge4Images.java:34)

at albin.imperialvision.com.testsr.TestScriptC.<init>(TestScriptC.java:16)

at albin.imperialvision.com.testrenderscriptsupport.MainActivity.onCreate(MainActivity.java:29)

at android.app.Activity.performCreate(Activity.java:5143)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135) 

at android.app.ActivityThread.access$700(ActivityThread.java:131) 

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228) 

at android.os.Handler.dispatchMessage(Handler.java:99) 

at android.os.Looper.loop(Looper.java:137) 

at android.app.ActivityThread.main(ActivityThread.java:4866) 

at java.lang.reflect.Method.invokeNative(Native Method) 

at java.lang.reflect.Method.invoke(Method.java:511) 

 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 

at dalvik.system.NativeStart.main(Native Method) 
    10-31 11:09:32.480 19402-19429/albin.imperialvision.com.testrenderscriptsupport A/libc: Fatal signal 11 (SIGSEGV) at 0x00000010 (code=1),
thread 19429 (erscriptsupport)

for java part TestScriptC.java:

import android.content.Context;
import android.support.v8.renderscript.RenderScript;

/**
 * Created by kevin on 17-10-30.
 */

public class TestScriptC {
    public TestScriptC(Context context)
    {
        ScriptC_merge4Images merge4Images;
        merge4Images=new ScriptC_merge4Images(RenderScript.create(context));
    }

}

和renderscript merge4Images.rs:

#pragma version(1)
#pragma rs_fp_relaxed
#pragma rs java_package_name(albin.imperialvision.com.testsr)

rs_allocation a_Blob;
rs_allocation b_Blob;
rs_allocation c_Blob;
rs_allocation d_Blob;


uint aoutHeight_dstHPad;
uint aoutWidth_dstWPad;
uint RightOffset_dstWPad;
uint coutWidth_dstWPad;
uint BottomOffset_dstHPad;




void root(uchar4 * out,uint x,uint y)
{

    if(y<aoutHeight_dstHPad)
    {
       *out = ( (x<aoutWidth_dstWPad) ?  rsGetElementAt_uchar4(a_Blob,x,y) : rsGetElementAt_uchar4(b_Blob,x-RightOffset_dstWPad,y) );
    }
    else
    {
       *out = ( (x<coutWidth_dstWPad) ?  rsGetElementAt_uchar4(c_Blob,x,y-BottomOffset_dstHPad) : rsGetElementAt_uchar4(d_Blob,x-RightOffset_dstWPad,y-BottomOffset_dstHPad) );
    }


}

如果我们只是将代码添加到项目中,我测试了它,程序运行正常,但是当它添加为jar时,它就会出错。 如错误所示,此处可能出现错误:

 public  ScriptC_merge4Images(RenderScript rs) {
        this(rs, //  (ScriptC_merge4Images.java:34)
             rs.getApplicationContext().getResources(),
             rs.getApplicationContext().getResources().getIdentifier(
                 __rs_resource_name, "raw",
                 rs.getApplicationContext().getPackageName())//the wrong id from here 
             );
    }

    public  ScriptC_merge4Images(RenderScript rs, Resources resources, int id) {
        super(rs, resources, id);//get wrong id here  (ScriptC_merge4Images.java:42)
        __ALLOCATION = Element.ALLOCATION(rs);
        __U32 = Element.U32(rs);
        __U8_4 = Element.U8_4(rs);
    }

0 个答案:

没有答案