我有一個預建立的第三方C庫libliveplay.so,我想將它添加到apk。我把它如何在android apk中添加第三方C庫?
libs/armeabi
libs/armeabi-v7a
下,我的android.mk文件是這樣的:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := RtspPlayer
LOCAL_CERTIFICATE := platform
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_DEX_PREOPT := false
LOCAL_SHARED_LIBRARIES := libliveplay
include $(BUILD_PACKAGE)
include $(call all-makefiles-under,$(LOCAL_PATH))
但不能用此方法添加所以進APK,任何人都可以幫忙嗎?
當APK打造出來的,我的設備上安裝和運行時發生錯誤:
E/AndroidRuntime(4660): FATAL EXCEPTION: main
E/AndroidRuntime(4660): java.lang.ExceptionInInitializerError
E/AndroidRuntime(4660): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(4660): at java.lang.Class.newInstance(Class.java:1319)
E/AndroidRuntime(4660): at android.app.Instrumentation.newActivity(Instrumentation.java:1064)
E/AndroidRuntime(4660): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
E/AndroidRuntime(4660): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime(4660): at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(4660): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime(4660): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(4660): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(4660): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime(4660): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(4660): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(4660): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(4660): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(4660): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(4660): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load liveplay from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.mrlans.play-2.apk,libraryPath=/data/app-lib/com.mrlans.play-2]: findLibrary returned null
E/AndroidRuntime(4660): at java.lang.Runtime.loadLibrary(Runtime.java:365)
E/AndroidRuntime(4660): at java.lang.System.loadLibrary(System.java:535)
E/AndroidRuntime(4660): at com.mrlans.play.MediaActivity.<clinit>(MediaActivity.java:152)
E/AndroidRuntime(4660): ... 15 more
錯誤顯示,所以沒有包括在APK,它並沒有安裝到系統時,APK安裝。請幫忙。
它實際上是添加 – mangusta
http://stackoverflow.com/questions/8650472/how-do-i-import-a-native-library-so-file-into-eclipse 請仔細閱讀此問題。 – Bhaskar
它已經是apk的一種藝術,你不需要手動添加它。只需在運行時通過您的代碼加載它 –