项目场景:
项目的第三方网络库升级新版本,替换就版本的jar
问题描述
老项目升级第三方okhttp 3.14.9 jar 出现编译失败:
build out/target/common/obj/JAVA_LIBRARIES/lib-okhttp-3.14.9_intermediates/classes.jack
FAILED: out/target/common/obj/JAVA_LIBRARIES/lib-okhttp-3.14.9_intermediates/classes.jack
/bin/bash -c "(mkdir -p out/target/common/obj/JAVA_LIBRARIES/lib-okhttp-3.14.9_intermediates/classes.jack.tmpjill.res ) && (unzip -qo vendor/tpv/apps/tpvRemoteControl/app/src/main/libs/okhttp-3.14.9.jar -d out/target/common/obj/JAVA_LIBRARIES/lib-okhttp-3.14.9_intermediates/classes.jack.tmpjill.res ) && (find out/target/common/obj/JAVA_LIBRARIES/lib-okhttp-3.14.9_intermediates/classes.jack.tmpjill.res -iname \"*.class\" -delete ) && (JACK_VERSION=4.31.CANDIDATE out/host/linux-x86/bin/jack @build/core/jack-default.args -D jack.import.resource.policy=keep-first -D jack.import.type.policy=keep-first -D jack.android.min-api-level=1 --import vendor/tpv/apps/tpvRemoteControl/app/src/main/libs/okhttp-3.14.9.jar --import-resource out/target/common/obj/JAVA_LIBRARIES/lib-okhttp-3.14.9_intermediates/classes.jack.tmpjill.res --output-jack out/target/common/obj/JAVA_LIBRARIES/lib-okhttp-3.14.9_intermediates/classes.jack ) && (rm -rf out/target/common/obj/JAVA_LIBRARIES/lib-okhttp-3.14.9_intermediates/classes.jack.tmpjill.res )"
原因分析:
Lambda coming from jar file need their interfaces on the...
提示无法支持lambda表达式写法,其中 jack.android.min-api-level=1 关键所在,由于编译的android api level导致无法支持 lambda写法导致编译不通过
解决方案:
问题找到,只要找到对应的修改 jack.android.min-api-level 版本就行。
这边参考Android O Jack预编译静态jar编译报错解决_wd623894174的博客-CSDN博客
LOCAL_MIN_SDK_VERSION 默认值 1
其中
LOCAL_STATIC_JAVA_LIBRARIES := lib-okhttp-3.14.9
修改前:
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := lib-okhttp-3.14.9/libs/okhttp-3.14.9.jar
include $(BUILD_MULTI_PREBUILT)
修改后:
include $(CLEAR_VARS)
LOCAL_MODULE := lib-okhttp-3.14.9
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_SRC_FILES := libs/okhttp-3.14.9.jar
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_MIN_SDK_VERSION := 24
include $(BUILD_PREBUILT)
这样修改可通过编译,指定了 LOCAL_MIN_SDK_VERSION 24 可根据需要版本修改