从libs /添加jar文件到Android.mk

时间:2012-12-11 22:19:41

标签: android android-make

几乎Adding a external jar reference in Android.mk找到了答案,但我仍然不在那里。

我的项目在libs /目录中包含commons-io-2.4.jar和jsch-0.1.49.jar。在日食中,一切都建立得很漂亮。现在我想编写一个Android.mk文件来自动构建我的项目。

我的Android.mk看起来像这样,但它不起作用。

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := MyProject
LOCAL_CERTIFICATE := platform

LOCAL_STATIC_JAVA_LIBRARIES := jsch-0.1.49 commons-io-2.4

LOCAL_PROGUARD_FLAGS      := -include $(LOCAL_PATH)/proguard.flags

include $(BUILD_PACKAGE)

LOCAL_STATIC_JAVA_LIBRARIES := libs
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libs:jsch-0.1.49 libs:commons-io-2.4

include $(BUILD_MULTI_PREBUILT)

我确定我的错误只是一个小秘密,但我无法理解。

Android.mk文件有很好的参考吗?我所能找到的只是使用ndk的配方。

2 个答案:

答案 0 :(得分:23)

好的,几个小时的谷歌搜索和实验似乎找到了解决方案 在此记录以供其他人查找:

关键是

  1. 使用我想要包含的库的符号名称定义LOCAL_STATIC_JAVA_LIBRARIES,例如libjsch
  2. 执行CLEAR_VARS(为什么?)
  3. LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES定义为libjsch:<path-to-jar-file>
  4. 包括BUILD_MULTI_PREBUILT
  5. (测试显示任何符号名称(例如“foo”)都可以正常工作,只要它在两个声明中匹配即可。)

    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    
    LOCAL_SRC_FILES := $(call all-java-files-under, src)
    
    LOCAL_PACKAGE_NAME := MyProject
    
    LOCAL_STATIC_JAVA_LIBRARIES := libjsch
    
    include $(BUILD_PACKAGE)
    
    include $(CLEAR_VARS)
    
    LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libjsch:libs/jsch-0.1.49.jar
    
    include $(BUILD_MULTI_PREBUILT)
    

答案 1 :(得分:6)

感谢Edward Falk。我刚刚解决了我的问题你给了我再次感谢这里是我的代码。关键字&#34; lib&#34;是一匹夜魇。

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-subdir-java-files)

LOCAL_PACKAGE_NAME := MDM

LOCAL_STATIC_JAVA_LIBRARIES := libandroid-async-http libgcm libjson-simple


LOCAL_JAVA_LIBRARIES += telephony-common mms-common

LOCAL_CERTIFICATE := platform

include $(BUILD_PACKAGE)

include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libandroid-async-http:libs/android-async-http-1.4.4.jar libgcm:libs/gcm.jar  libjson-simple:libs/json-simple-1.1.1.jar 

include $(BUILD_MULTI_PREBUILT)