当前位置:编程学习 > wap >>

jni编译错误:Native registration unable to find class

跟着老罗的那个从内核驱动到上层的开发一直做到为上层提供jni接口这,就这在出了问题,哪位高手能帮个忙,告诉我问题出在哪里?都以及2天了

03-02 22:35:34.677: I/Zygote(171): ...preloaded 379 resources in 3944ms.
03-02 22:35:34.757: D/dalvikvm(171): GC_EXPLICIT freed 20K, 2% free 6461K/6531K, paused 3ms+3ms
03-02 22:35:34.807: I/Zygote(171): ...preloaded 31 resources in 123ms.
03-02 22:35:34.857: D/dalvikvm(171): GC_EXPLICIT freed 14K, 2% free 6463K/6531K, paused 5ms+4ms
03-02 22:35:34.917: D/dalvikvm(171): GC_EXPLICIT freed 6K, 2% free 6457K/6531K, paused 3ms+3ms
03-02 22:35:34.977: D/dalvikvm(171): GC_EXPLICIT freed <1K, 2% free 6457K/6531K, paused 3ms+4ms
03-02 22:35:34.997: I/dalvikvm(171): System server process 184 has been created
03-02 22:35:35.007: I/Zygote(171): Accepting command socket connections
03-02 22:35:35.238: E/BatteryService(184): usbOnlinePath not found
03-02 22:35:35.238: E/BatteryService(184): batteryVoltagePath not found
03-02 22:35:35.238: E/BatteryService(184): batteryTemperaturePath not found
03-02 22:35:35.248: E/UsbHostManagerJNI(184): hellousbhost
03-02 22:35:35.258: E/(184): onhello
03-02 22:35:35.258: I/HelloService(184): hellpeng
03-02 22:35:35.258: E/JNIHelp(184): Native registration unable to find class 'com/android/server/HelloService', aborting
03-02 22:35:35.258: A/libc(184): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)
03-02 22:35:35.767: I/DEBUG(33): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

这个是错误信息


我的jni是这样写的:


#define LOG_TAG "HelloService"
#include "jni.h"
#include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h"
#include "utils/Vector.h"
#include <utils/misc.h>
#include <utils/Log.h>
#include <hardware/hardware.h>
#include <hardware/hello.h>
#include <stdio.h>

namespace android
{
        /*在硬件抽象层中定义的硬件访问结构体,参考<hardware/hello.h>*/
        struct hello_device_t* hello_device = NULL;
        /*通过硬件抽象层定义的硬件访问接口设置硬件寄存器val的值*/
        static void hello_setVal(JNIEnv* env, jobject clazz, jint value) {
                int val = value;
                LOGI("Hello JNI: set value %d to device.", val);
                if(!hello_device) {
                        LOGI("Hello JNI: device is not open.");
                        return;
                }
                
                hello_device->set_val(hello_device, val);
        }
        /*通过硬件抽象层定义的硬件访问接口读取硬件寄存器val的值*/
        static jint hello_getVal(JNIEnv* env, jobject clazz) {
                int val = 0;
                if(!hello_device) {
                        LOGI("Hello JNI: device is not open.");
                        return val;
                }
                hello_device->get_val(hello_device, &val);
                
                LOGI("Hello JNI: get value %d from device.", val);
        
                return val;
        }
        /*通过硬件抽象层定义的硬件模块打开接口打开硬件设备*/
        static inline int hello_device_open(const hw_module_t* module, struct hello_device_t** device) {
                return module->methods->open(module, HELLO_HARDWARE_MODULE_ID, (struct hw_device_t**)device);
        }
        /*通过硬件模块ID来加载指定的硬件抽象层模块并打开硬件*/
        static jboolean hello_init(JNIEnv* env, jclass clazz) {
                hello_module_t* module;
                
                LOGI("Hello JNI: initializing......");
                if(hw_get_module(HELLO_HARDWARE_MODULE_ID, (const struct hw_module_t**)&module) == 0) {
                        LOGI("Hello JNI: hello Stub found.");
                        if(hello_device_open(&(module->common), &hello_device) == 0) {
                                LOGI("Hello JNI: hello device is open.");
                                return 0;
                        }
                        LOGE("Hello JNI: failed to open hello device.");
                        return -1;
                }
                LOGE("Hello JNI: failed to get hello stub module.");
                return -1;                
        }
        /*JNI方法表*/
        static const JNINativeMethod method_table[] = {
                {"init_native", "()Z", (void*)hello_init},
                {"setVal_native", "(I)V", (void*)hello_setVal},
                {"getVal_native", "()I", (void*)hello_getVal},
        };
        /*注册JNI方法*/
        int register_android_server_HelloService(JNIEnv *env) {
                LOGI("hellpeng");
                    return jniRegisterNativeMethods(env, "com/android/server/HelloService", method_table, NELEM(method_table));
        }
};


然后在onload.cpp里这样加的

/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "JNIHelp.h"
#include "jni.h"
#include "utils/Log.h"
#include "utils/misc.h"

namespace android {
int register_android_server_AlarmManagerService(JNIEnv* env);
int register_android_server_BatteryService(JNIEnv* env);
int register_android_server_InputApplicationHandle(JNIEnv* env);
int register_android_server_InputWindowHandle(JNIEnv* env);
int register_android_server_InputManager(JNIEnv* env);
int register_android_server_LightsService(JNIEnv* env);
int register_android_server_PowerManagerService(JNIEnv* env);
int register_android_server_UsbDeviceManager(JNIEnv* env);
int register_android_server_UsbHostManager(JNIEnv* env);
int register_android_server_VibratorService(JNIEnv* env);
int register_android_server_SystemServer(JNIEnv* env);
int register_android_server_HelloService(JNIEnv* env);
int register_android_server_location_GpsLocationProvider(JNIEnv* env);
int register_android_server_connectivity_Vpn(JNIEnv* env);
};

using namespace android;

extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    JNIEnv* env = NULL;
    jint result = -1;

    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
        LOGE("GetEnv failed!");
        return result;
    }
    LOG_ASSERT(env, "Could not retrieve the env!");
    register_android_server_PowerManagerService(env);
    register_android_server_InputApplicationHandle(env);
    register_android_server_InputWindowHandle(env);
    register_android_server_InputManager(env);
    register_android_server_LightsService(env);
    register_android_server_AlarmManagerService(env);
    register_android_server_BatteryService(env);
    register_android_server_UsbDeviceManager(env);
    register_android_server_UsbHostManager(env);
    register_android_server_VibratorService(env);
    register_android_server_SystemServer(env);
    LOGE("onhello");
    register_android_server_HelloService(env);
    LOGE("onhelloend");
    register_android_server_location_GpsLocationProvider(env);
    register_android_server_connectivity_Vpn(env);

    return JNI_VERSION_1_4;
}


红色的是我加的,makefile文件也没问题,因为我以及看到成才的so文件了,但是一致报那个错,模拟器在android那几个字的开机界面起不来,看门口一直不断尝试重启

还有,这个onload.cpp加载的是jni下面的方法还是java下的方法?能否告诉我原理 --------------------编程问答-------------------- 没有人知道吗? --------------------编程问答-------------------- 没做过,老罗的书?指的是那一本?说一下让大家学习一下高级技术! --------------------编程问答-------------------- 03-02 22:35:35.258: E/JNIHelp(184): Native registration unable to find class 'com/android/server/HelloService', aborting

这句不是说了吗?你regist了没啊 --------------------编程问答-------------------- Android硬件抽象层(HAL)概要介绍和学习计划 
http://blog.csdn.net/luoshengyang/article/details/6567257


 一. 在Android内核源代码工程中编写硬件驱动程序。

     二. 在Android系统中增加C可执行程序来访问硬件驱动程序。

     三. 在Android硬件抽象层增加接口模块访问硬件驱动程序。

     四. 在Android系统中编写JNI方法在应用程序框架层提供Java接口访问硬件。

     五. 在Android系统的应用程序框架层增加硬件服务接口。

     六. 在Android系统中编写APP通过应用程序框架层访问硬件服务。

--------------------编程问答-------------------- 楼主 解决了没  我出现相同错误啊 --------------------编程问答-------------------- register时无法找到指定目录下的service “com/android/server/HelloService”
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,