Native functions throw UnsatisfiedLinkError in custom view, despite working in main activity

Posted by Mark Ingram on Stack Overflow See other posts from Stack Overflow or by Mark Ingram
Published on 2010-12-21T12:09:17Z Indexed on 2010/12/22 3:54 UTC
Read the original article Hit count: 285

Filed under:
|
|
|
|

For some reason I can only call native functions from my main activity and not any custom views that I've created. Here is an example file (I followed a tutorial, but renamed the classes http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/)

See the usage of the native function "getNewString".

package com.example.native;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.View;

public class NativeTestActivity extends Activity
{   
    static
    {
        System.loadLibrary("nativeTest");
    }

    private native String getNewString();

    @Override public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);        
        this.setContentView(new BitmapView(this));

        String hello = getNewString(); // This line works fine
        new AlertDialog.Builder(this).setMessage(hello).show();
    }
}

class BitmapView extends View
{
    static
    {
        System.loadLibrary("nativeTest");
    }

    private native String getNewString();

    public BitmapView(Context context)
    {
        super(context);

        String hello = getNewString(); // This line throws the UnsatisfiedLinkError
        new AlertDialog.Builder(this.getContext()).setMessage(hello).show();
    }
}

How can I call native functions in my custom views?

I've built the application as an Android 2.2 app. I'm running the application on my HTC Desire. I have the latest SDK (9) and latest NDK (r5).

© Stack Overflow or respective owner

Related posts about java

Related posts about c++