记录下,编译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.*
...