Android中靜態jar庫

jackie_gnu發表於2011-11-03

如何編譯也static jar library.

  17 # Note: the source code is in java/, not src/, because this code is also part of
  18 # the framework library, and build/core/pathmap.mk expects a java/ subdirectory.
  19
  20 include $(CLEAR_VARS)
  21 LOCAL_MODULE := android-common
  22 LOCAL_SDK_VERSION := 8
  23 LOCAL_SRC_FILES := \
  24      $(call all-java-files-under, java) \
  25      $(call all-logtags-files-under, java)
  26 include $(BUILD_STATIC_JAVA_LIBRARY)
 


與編譯package等結構大致相同,不同之處是使用"BUILD_STATIC_JAVA_LIBRARY",生成的jar檔案不會copy到/system/framework/下面,

只會臨時存在於../out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/目錄下.

如何使用jar library.

  6 LOCAL_STATIC_JAVA_LIBRARIES := \
   7         android-common \
   8         guava
   9
  10 LOCAL_SRC_FILES := \
  11         $(call all-java-files-under, src) \
  12         src/com/android/browser/EventLogTags.logtags
  13
  14 LOCAL_PACKAGE_NAME := Browser
 


在Android.mk中引入android build system的LOCAL_STATIC_JAVA_LIBRARIES變數,並給其賦值為:android-common。

如此以來,編譯後的apk 或jar中就引入了所有的class檔案,有點像C語言中的靜態庫檔案(*.a)

 

 

 

相關文章