Click here to Skip to main content
11,802,762 members (69,330 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C Linux
Hi Dear,
I am creting an android application over JNI.i am created some files in java likes

package com.allwikan.runkey;

import com.allwikan.runkey.MainActivity;
import com.allwikan.runkey.R;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
	 private LinearLayout linearLayout;
		private   InputMethodManager inputMethodManager;
		 private Keyboard lkeyboard;
    public void onCreate(Bundle savedInstanceState) {
        lkeyboard=new Keyboard(MainActivity.this);
        Button button=(Button)findViewById(;
     button.setOnClickListener(new OnClickListener() {
	public void onClick(View v) {
		// TODO Auto-generated method stub
		// inputMethodManager.toggleSoftInputFromWindow(linearLayout.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(, menu);
        return true;

package com.allwikan.runkey;
import android.R.bool;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
public class Keyboard {

     static {
    Context mContext;
     public Keyboard(Context mContext){
           this.mContext = mContext;
      public  void  getSystemService(bool makevisible){
         if(makevisible != null){
            InputMethodManager m = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
            m.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
             InputMethodManager m = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
            m.toggleSoftInput(0, 0);
      public native void  openKeyBoard();

It display the keyboard in emuletor.but my requirement call by c over jni then we created two file .likes


/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_allwikan_runkey_Keyboard */
#ifndef _Included_com_allwikan_runkey_Keyboard
#define _Included_com_allwikan_runkey_Keyboard
#ifdef __cplusplus
extern "C" {
 * Class:     com_allwikan_runkey_Keyboard
 * Method:    openKeyBoard
 * Signature: ()V
JNIEXPORT void JNICALL Java_com_allwikan_runkey_Keyboard_openKeyBoard
  (JNIEnv *, jobject);
#ifdef __cplusplus


#include <com_allwikan_runkey_keyboard.h>
#include "stdio.h"

#include "jni.h"

#define  LOG_TAG    "com_allwikan_runkeyboard_Keyboard"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
int main()

	JNIEnv *env;
	     JavaVM *jvm;
	     jint res;
	     jclass cls;
	     jmethodID mid;
	     jstring jstr;
	     jclass stringClass;
	     jobjectArray args;

	 #ifdef JNI_VERSION_1_2
	     JavaVMInitArgs vm_args;
	     JavaVMOption options[1];
	   //  options[0].optionString = ("-Djava.class.path=") USER_CLASSPATH;
	     vm_args.version = 0x00010002;
	     vm_args.options = options;
	     vm_args.nOptions = 1;
	     vm_args.ignoreUnrecognized = JNI_TRUE;
	     /* Create the Java VM */
	     res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
	     JDK1_1InitArgs vm_args;
	     char classpath[1024];
	     vm_args.version = 0x00010001;
	     /* Append USER_CLASSPATH to the default system class path */
	     sprintf(classpath, "%s%c%s",
	             vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
	     vm_args.classpath = classpath;
	     /* Create the Java VM */
	     res = JNI_CreateJavaVM(&jvm, &env, &vm_args);
	 #endif /* JNI_VERSION_1_2 */

	     if (res < 0) {
	         fprintf(stderr, "Can't create Java VM\n");
	     cls = (*env)->FindClass(env, "Prog");
	     if (cls == NULL) {
	         goto destroy;
	     mid = (*env)->GetStaticMethodID(env, cls, "main",
	     if (mid == NULL) {
	         goto destroy;
	     jstr = (*env)->NewStringUTF(env, " from C!");
	     if (jstr == NULL) {
	         goto destroy;
	     stringClass = (*env)->FindClass(env, "java/lang/String");
	     args = (*env)->NewObjectArray(env, 1, stringClass, jstr);
	     if (args == NULL) {
	         goto destroy;
	     (*env)->CallStaticVoidMethod(env, cls, mid, args);
	     if ((*env)->ExceptionOccurred(env)) {


When compile this code by ndk-build commond its give error

/home/allwikan/Documents/eclipse_workspace/RunKey/jni/com_allwikan_runkey_Keyboard.c:33: undefined reference to `JNI_CreateJavaVM'
collect2: ld returned 1 exit status

Please help me.
(1)How to resolve this error
(2)how to keyboard display in emulator
(3)which function used in c for display keyboard.

Thanks ...

I have also two file like

LOCAL_PATH :=$(call my-dir)
include $(call all-subdir-makefiles)

include $(CLEAR_VARS)

LOCAL_LDLIBS := -llog -ldl
LOCAL_MODULE := com_allwikan_runkey_Keyboard
LOCAL_SRC_FILES := com_allwikan_runkey_Keyboard.c
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog


APP_ABI :=all

then where am i wrong.

please help me....
Posted 14-Sep-12 22:27pm
Edited 15-Sep-12 3:28am
Richard MacCutchan at 15-Sep-12 11:22am
Where is JNI_CreateJavaVM() defined? Probably in some JNI system library which you have not added to your build parameters, as I explained earlier.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You are missing a library or LIB directive in your project, so the linker cannot resolve the reference. However, I am not sure that you can directly load a C executable into an Android system.
trilok 2 at 15-Sep-12 12:37pm
Thanks for giving reply
but i have also file where BUILD_SHARED_LIBRARY so the code is compiling but gives on error
undefined reference to `JNI_CreateJavaVM' so how to resoolve it.

Richard MacCutchan at 15-Sep-12 12:51pm
How many more times do I need to explain that you are missing a library in your build, which contains the definition for the missing reference? If you do not know how to compile and link a program then take a look at the documentation, starting with the man pages for make and ld.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 KrunalRohit 366
1 OriginalGriff 365
2 F-ES Sitecore 295
3 CPallini 270
4 Sergey Alexandrovich Kryukov 239
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,695
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 15 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100