我在尝试实现一些用Renderscript for Android编写的代码时遇到了不同的麻烦。 首先让我说我的所有SDK包都是22.3版本的最新版本,包括Ecplise ADT和Build-Tools 19.0.0。
我的目的是在各种Android平台上实现一些高计算图像算法,可能从API 8开始。为此,我在我的Ecplise项目中设置了对renderscript-v8
库的引用,将应用程序定位到API 19。
我有两个Android设备要测试,第一个是Android 4.3(API 18),第二个是Android 2.2(API 8)。我在运行这段代码时遇到了不同的异常,调用ScriptIntrinsicYuvToRGB(代码部分来自Executing ScriptIntrinsicYuvToRgb问题):
/* --------------
global vars */
private RenderScript rs;
private ScriptIntrinsicYuvToRGB rs_YUVtoRGB;
private Allocation rs_YUVtoRGB_in;
private Allocation rs_YUVtoRGB_out;
/* --------------
in constructor... */
this.rs = RenderScript.create(this.getContext());
this.rs_YUVtoRGB = ScriptIntrinsicYuvToRGB.create(this.rs, Element.U8_4(rs));
Type.Builder tb_in = new Type.Builder(this.rs, Element.createPixel(this.rs, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
tb_in.setX(prevWidth);
tb_in.setY(prevHeight);
tb_in.setMipmaps(false);
tb_in.setYuvFormat(this.camera.getParameters().getPreviewFormat());
this.rs_YUVtoRGB_in = Allocation.createTyped(this.rs, tb_in.create(), Allocation.USAGE_SCRIPT);
Type.Builder tb_out = new Type.Builder(this.rs, Element.RGBA_8888(this.rs));
tb_out.setX(prevWidth);
tb_out.setY(prevHeight);
tb_out.setMipmaps(false);
this.rs_YUVtoRGB_out = Allocation.createTyped (this.rs, tb_out.create(), Allocation.USAGE_SCRIPT);
/* --------------
launching the script... */
// byte[] raw... // a YUV image
this.rs_YUVtoRGB_in.copyFrom(raw);
this.rs_YUVtoRGB.setInput(this.rs_YUVtoRGB_in);
this.rs_YUVtoRGB.forEach(this.rs_YUVtoRGB_out);
int[] framePixels = new int[previewSize.width * previewSize.height];
this.rs_YUVtoRGB_out.copyTo(framePixels); // final RGB converted image
Eclipse设法编译它(它应该意味着库被很好地引用),但是......
Android 4.3失败:Type.Builder tb_in = new Type.Builder(this.rs, Element.createPixel(this.rs, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
Unsupported DataKind
11-24 11:17:57.685: E/AndroidRuntime(2494): FATAL EXCEPTION: main
11-24 11:17:57.685: E/AndroidRuntime(2494): android.renderscript.RSIllegalArgumentException: Unsupported DataKind
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.renderscript.Element.createPixel(Element.java:911)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.support.v8.renderscript.ElementThunker.createPixel(ElementThunker.java:224)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.support.v8.renderscript.Element.createPixel(Element.java:832)
11-24 11:17:57.685: E/AndroidRuntime(2494): at com.lag.appprj.CameraPreview.setupCamera(CameraPreview.java:167)
11-24 11:17:57.685: E/AndroidRuntime(2494): at com.lag.appprj.CameraPreview.surfaceCreated(CameraPreview.java:86)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.SurfaceView.updateWindow(SurfaceView.java:571)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.SurfaceView.access$000(SurfaceView.java:86)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:833)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1860)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
在Android 2.2上,它在初始阶段失败:Error loading RS jni library: java.lang.UnsatisfiedLinkError: Library RSSupport not found
11-24 11:45:45.329: E/AndroidRuntime(2048): FATAL EXCEPTION: main
11-24 11:45:45.329: E/AndroidRuntime(2048): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lag.appprj/com.lag.appprj.CaptureActivity}: android.support.v8.renderscript.RSRuntimeException: Error loading RS jni library: java.lang.UnsatisfiedLinkError: Library RSSupport not found
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.os.Looper.loop(Looper.java:123)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-24 11:45:45.329: E/AndroidRuntime(2048): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 11:45:45.329: E/AndroidRuntime(2048): at java.lang.reflect.Method.invoke(Method.java:521)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-24 11:45:45.329: E/AndroidRuntime(2048): at dalvik.system.NativeStart.main(Native Method)
11-24 11:45:45.329: E/AndroidRuntime(2048): Caused by: android.support.v8.renderscript.RSRuntimeException: Error loading RS jni library: java.lang.UnsatisfiedLinkError: Library RSSupport not found
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.support.v8.renderscript.RenderScript.create(RenderScript.java:945)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.support.v8.renderscript.RenderScript.create(RenderScript.java:982)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.support.v8.renderscript.RenderScript.create(RenderScript.java:968)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.lag.appprj.CameraPreview.<init>(CameraPreview.java:80)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.lag.appprj.CaptureActivity.onCreate(CaptureActivity.java:34)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
感谢您的帮助
答案 0 :(得分:5)
createPixel()的错误是ElementThunker.java中的实际错误。它缺少PIXEL_YUV的情况,因此最终返回null而不是相应的类型。我将在AOSP和未来的SDK版本中修复此问题。 (补丁在https://android-review.googlesource.com/70810)。
就库加载问题而言,我相信您的其他SO问题,您注意到您的Application.mk文件并非针对所有体系结构构建(因此不捆绑相应的共享库)。它在4.3上工作的原因是4.3自动拥有libRSSupport.so的副本(虽然它确实不应该)。较旧的设备显然没有.so的默认/ system / lib /副本,因此除非你的构建实际上用apk打包它,否则它们总是无法加载它。