2014-04-01 56 views
2

我有一個預建立的第三方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安裝。請幫忙。

+0

它實際上是添加 – mangusta

+0

http://stackoverflow.com/questions/8650472/how-do-i-import-a-native-library-so-file-into-eclipse 請仔細閱讀此問題。 – Bhaskar

+0

它已經是apk的一種藝術,你不需要手動添加它。只需在運行時通過您的代碼加載它 –

回答

0

您需要將libliveplay包含爲PREBUILT庫。將libliveplay.so在你的/ JNI目錄,因此結構如下:

Android.mk     --> the file above 
armeabi/libliveplay.so  --> the armeabi prebuilt shared library 
armeabi-v7a/libliveplay.so --> the armeabi-v7a prebuilt shared library 

然後在Android.mk

LOCAL_PATH:= $(call my-dir) 

include $(CLEAR_VARS) 
LOCAL_MODULE := liveplay 
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libliveplay.so 
include $(PREBUILT_SHARED_LIBRARY) 


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 := liveplay 

include $(BUILD_PACKAGE) 
include $(call all-makefiles-under,$(LOCAL_PATH)) 
+0

我已經試過你的方法,構建出來的apk沒有包含libliveplay.so – gladman

+0

你可以檢查libliveplay.so的路徑是否正確? – Krypton

+0

我的lib路徑是在project_path/libs/armeabi /和project_path/libs/armeabi-v7a /文件夾下,它是android apk libs文件夾 – gladman