DevGuy
DevGuy

Reputation: 636

ndk-build not compiling the lib.so files

im building native code for android from command line via cd <project> ndk-build but when i run it it outputs nothing can be done for 'all' im using code from HelloJni sample, and if i import the the sample and compile it everything works fine.

activity

public class MainActivity extends Activity 
{
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        Log.i("DEBUG", stringFromJNI());
        setContentView(new MySurfaceView(this));
    }

    public native String stringFromJNI();

    static
    {
        System.loadLibrary("nativemain");
    }
}

nativemain.c

#include <string.h>
#include <jni.h>

jstring Java_com_ndktest2_MainActivity_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
{
    return (*env)->NewStringUTF(env, "Hello from JNI !");
}

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := nativemain
LOCAL_SRC_FILES := nativemain.c

include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_ABI := armeabi

Thank you so much for you guys and gals help!!

UPDATE 1: i refreshed the project and ran ndk-build again and work, but i received a UnsatisfiedLinkError exception on run time. Im using BlueStack as my emulator.

enter image description here

Upvotes: 1

Views: 1335

Answers (2)

Rick77
Rick77

Reputation: 3221

Try removing the "Application.mk" as it's not required for single-ndk-module applications (and the hello-jni doesn't have one)

Upvotes: 1

Rick77
Rick77

Reputation: 3221

Try putting a

JNIEXPORT

in front of your

Java_com_ndktest2_MainActivity_stringFromJNI

declaration.

Also the following SO questions might be related to your problem:

Android-NDK “java.lang.UnsatisfiedLinkError”

java.lang.UnsatisfiedLinkError

Hope this helps

Upvotes: 2

Related Questions