android.renderscript.RSRuntimeException: Loading of ScriptC script failed. (android sdk build tools 23.0.1)

[亡魂溺海] 提交于 2020-04-30 14:27:19

问题


Trying to compile renderscript without using the support library. I'm using Android Studio with android sdk build tools 23.0.1 (I also have 20 and 23.0.0). Trying to compile it for Samsung galaxy s5 plus. (Android 5.0.2 API 21)

The inverse.rs file is located in: /src/main/rs/

In my 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 file:

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')
}

And this is my error log:

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:


Set targetSdkVersion to the supported level of your S5, as 23 will cause this to be only runnable on API level 23+ devices. We don't use minSdkVersion. We use your targetSdkVersion when compiling for RS.



来源:https://stackoverflow.com/questions/33241195/android-renderscript-rsruntimeexception-loading-of-scriptc-script-failed-andr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!