android.renderscript.RSRuntimeException:加载ScriptC脚本失败。 (android sdk build tools 23.0.1)

时间:2015-10-20 15:51:30

标签: java android renderscript

尝试在不使用支持库的情况下编译renderscript。 我正在使用Android Studio和android sdk构建工具23.0.1(我也有20和23.0.0)。试图为三星galaxy s5 plus编译它。 (Android 5.0.2 API 21)

inverse.rs文件位于: / SRC /主/ RS /

在我的mainactivity.java中:

RenderScript rs = RenderScript.create(this.getApplicationContext());
Allocation allocIn;
allocIn = Allocation.createFromBitmap(rs, bitmap);
Allocation allocOut = Allocation.createTyped(rs, allocIn.getType());
ScriptC_inverse inverse = new ScriptC_inverse(rs); //crashes on this line

inverse.forEach_invert(allocIn,allocOut);
rs.finish();
allocOut.copyTo(bitmap);

allocOut.destroy();
allocIn.destroy();
rs.destroy();

inverse.rs:

#pragma version(1)
#pragma rs java_package_name(com.example.dries.myocrtest)

uchar4 __attribute__((kernel)) invert(uchar4 in) {
  uchar4 out = in;
  out.r = 255 - in.r;
  out.g = 255 - in.g;
  out.b = 255 - in.b;
  return out;
}

build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.dries.myocrtest"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        renderscriptTargetApi 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile project(':tesstwo')
    compile project(':fileExplorer')
}

这是我的错误日志:

12384-12384/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.dries.myocrtest, PID: 12384
    android.renderscript.RSRuntimeException: Loading of ScriptC script failed.
            at android.renderscript.ScriptC.<init>(ScriptC.java:82)
            at com.example.dries.myocrtest.ScriptC_inverse.<init>(ScriptC_inverse.java:34)
            at com.example.dries.myocrtest.MainActivity.ocr(MainActivity.java:126)
            at com.example.dries.myocrtest.MainActivity.onOptionsItemSelected(MainActivity.java:86)
            at android.app.Activity.onMenuItemSelected(Activity.java:3030)
            at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:325)
            at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:147)
            at android.support.v7.internal.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
            at android.support.v7.app.AppCompatDelegateImplV7.onMenuItemSelected(AppCompatDelegateImplV7.java:609)
            at android.support.v7.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
            at android.support.v7.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:153)
            at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
            at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:948)
            at android.support.v7.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:191)
            at android.widget.AdapterView.performItemClick(AdapterView.java:334)
            at android.widget.AbsListView.performItemClick(AbsListView.java:1531)
            at android.widget.AbsListView$PerformClick.run(AbsListView.java:3667)
            at android.widget.AbsListView$3.run(AbsListView.java:5585)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:6066)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

1 个答案:

答案 0 :(得分:0)

将targetSdkVersion设置为S5支持的级别,因为23将使其仅在API级别23+设备上运行。我们不使用minSdkVersion。我们在编译RS时使用targetSdkVersion。