新手帮助,NDK,java.lang.UnsatisfiedLinkError中 [英] Beginner help with NDK, java.lang.UnsatisfiedLinkError
问题描述
我想创建我的使用NDK的第一款Android应用程序。我试图用live555.com源构建流从手机MP4文件到别的地方的应用程序。
I am trying to create my first Android app that uses the NDK. I am trying to use the live555.com sources to build an app that streams a MP4 file from the phone to somewhere else.
我使用Windows 7 32位与JDK 1.6.0_24,MOTODEV 2.1和最新的Android SDK和NDK工具包。
I am using Windows 7 32 bit with JDK 1.6.0_24, MOTODev 2.1 and latest Android SDK and NDK toolkits.
到目前为止,我已经建立了新的项目,创造了JNI目录。内部JNI我已经把源文件和Android.mk文件。如果我执行NDK的构建我看到:
So far I have setup a new project and created the jni directory. Inside JNI I have placed the source files and Android.mk files. If I execute ndk-build I see:
$ $NDK/ndk-build
SharedLibrary : libtestProgs.so
Install : libtestProgs.so => libs/armeabi/libtestProgs.so
如此看来本机库正在建设中。
So it seems the native library is being built.
当我运行我的应用程序崩溃与lava.lang.UnsatisfiedLinkError:startStream
When I run my app it crashes with a lava.lang.UnsatisfiedLinkError: startStream.
startStream()是我想在libtestProgs.so库调用的方法。
startStream() is the method I am trying to call in the libtestProgs.so library.
事情我已经检查:
libtestProgs.so是建立和下库/ armeabi的适当位置
的System.loadLibrary(testProgs);我试图本地调用之前被称为
运行JAVAH -o jni.h com.streamtest.MainActivity,包括来自.cpp文件这个.H。
Things I have checked: libtestProgs.so is built and in the proper place under libs/armeabi System.loadLibrary("testProgs"); is called before I attempt the native call Run javah -o jni.h com.streamtest.MainActivity and include this .h from the .cpp file.
下面是我的MainActivity.java文件:
Here is my MainActivity.java file:
package com.streamtest;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
public static final String LOG_TAG = "StreamTest";
static
{
try
{
//System.loadLibrary("jnix");
System.loadLibrary("testProgs");
}
catch(Throwable e)
{
Log.e(LOG_TAG, e.toString());
throw new RuntimeException(e);
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// call our native code
Log.e(LOG_TAG, "About to call native code!");
startStream();
}
private native void startStream();
}
本机C ++文件只是从live555.com的testOnDemandRTSPServer.cpp文件。我改变了main()方法是一个Java本机方法。在这里,它是:
The native c++ file is simply the testOnDemandRTSPServer.cpp file from live555.com. I changed the main() method to be a Java native method. Here it is:
#include "com_streamtest_MainActivity.h"
#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"
void Java_com_streamtest_MainActivity_startStream(JNIEnv *env)
{
// Begin by setting up our usage environment:
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
uenv = BasicUsageEnvironment::createNew(*scheduler);
下面是LogCat中输出:
Here is the LogCat output:
04-12 08:40:27.934: ERROR/StreamTest(17130): About to call native code!
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): FATAL EXCEPTION: main
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): java.lang.UnsatisfiedLinkError: startStream
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at com.streamtest.MainActivity.startStream(Native Method)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at com.streamtest.MainActivity.onCreate(MainActivity.java:31)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at android.os.Looper.loop(Looper.java:123)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at java.lang.reflect.Method.invoke(Method.java:521)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-12 08:40:27.965: ERROR/AndroidRuntime(17130): at dalvik.system.NativeStart.main(Native Method)
我想知道有关的致命异常:主线。在原始.cpp文件的是一个main()方法。在我的新文件没有主()。这是问题的原因是什么?如果是,我怎么使用一个.cpp文件作为库?它需要一个main()方法?
I am wondering about the FATAL EXCEPTION: main line. In the original .cpp file their was a main() method. In my new file there is no main(). Is this the cause of the problem? If it is, how do I use a .cpp file as a library? Does it need a main() method?
任何帮助AP preciated,我试图让我的第一个应用程序NDK运行。
Any help appreciated as I try to get my first NDK app running.
谢谢,
詹姆斯
Thanks, James
推荐答案
是否包含testOnDemandRTSPServer.cpp在你的Android.mk文件,你LOCAL_SRC_FILES变量?
Did you include testOnDemandRTSPServer.cpp in your LOCAL_SRC_FILES variable in your Android.mk file?
当您执行NDK的构建,你应该已经看到每次在LOCAL_SRC_FILES包括C / C ++的文件正在编制。你应该看到这样一行(其中几个人如果有多个C / C ++文件):
When you executed ndk-build, you should have seen each of the c/c++ files you included in LOCAL_SRC_FILES being compiled. You should have seen a line like (among several others if there are multiple c/c++ files):
编译胳膊:libtestProgs< = testOnDemandRTSPServer.cpp
Compile arm : libtestProgs <= testOnDemandRTSPServer.cpp
事实上,根据您从NDK的构建执行包括输出,它看起来像你没有包含在LOCAL_SRC_FILES什么,你只是建立什么也没有一个libtestProgs.so文件编译成它。
In fact, Based on the output you included from your execution of ndk-build, it looks like you didn't included anything in LOCAL_SRC_FILES, and you're just creating a libtestProgs.so file with nothing compiled into it.
从文档:
的LOCAL_SRC_FILES变量必须包含℃的列表和/或C ++源代码
将要建造和组装成一个模块文件。请注意,您应该
没有表头和这里包含的文件,因为编译系统会
计算自动为您依赖关系;只列出源文件
这将直接传递给一个编译器,你应该是好的。
"The LOCAL_SRC_FILES variables must contain a list of C and/or C++ source files that will be built and assembled into a module. Note that you should not list header and included files here, because the build system will compute dependencies automatically for you; just list the source files that will be passed directly to a compiler, and you should be good."
请参阅Android的MK.html在您的详细信息下载Android的JNI的文档文件夹中。
See ANDROID-MK.html in the docs folder of the Android JNI you downloaded for details.
这篇关于新手帮助,NDK,java.lang.UnsatisfiedLinkError中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!