記錄下,編譯fourthline.cling靜態庫的依賴問題。
1,因爲需要在android的源碼環境下調試依賴cling的投屏,需要將fourthline.cling編譯爲靜態庫。
首先預製依賴的.jar文件,具體是LOCAL_STATIC_JAVA_LIBRARIES,include $(BUILD_STATIC_JAVA_LIBRARY)相關.mk文件的編寫。
2,然後,javax包的依賴,android環境下貌似不能直接使用javax包下的文件,需另外導入相關庫:
https://www.mvnjar.com/javax.enterprise/cdi-api/2.0/detail.html
也就是cdi-api-2.0的jar包,它包含的類文件:
javax.decorator.Decorator.
javax.enterprise.....
3,在把fourthline.cling編譯成靜態庫時,引用前面的靜態庫:
LOCAL_STATIC_JAVA_LIBRARIES += cdi-api
LOCAL_SDK_VERSION := current
include $(BUILD_STATIC_JAVA_LIBRARY)
需要提醒的是其中的LOCAL_SDK_VERSION := current編譯項會導致
external/flCling/fourthlineCling/Android.mk: error: fourthling.cling (java:sdk) should not link to cdi-api (java:platform)
編譯錯誤。因爲使用android中非public的接口,所以需要修改.mk文件,LOCAL_SDK_VERSION := current行替換爲LOCAL_PRIVATE_PLATFORM_APIS := true
4,過濾掉引用類導致的編譯錯誤:
如編譯log中出現:
Warning: javax.enterprise.inject.spi.BeanManager: can't find referenced class javax.el.ExpressionFactory
Warning: org.eclipse.jetty.servlet.jmx.ServletMappingMBean: can't find referenced field 'java.lang.Object _managed' in program class org.eclipse.jetty.servlet.jmx.ServletMappingMBean
......
Error: Please correct the above warnings first.
[ 18% 3/16] //frameworks/base:framework javac10 [common]
ninja: build stopped: subcommand failed.
12:42:21 ninja failed with: exit status 1
參考文檔:
https://www.guardsquare.com/en/products/proguard/manual/troubleshooting#unresolvedclass
Warning: can't find superclass or interface
Warning: can't find referenced class
Warning: can't find referenced field/method '...' in program class ...
api我就不翻譯了,大意是引用的jar包中又引用了別的類,導致了這樣的警告,儘管不是error,也導致了編譯不過。
如果這些缺失的class,不影響程序的正常運行,沒有這些依賴也沒啥壞處,就可以過濾掉這些警告。
如果缺失這些class,導致程序crash,還是要去找到對應的jar包,導入進來。
這裏的處理,是去過濾掉這些warning:
做法,首先根目錄編寫:proguard.flags文件
然後,在android.mk中應用這個文件proguard.flags。
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
另外proguard.flags文件的內容:
# Disable the warnings of using dynamic method call in common library.
-dontnote org.fourthline.cling.*
...
#Avoid the library class dependency error
-dontwarn org.eclipse.jetty.jmx.*
-dontwarn javax.el.*
...