sparrow007 / BlurImage

This Android Project help you to make your image blur in fastest way
Apache License 2.0
185 stars 34 forks source link

So file error on multiple devices #3

Open rohankandwal opened 5 years ago

rohankandwal commented 5 years ago

Caused by androidx.renderscript.RSRuntimeException: Error loading RS jni library: java.lang.UnsatisfiedLinkError: JNI_ERR returned from JNI_OnLoad in "/data/app/xxxx-1/lib/arm64/librsjni_androidx.so" Support lib API: 2301 at androidx.renderscript.RenderScript.internalCreate(RenderScript.java:1414) at androidx.renderscript.RenderScript.create(RenderScript.java:1599) at androidx.renderscript.RenderScript.create(RenderScript.java:1549) at androidx.renderscript.RenderScript.create(RenderScript.java:1525) at androidx.renderscript.RenderScript.create(RenderScript.java:1512) at com.jackandphantom.blurimage.BlurImage.blur(BlurImage.java:53) at com.jackandphantom.blurimage.BlurImage$AsyncBlurImage.doInBackground(BlurImage.java:155) at com.jackandphantom.blurimage.BlurImage$AsyncBlurImage.doInBackground(BlurImage.java:146) at android.os.AsyncTask$2.call(AsyncTask.java:292) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818)

sparrow007 commented 5 years ago

@rohankandwal thanks for Log cat i will resolve it as soon as possible

sparrow007 commented 5 years ago

@rohankandwal if you want to take this issue you can feel free to contribute.

rohankandwal commented 5 years ago

@sparrow007 Not very expert on RenderScript, but create and used the following class, which never caused any crashes so far. The app is already live, still didn't get one.

public class BlurBuilder {
    private static final float BITMAP_SCALE = 0.2f;
    private static final float BLUR_RADIUS = 7.5f;

    public static Bitmap blur(View v) {
        return blur(v.getContext(), getScreenshot(v));
    }

    public static Bitmap blur(Context ctx, Bitmap image) {
        int width = Math.round(image.getWidth() * BITMAP_SCALE);
        int height = Math.round(image.getHeight() * BITMAP_SCALE);

         Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
        Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

        RenderScript rs = RenderScript.create(ctx);
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(BLUR_RADIUS);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);

        return outputBitmap;
    }

    private static Bitmap getScreenshot(View v) {
        Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(b);
        v.draw(c);
        return b;
    }
}

Let me know if above code makes any sense to you and it can be of some help.

Jorgesys commented 5 years ago

@rohankandwal apparently the error ocurrs in this line:

RenderScript rs = RenderScript.create(ctx);

but only in apps that are already using "androidx" and with OS 5.0 and 5.1 apparently.

fmaxx commented 5 years ago

I've fixed up that issue to change: buildToolsVersion '29.0.2' (was 28.0.3)

rex50 commented 3 years ago

I was getting same error in only release builds.

I've added below lines in my Proguard file and the issue got solved

#For RenderScript
-keepclasseswithmembernames class * {
native <methods>;
}
-keep class androidx.renderscript.** { *; }