错误Rendercript Android Studio 2.0

时间:2016-04-08 04:44:23

标签: android android-studio-2.0 android-renderscript

今天,我收到了Android Studio 2.0版的最新更新。更新完成后,我构建应用程序但在构建gradle中遇到错误消息

Error:Renderscript support mode is not currently supported with renderscript target 21+

我已经通过替换

进行搜索并找到了解决方案
renderscriptTargetApi 21
renderscriptSupportModeEnabled true

renderscriptTargetApi 20
renderscriptSupportModeEnabled true

Build是成功的,但是当我运行app时,app崩溃了show logcat:

E/AndroidRuntime: FATAL EXCEPTION: main
android.support.v8.renderscript.RSRuntimeException: Error loading RS jni library: java.lang.UnsatisfiedLinkError: unknown failure Support lib API: 2301
at android.support.v8.renderscript.RenderScript.internalCreate(RenderScript.java:1358)
at android.support.v8.renderscript.RenderScript.create(RenderScript.java:1529)
at android.support.v8.renderscript.RenderScript.create(RenderScript.java:1479)
at android.support.v8.renderscript.RenderScript.create(RenderScript.java:1455)
at android.support.v8.renderscript.RenderScript.create(RenderScript.java:1442)
at com.tadev.musicplayer.utils.design.blurry.BlurImageUtils.blurRenderScript(BlurImageUtils.java:25)
at com.tadev.musicplayer.ui.activities.fragments.MainMusicPlayFragment$5.onResourceReady(MainMusicPlayFragment.java:313)
at com.tadev.musicplayer.ui.activities.fragments.MainMusicPlayFragment$5.onResourceReady(MainMusicPlayFragment.java:310)
at com.bumptech.glide.request.GenericRequest.onResourceReady(GenericRequest.java:525)
at com.bumptech.glide.request.GenericRequest.onResourceReady(GenericRequest.java:507)
at com.bumptech.glide.load.engine.EngineJob.handleResultOnMainThread(EngineJob.java:158)
at com.bumptech.glide.load.engine.EngineJob.access$100(EngineJob.java:22)
at com.bumptech.glide.load.engine.EngineJob$MainThreadCallback.handleMessage(EngineJob.java:202)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)

代码处理模糊:

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;

/**
 * Created by Iris Louis on 04/04/2016.
 */
public class BlurImageUtils {
    public static Bitmap blurRenderScript(Context context, Bitmap smallBitmap, int radius) {

        try {
            smallBitmap = RGB565toARGB888(smallBitmap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Bitmap bitmap = Bitmap.createBitmap(
                smallBitmap.getWidth(), smallBitmap.getHeight(),
                Bitmap.Config.ARGB_8888);

        RenderScript renderScript = RenderScript.create(context);

        Allocation blurInput = Allocation.createFromBitmap(renderScript, smallBitmap);
        Allocation blurOutput = Allocation.createFromBitmap(renderScript, bitmap);

        ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(renderScript,
                Element.U8_4(renderScript));
        blur.setInput(blurInput);
        blur.setRadius(radius); // radius must be 0 < r <= 25
        blur.forEach(blurOutput);

        blurOutput.copyTo(bitmap);
//        renderScript.destroy();

        return bitmap;

    }

    private static Bitmap RGB565toARGB888(Bitmap img) throws Exception {
        int numPixels = img.getWidth() * img.getHeight();
        int[] pixels = new int[numPixels];

        //Get JPEG pixels.  Each int is the color values for one pixel.
        img.getPixels(pixels, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());

        //Create a Bitmap of the appropriate format.
        Bitmap result = Bitmap.createBitmap(img.getWidth(), img.getHeight(), Bitmap.Config.ARGB_8888);

        //Set RGB pixels.
        result.setPixels(pixels, 0, result.getWidth(), 0, 0, result.getWidth(), result.getHeight());
        return result;
    }
}

将IDE更新为2.0时出现意外情况!

Plz,给我一些解决方案。谢谢大家!!!

0 个答案:

没有答案