led native的错误记录

1.是nostdlib 不是nostdio 敲错了 然后 文件的路径还21 不是9 之前写错了

arm-linux-gnueabi-gcc -shared -fPIC hello.c -o libnative.so 
-I /usr/lib/jvm/java-7-openjdk-amd64/include/ 
-I /home/linux//fspad-733/androidM/system/core/include/ 	
-nostdlib /home/linux/fspad-733/androidM/prebuilts/ndk/9/platforms/android-21/arch-arm/usr/lib/libc.so 
/home/linux/fspad-733/androidM/prebuilts/ndk/9/platforms/android-21/arch-arm/usr/lib/liblog.so

2.native里面的注册方法吗写错了 要跟上层一样 源码

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 



#define LOG_TAG "myled"//重复定义 要换一个
#define logtag "myled"
int fd;
jint c_close(JNIEnv *env,jobject obj)
{
	close(fd);
	return 123;
}

jint c_open(JNIEnv *env,jobject obj)
{
	fd = open("/dev/myled",O_RDWR);
	if(fd == -1){
		perror("open /dev/myled error");
		return -1;
	}
	
	return 123;
}

jint c_ioctl(JNIEnv *env,jobject obj,jint a,jint b)
{
	
	ioctl(fd,a,b);
	__android_log_print(ANDROID_LOG_INFO,LOG_TAG,"led ioctl");
	return 123;
}

JNINativeMethod methods[] = {
	[0]={
	//	.name = "jaca_open", 敲错了·要修改
        .name = "java_open",
		.signature = "()I",
		.fnPtr = (void *)c_open,
	},
	[1]={
		.name = "java_close",
		.signature = "()I",
		.fnPtr = (void *)c_close,
	},
	[2]={
		.name = "java_ioctl",
		.signature = "(II)I",
		.fnPtr = (void *)c_ioctl,
	},
};


JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *jvm, void *reserved)
{
    JNIEnv *env;
    jclass cls;
	
   
    if((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_4)) {
        return JNI_ERR; /* JNI version not supported */
    }
	
//    cls = (*env)->FindClass(env, "LedService");  //包名不对 
     cls = (*env)->FindClass(env, "com/xxx/lesservice/LedService");
    if(cls == NULL) {
        return JNI_ERR;
    }
	
   (*env)->RegisterNatives(env, cls, methods, 3);
    return JNI_VERSION_1_4;
}

 

你可能感兴趣的:(led native的错误记录)