title: Loading of ScriptC script failed / cannot load library - Renderscript Android
body: <p>I get the following error message:</p>
  
  <blockquote>
    <p>01-19 23:31:16.436: E/RenderScript(30603): Unable to open shared library (/data/data/com.example.android.rs.hellocompute//lib/librs.mono.so): Cannot load library: reloc_library[1313]:  1222 cannot locate '_Z9rsForEach9rs_script13rs_allocationS0_'...</p>
    
    <p>01-19 23:31:16.436: E/RenderScript(30603): Unable to open system shared library (/system/lib/librs.mono.so): (null)</p>
    
    <p>01-19 23:31:16.444: D/AndroidRuntime(30603): Shutting down VM</p>
    
    <p>01-19 23:31:16.444: W/dalvikvm(30603): threadid=1: thread exiting with uncaught exception (group=0x40018560)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603): FATAL EXCEPTION: main</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.rs.hellocompute/com.example.android.rs.hellocompute.HelloCompute}: android.support.v8.renderscript.RSRuntimeException: Loading of ScriptC script failed.</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at android.app.ActivityThread.access$1500(ActivityThread.java:124)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at android.os.Handler.dispatchMessage(Handler.java:99)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at android.os.Looper.loop(Looper.java:130)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at android.app.ActivityThread.main(ActivityThread.java:3806)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at java.lang.reflect.Method.invokeNative(Native Method)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at java.lang.reflect.Method.invoke(Method.java:507)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at dalvik.system.NativeStart.main(Native Method)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603): Caused by: android.support.v8.renderscript.RSRuntimeException: Loading of ScriptC script failed.</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at android.support.v8.renderscript.ScriptC.(ScriptC.java:69)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at com.example.android.rs.hellocompute.ScriptC_mono.(ScriptC_mono.java:41)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at com.example.android.rs.hellocompute.HelloCompute.createScript(HelloCompute.java:64)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at com.example.android.rs.hellocompute.HelloCompute.onCreate(HelloCompute.java:49)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)</p>
    
    <p>01-19 23:31:16.585: E/AndroidRuntime(30603):   ... 11 more</p>
  </blockquote>
  
  <p>I guess that this message is created by <code>int id</code> being 0 in ScriptC_mono.java although it should be <code>R.raw.mono</code>, but I cannot find out why. Here are my *.rs and MainActivity.java files:</p>
  
  <p>MainActivity:</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.graphics.BitmapFactory;
  import android.graphics.Bitmap;
  import android.support.v8.renderscript.*;
  import android.widget.ImageView;
  
  public class HelloCompute extends Activity {
  private Bitmap mBitmapIn;
  private Bitmap mBitmapOut;
  
  private RenderScript mRS;
  private Allocation mInAllocation;
  private Allocation mOutAllocation;
  private ScriptC_mono mScript;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      mBitmapIn = loadBitmap(R.drawable.data);
      mBitmapOut = Bitmap.createBitmap(mBitmapIn.getWidth(), mBitmapIn.getHeight(),
                                       mBitmapIn.getConfig());
  
      ImageView in = (ImageView) findViewById(R.id.displayin);
      in.setImageBitmap(mBitmapIn);
  
      ImageView out = (ImageView) findViewById(R.id.displayout);
  
      createScript();
      out.setImageBitmap(mBitmapOut);
  }
  
  
  private void createScript() {
      mRS = RenderScript.create(this);
  
      mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
                                                  Allocation.MipmapControl.MIPMAP_NONE,
                                                  Allocation.USAGE_SCRIPT);
      mOutAllocation = Allocation.createFromBitmap(mRS, mBitmapOut,
                                                   Allocation.MipmapControl.MIPMAP_NONE,
                                                   Allocation.USAGE_SCRIPT);
  
      mScript = new ScriptC_mono(mRS, getResources(), R.raw.mono);
  
      mScript.forEach_root(mInAllocation, mOutAllocation);
      mOutAllocation.copyTo(mBitmapOut);
  
      mScript.destroy();
  }
  
  private Bitmap loadBitmap(int resource) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inPreferredConfig = Bitmap.Config.ARGB_8888;
      return BitmapFactory.decodeResource(getResources(), resource, options);
  }}
  </code></pre>
  
  <p>Mono.rs:</p>
  
  <pre><code>#pragma version(1)
  #pragma rs java_package_name(com.android.example.hellocompute)
  
  rs_allocation gIn;
  rs_allocation gOut;
  rs_script gScript;
  
  const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
  
  void root(const uchar4 *v_in, uchar4 *v_out, const void *usrData, uint32_t x, uint32_t y) {
  float4 f4 = rsUnpackColor8888(*v_in);
  
  float3 mono = dot(f4.rgb, gMonoMult);
  *v_out = rsPackColorTo8888(mono);
  }
  
  void filter() {
  rsForEach(gScript, gIn, gOut, 0);
  }
  </code></pre>