application exits after run.
i guss the problem lie in "System.loadLibrary(...)"

source code is as the following


/////////////////////////////////////////////////////////////////////////////
TestJNI.java
package com.test.hello;

/**
 * @author stavy
 *
 */
public class TestJNI {
        static {
                //System.out.println(System.getProperty("java.library.path"));
                try {
        System.loadLibrary("testjni");
    } catch (Exception e) {
        System.out.println("libtestjni.so load errer");
    }
  }

        public int test( ) {
                testjni();
                return 0;
        }

        private native int testjni();
}


/////////////////////////////////////////////////////////////////////////////
HelloAndriod.java
package com.test.hello;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;


public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        //setContentView(R.layout.main);
        TextView tv = new TextView(this);
        tv.setText("hello android!");
        setContentView(tv);

        TestJNI testjni = new TestJNI();
        testjni.test();
    }
}


/////////////////////////////////////////////////////////////////////////////
com_test_hello_TestJNI.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_test_hello_TestJNI */

#ifndef _Included_com_test_hello_TestJNI
#define _Included_com_test_hello_TestJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_test_hello_TestJNI
 * Method:    testjni
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_com_test_hello_TestJNI_testjni
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif


/////////////////////////////////////////////////////////////////////////////
testjni.c
#include "com_test_hello_TestJNI.h"
#include <stdio.h>


JNIEXPORT jint JNICALL Java_com_test_hello_TestJNI_testjni(JNIEnv
*jenv, jobject jobj)
{
        printf("hello testjni!\n");
        return 0;
}



/////////////////////////////////////////////////////////////////////////////
Makefile
INCPATH:= -I. -I/usr/local/jdk1.6.0_05/include -I/usr/local/
jdk1.6.0_05/include/linux
CC := /usr/local/arm-2007q3/bin/arm-none-linux-gnueabi-gcc
LN := /usr/local/arm-2007q3/bin/arm-none-linux-gnueabi-ld
LIBA := /usr/local/arm-2007q3/lib/gcc/arm-none-linux-gnueabi/4.2.1/
libgcc.a

TARGET := libtestjni.so

all: objdir $(TARGET)

obj/testjni.o : testjni.c
        $(CC) $(INCPATH) -fpic -c $< -o $@

obj/testjni.so.tmp : obj/testjni.o
        $(LN) -r -static -o $@ $< $(LIBA)

$(TARGET) : obj/testjni.so.tmp
        $(LN) -shared -Tarmelf_linux_eabi.xsc -o $@ $<

objdir:
        mkdir -p obj

clean:
        rm -f err $(TARGET) obj/*






--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to