Android的NDK:没有JNI_OnLoad在...跳过INIT发现:但有JNI_OnLoad [英] Android NDK : No JNI_OnLoad found in ... skipping init : But there is JNI_OnLoad

查看:1410
本文介绍了Android的NDK:没有JNI_OnLoad在...跳过INIT发现:但有JNI_OnLoad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再次问这个问题,因为我不得不这样做。

我有,同时运行的是基于NDK应用此错误。


  

ðdalvikvm:没有JNI_OnLoad在/data/app-lib/com.venky-1/libme.so 0xa5082228发现,跳过的init
  W¯¯dalvikvm:未找到本地LCOM / venky /家庭实施; .getPermission:(Landroid /应用/活动;)我


我公司已通过


  1. 没有JNI_OnLoad中发现的......跳跃的init

  2. No JNI_OnLoad发现跳过INIT>关闭应用

  3. 没有JNI_Onload()发现VM关停

  4. ​​ JNI_OnLoad没有找到

他们的问题要么


  1. ,因为它们使用JNI特定的命名约定,他们没有使用JNI_OnLoad(例如Java_com_venky_Home_start())。因此,该消息没有意义,因为有一种替代方法。

  2. 他们用C ++和有功能名称重整。

我的情况完全不同。和上面的两个都在我的情况下无效。我使用的C文件。因此,没有截断。而且我不使用JNI样的功能名称。我手动注册使用JNI_OnLoad的功能。
因此我的结论是没有找到实现是由于这样的事实,即该应用程序是某种无法找到JNI_OnLoad。但为什么?它是在C文件present。

是code的有关章节如下。如果你需要更多的请咨询。


  

JNI / Android.mk


 包含$(CLEAR_VARS)
LOCAL_MODULE:=我
LOCAL_SRC_FILE:= me.c
包括$(BUILD_SHARED_LIBRARY)


  

COM / venky / Home.java


 包com.venky;进口android.app.Activity;
进口android.os.Bundle;公共类家庭延伸活动{    静态{
        的System.loadLibrary(我);
    }
    私人本地INT getPermission(活动活动);    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.home);
        getPermission(本);
    }
}


  

JNI / me.c


 的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#包括LT&;&STDARG.H GT;
#包括LT&;&string.h中GT;
#包括LT&;机器人/ log.h>
#包括LT&;&jni.h GT;#定义LOG_TAGcom.venky.me#定义LOG_D(...)__android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#定义LOG_F(fn_name)__android_log_write(ANDROID_LOG_DEBUG,LOG_TAG,呼吁:fn_name)静态的JavaVM * JAVA_VM;jint JNI_OnLoad(JavaVM的* VM,无效*保留)
{
    LOG_F(JNI_OnLoad);
    JAVA_VM = VM;    //获取JNI信封为所有的函数调用
    JNIEnv的* ENV;
    如果((* VM) - > GETENV(VM,(无效**)及包膜,JNI_VERSION_1_6)= JNI_OK!){
        LOG_D(GETENV失败。);
        返回-1;
    }    //查找类调用本地函数
    JCLASS NativeUsb =(* ENV) - GT;的findClass(ENV,COM / venky /家庭);
    如果(class_home == NULL){
        LOG_D(findClass的失败:没有找到类);
        返回-1;
    }    //注册getUsbPermission本地方法
    JNINativeMethod纳米[1] = {
        {getPermission,(Landroid /应用/活动;)我,get_permission}
    };    如果((* ENV) - > RegisterNatives(ENV,NativeUsb,纳米,1)){
         LOG_D(RegisterNatives失败。);
         返回-1;
    }    返回JNI_VERSION_1_6;
}INT get_permission(jobject活动)
{
    LOG_F(get_usb_permission);}


解决方案

通过@AlexCohn的帮助下,我发现我的错误。什么愚蠢的愚蠢的错误是。


  

JNI / Android.mk


 包含$(CLEAR_VARS)
  LOCAL_MODULE:=我
- LOCAL_SRC_FILE:= me.c
+ LOCAL_SRC_FILES:= me.c
  包括$(BUILD_SHARED_LIBRARY)

由于这个原因,me.c未编译。因此,它不包括在内置共享库。我至少浪费了几个小时这一点。

I am asking this question again because I have to.

I am having this error while running a NDK based application.

D dalvikvm: No JNI_OnLoad found in /data/app-lib/com.venky-1/libme.so 0xa5082228, skipping init W dalvikvm: No implementation found for native Lcom/venky/Home;.getPermission:(Landroid/app/Activity;)I

I have been through

  1. No JNI_OnLoad found in ... skipping init
  2. No JNI_OnLoad found skipping init > Application shutdown
  3. No JNI_Onload() found and VM shutting down
  4. JNI_OnLoad not found

Their problem was either

  1. They were not using JNI_OnLoad because they used JNI specific naming convention (For example Java_com_venky_Home_start()). Hence this message has no significance as there is an alternative.
  2. They were using C++ and there was function name mangling.

My case is entirely different. And the above two are invalid in my case. I am using C files. So no mangling. And I am not using JNI kind of function names. I am manually registering the functions using JNI_OnLoad. Hence my conclusion is that "No Implementation Found" is due to the fact that the application is somehow unable to find JNI_OnLoad. But why? It is present in the C file.

Relevant sections of code are as follows. Please ask if you need more.

jni/Android.mk

include $(CLEAR_VARS)
LOCAL_MODULE := me
LOCAL_SRC_FILE := me.c
include $(BUILD_SHARED_LIBRARY)

com/venky/Home.java

package com.venky;

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

public class Home extends Activity {

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


    private native int getPermission(Activity activity);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        getPermission(this);
    }
}

jni/me.c

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <android/log.h>
#include <jni.h>

#define LOG_TAG "com.venky.me"

#define LOG_D(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOG_F(fn_name) __android_log_write(ANDROID_LOG_DEBUG, LOG_TAG, "Called : " fn_name )

static JavaVM *java_vm;

jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
    LOG_F ("JNI_OnLoad");
    java_vm = vm;

    // Get JNI Env for all function calls
    JNIEnv* env;
    if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_6) != JNI_OK) {
        LOG_D ("GetEnv failed.");
        return -1;
    }

    // Find the class calling native function
    jclass NativeUsb = (*env)->FindClass(env, "com/venky/Home");
    if (class_home == NULL) {
        LOG_D ("FindClass failed : No class found.");
        return -1;
    }

    // Register native method for getUsbPermission
    JNINativeMethod nm[1] = {
        { "getPermission", "(Landroid/app/Activity;)I", get_permission}
    };

    if ((*env)->RegisterNatives(env, NativeUsb, nm , 1)) {
         LOG_D ("RegisterNatives Failed.");
         return -1;
    }

    return JNI_VERSION_1_6;
}

int get_permission (jobject activity)
{
    LOG_F ("get_usb_permission");

}

解决方案

By help of @AlexCohn, I found out my error. And what a silly stupid error it was.

jni/Android.mk

  include $(CLEAR_VARS)
  LOCAL_MODULE := me
- LOCAL_SRC_FILE := me.c
+ LOCAL_SRC_FILES := me.c
  include $(BUILD_SHARED_LIBRARY)

Because of this, me.c wasn't compiling. Hence it was not included in the built shared library. I had wasted a couple of hours on this at least.

这篇关于Android的NDK:没有JNI_OnLoad在...跳过INIT发现:但有JNI_OnLoad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆