Problems using renderscriptSupportModeEnabled true

1

I'm using a library to use the Blur effect in my DialogFragment and everything works perfect, but in gradle I get a warning

  

all com.android.support libraries must use the exact same version specification (mixing versions can lead to rutime crashes). Found version 25.3.1, 25.0.2. Examples include com.android.support:animated-vector-drawable:25.3.1 and com.android.support:renderscript:25.0.2

This warning only comes up if I activate renderscriptSupportModeEnabled by putting true if I put it false I do not receive the warning. But I need it to use the library that I mentioned above.

gradle :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "prueba.dos"
        minSdkVersion 19
        targetSdkVersion 25
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'com.google.firebase:firebase-core:10.0.0'
    compile 'com.google.firebase:firebase-messaging:10.0.0'
    compile 'com.google.firebase:firebase-database:10.0.0'
    compile 'com.firebaseui:firebase-ui-database:0.6.2'
    compile 'fr.tvbarthel.blurdialogfragment:lib:2.2.0'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

The library in particular is BlurDialogFragment .

I know what you think a while ago question with a similar problem, but I can not solve it and I do not know whether to leave it at that. Will I have problems in the future?

Thank you!

EDITO1:

I've been doing some research and the only class that uses renderscriptSupportModeEnabled true is RenderScriptBlurHelper (From the library I mentioned)

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.RSRuntimeException;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import android.util.Log;

/**
 * Simple helper used to blur a bitmap thanks to render script.
 */
final class RenderScriptBlurHelper {

    /**
     * Log cat
     */
    private static final String TAG = RenderScriptBlurHelper.class.getSimpleName();

    /**
     * Non instantiable class.
     */
    private RenderScriptBlurHelper() {

    }

    /**
     * blur a given bitmap
     *
     * @param sentBitmap       bitmap to blur
     * @param radius           blur radius
     * @param canReuseInBitmap true if bitmap must be reused without blur
     * @param context          used by RenderScript, can be null if RenderScript disabled
     * @return blurred bitmap
     */
    public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap, Context context) {
        Bitmap bitmap;

        if (canReuseInBitmap) {
            bitmap = sentBitmap;
        } else {
            bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
        }

        if (bitmap.getConfig() == Bitmap.Config.RGB_565) {
            // RenderScript hates RGB_565 so we convert it to ARGB_8888
            // (see http://stackoverflow.com/questions/21563299/
            // defect-of-image-with-scriptintrinsicblur-from-support-library)
            bitmap = convertRGB565toARGB888(bitmap);
        }

        try {
            final RenderScript rs = RenderScript.create(context);
            final Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
                    Allocation.USAGE_SCRIPT);
            final Allocation output = Allocation.createTyped(rs, input.getType());
            final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
            script.setRadius(radius);
            script.setInput(input);
            script.forEach(output);
            output.copyTo(bitmap);
            return bitmap;
        } catch (RSRuntimeException e) {
            Log.e(TAG, "RenderScript known error : https://code.google.com/p/android/issues/detail?id=71347 "
                    + "continue with the FastBlur approach.");
        }

        return null;
    }

    private static Bitmap convertRGB565toARGB888(Bitmap bitmap) {
        return bitmap.copy(Bitmap.Config.ARGB_8888, true);
    }
}

And I've tried eliminating this:

 try {
            final RenderScript rs = RenderScript.create(context);
            final Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
                    Allocation.USAGE_SCRIPT);
            final Allocation output = Allocation.createTyped(rs, input.getType());
            final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
            script.setRadius(radius);
            script.setInput(input);
            script.forEach(output);
            output.copyTo(bitmap);
            return bitmap;
        } catch (RSRuntimeException e) {
            Log.e(TAG, "RenderScript known error : https://code.google.com/p/android/issues/detail?id=71347 "
                    + "continue with the FastBlur approach.");
        }

And I do not need to activate it anymore, the Blur effect works perfectly, but I do not know how much the part of the code that I have deleted influences. Any ideas?

    
asked by UserNameYo 29.05.2017 в 15:24
source

2 answers

1

If you define compileSdkVersion 25 you should have similar versions in the libraries, if they are different, suggest changing them to avoid problems.

  

all com.android.support libraries must use the exact same version   specification (mixing versions can lead to rutime crashes). Found   version 25.3.1, 25.0.2. Examples incliude   com.android.support:animated-vector-drawable:25.3.1 and   com.android.support:renderscript:25.0.2

To know which is the latest version and configure, place the mouse pointer over the dependency and it will tell you what is the latest version:

If you are using:

renderscriptSupportModeEnabled true

you use the classes:

import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RSRuntimeException;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;

But you can not use the activated mode, use the normal classes:

import android.graphics.Bitmap;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
    
answered by 29.05.2017 / 16:57
source
1

You should not have any problem. I mean, even though it shows up in red, it's not a problem, it's more, it lets you compile and execute. What he is telling you is that there is some library out there with a version of something smaller than what you have in your gradle files and that they should have all the same.

Possibly the library you use for the blur effect is pulling support or some other google and has a lower version than you have in your Gradle file.

As I have already told you, do not worry about it, it is true that it is a nuisance to see that red line there but if you look at it you should let it run.

    
answered by 29.05.2017 в 15:35