jni调用so文件问题

Ghello_mail 2011-07-09 08:29:22
    public class CplusGraphics {
static{
System.out.println("方法被调用之前--------------");
System.loadLibrary("ShapeRead");
System.out.println("方法被调用--------------");
}
public static native int GetShpType();
}


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

#ifndef _Included_com_graphics_base_CplusGraphics
#define _Included_com_graphics_base_CplusGraphics
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_graphics_base_CplusGraphics
* Method: GetShpType
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_graphics_base_CplusGraphics_GetShpType
(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

    #include "com_graphics_base_CplusGraphics.h"
#include <stdlib.h>

#ifndef _Included_com_fileText_fileRead
#define _Included_com_fileText_fileRead
#ifdef __cplusplus

extern "C" {
#endif
//jobject arraylist;

JNIEXPORT jint JNICALL Java_com_graphics_base_CplusGraphics_GetShpType
(JNIEnv *env, jobject obj)

/*
* Class: CplusGraphics
* Method: SetShpType
* Signature: (I)V
*/
{
int i = 100;
jint type = i;
return type;
}

#ifdef __cplusplus
}
#endif
#endif



//其他类里面调用
System.out.println(CplusGraphics.GetShpType());


然后编译没问题,android模拟器里面运行程序,屏幕会卡住。

System.out.println("方法被调用之前--------------");
System.loadLibrary("ShapeRead");
System.out.println("方法被调用--------------");
中只有第一句输出了。就卡在第二句java语句上了。 求各位大大帮忙看看哪里错了。

...全文
474 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
念茜 2011-07-10
  • 打赏
  • 举报
回复
应该是没找到库文件,自己做的jni接口还是编进应用程序的好
Ghello_mail 2011-07-10
  • 打赏
  • 举报
回复
谢谢楼上各位,问题解决了。 上面少贴了两行,是声明了一个类的对象,就是这部分出错了。这个类中其中使用了fstream,引用的是#include<fstream>,把头文件换成#include <iostream>之后问题解决了。感觉很莫名。。。
是ndk的问题?不知道各位大大使用jni的时候是如何调试c/c++代码的?能否java代码转到c++代码?
fontlose 2011-07-09
  • 打赏
  • 举报
回复
so文件都没加载成功,so文件要拷到libs\armeabi\下。

可以检查下/data/data/包/lib下有没so文件生成。
xqhrs232 2011-07-09
  • 打赏
  • 举报
回复
你的SO文件有没整到你的APK里面去?

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧