2016-06-24 2 views
0

일부 장치에서 테스트 할 때 나는 비트 맵에 흐림 효과를 만들기 위해 안드로이드 지원 RenderScript를 사용하려고하지만, 한 (API 22) 내 응용 프로그램 충돌 두 컨텍스트가 없습니다 다른 SDK 버전 "오류가 발생했습니다.RenderScript : "이 문맥과 다른 지원 lib 디렉토리에 SDK 버전

아무도이 전에 물었다 것을 매우 이상했다!

build.gradle

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    defaultConfig { 
     minSdkVersion 16 
     targetSdkVersion 23 
     versionCode 1 
     renderscriptTargetApi 18 
     renderscriptSupportModeEnabled true 
    } 
} 
dependencies { 
compile 'com.android.support:appcompat-v7:23.2.1' 
compile 'com.android.support:support-vector-drawable:23.2.1' 
compile 'com.android.support:support-annotations:23.2.1' 
compile 'com.android.support:support-v13:23.2.1' 
compile 'com.android.support:support-v4:23.2.1' 
compile 'com.android.support:design:23.2.1' 
compile 'com.android.support:palette-v7:23.2.1' 
compile 'com.android.support:recyclerview-v7:23.2.1' 
compile 'com.android.support:cardview-v7:23.2.1' 

MainActivity.java

이 작업을 수행하려고 할 때 충돌
public Bitmap blurImage(Bitmap image) { 
    final float BITMAP_SCALE = 0.4f; 
    final float BLUR_RADIUS = 7.5f; 
    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(context); 
    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; 
} 

:

RenderScript rs = RenderScript.create(context); 

기능 및 비트 맵은 모두 동일한 활동에 , 내 질문은 : 두 가지 다른 상황을 일으키는 것은 무엇입니까?

답변

2

은 수입을 확인하십시오. 대부분 한 파일에 android.renderscript.RenderScript을 가져오고 다른 파일에는 android.support.v8.renderscript.RenderScript을 가져올 가능성이 큽니다. 컨텍스트는 앱 컨텍스트에 연결되어 있으므로 애플리케이션에 둘 중 하나만있을 수 있습니다. 관련 메모에

, 위의 방법은 정확히 내가 코드를 하나 개의 장소에 있도록하는 유틸리티 헬퍼 클래스를 만드는 제안 두 파일 사이의 동일합니다.

+0

예, 당신은 옳았다! 하지만 지원 모드를 비활성화해야했습니다. 또한 minSdk를 17으로 변경했습니다. android.support.v8.renderscript.RenderScript가 앱을 중단시키고 있습니다. –