我编写了一个在发布时崩溃的NativeActivity,因为(我的理论......)我在做错误命名共享库或AndroidManifest.xml中的模块。下面是我的应用程序启动时LogCat的输出,以及我的清单文件的内容。
我在设置时出错的任何想法?
谢谢, ALF
===================清单=========================== ==================
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Mythica.SpiderGame"
android:versionCode="1"
android:versionName="1.0">
<!-- This is the platform API where NativeActivity was introduced. -->
<uses-sdk android:minSdkVersion="12" />
<!-- This .apk has no Java code itself, so set hasCode to false. -->
<application android:label="@string/app_name" android:hasCode="false">
<!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="android.app.NativeActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
android:value="SpiderGame" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<!-- END_INCLUDE(manifest) -->
=================== LOGCAT OUTPUT ========================== ===================
07-31 23:13:11.770:WARN / dalvikvm(1384):threadid = 1:线程退出时未捕获异常(group = 0x4016d760) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):致命异常:主要 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):java.lang.RuntimeException:无法启动活动ComponentInfo {com.Mythica.SpiderGame / android.app.NativeActivity}:java.lang.IllegalArgumentException:无法加载本地库:/data/data/com.Mythica.SpiderGame/lib/libSpiderGame.so 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1751) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):在android.app.ActivityThread.access $ 1500(ActivityThread.java:122) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1005) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):在android.os.Handler.dispatchMessage(Handler.java:99) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):在android.os.Looper.loop(Looper.java:132) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):在android.app.ActivityThread.main(ActivityThread.java:4028) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):at java.lang.reflect.Method.invokeNative(Native Method) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):at java.lang.reflect.Method.invoke(Method.java:491) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:844) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):at dalvik.system.NativeStart.main(Native Method) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):引起:java.lang.IllegalArgumentException:无法加载本机库:/data/data/com.Mythica.SpiderGame/lib/libSpiderGame.so 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):在android.app.NativeActivity.onCreate(NativeActivity.java:199) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715) 07-31 23:13:11.780:ERROR / AndroidRuntime(1384):......还有11个 07-31 23:13:11.780:WARN / ActivityManager(288):强制完成活动com.Mythica.SpiderGame / android.app.NativeActivity 07-31 23:13:11.800:ERROR / android.os.Debug(288):Dumpstate&gt; /数据/日志/ dumpstate_app_error
答案 0 :(得分:0)
我的问题的解决方案是将我的游戏库构建为静态对象而不是共享库。 MyApp引用了MyLibrary.so,我想共享库必须在运行之前手动复制到设备上,尽管由于静态链接正在完成工作,我还没有测试过这个理论。
如果我是正确的,那么无效的假设就是认为我自己的任何共享库都会内置到我的.apk中,就像内置NativeActivity一样。
答案 1 :(得分:0)
您应该阅读NDK中的docs / PREBUILTS.html。您可以在Android.mk文件中添加如下所示的部分:
#
# Include prebuilt shared library
#
include $(CLEAR_VARS)
LOCAL_MODULE := MyLibrary-prebuilt
LOCAL_SRC_FILES := relative/path/to/MyLibrary.so
LOCAL_EXPORT_C_INCLUDES := relative/path/to/includes
include $(PREBUILT_SHARED_LIBRARY)
然后就在Android.mk结束时调用BUILD_SHARED_LIBRARY之前,你把它放在:
LOCAL_SHARED_LIBRARIES := MyLibrary-prebuilt
这假设你已经设法在ndk构建系统之外为ARM交叉编译你的库。如果您想在ndk-build中构建共享库,那么就像为原生活动构建.so一样。