Tencent / Shadow

零反射全动态Android插件框架
BSD 3-Clause "New" or "Revised" License
7.46k stars 1.3k forks source link

kotlin_version="1.5.3",升级 kotlin 版本到 1.8.0 后编译release版本 APK 时报错 #1211

Closed LeonWu6 closed 11 months ago

LeonWu6 commented 1 year ago

Shadow 框架的 kotlin_version="1.5.3",升级 kotlin 版本到 1.8.0 后, 每次将工模 clean 后,选择 assembleRelease 编译,clean后的第一次编译,就会报下面的编译异常。 查不出原因,故来请教下大佬,求指导。

Runtime APK 的 lintVitalAnalyzeRelease task 时:

> Task :CellularRuntime:lintVitalAnalyzeRelease
e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.0/1796921c7a3e2e2665a83e6c8d33399336cd39bc/kotlin-stdlib-1.8.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.0/1796921c7a3e2e2665a83e6c8d33399336cd39bc/kotlin-stdlib-1.8.0.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.0/1796921c7a3e2e2665a83e6c8d33399336cd39bc/kotlin-stdlib-1.8.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.8.0/f7197e7cc76453ac59f8b0f8d5137cc600becd36/kotlin-stdlib-common-1.8.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: E:/codes/em_u/em/splitApk/CellularRuntime/build/intermediates/app_classes/release/classes.jar!/META-INF/CellularRuntime_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

Loader APK 的 lintVitalAnalyzeRelease task 时:

> Task :CellularLoader:lintVitalAnalyzeRelease
e: E:/codes/em_u/em/host-lib/build/outputs/jar/host-lib-debug.jar!/META-INF/host-lib_debug.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e:E:/codes/em_u/em/utils/constant/build/.transforms/4d0d0f20d32d1ab50e7e147d73e5aa11/transformed/out/jars/classes.jar!/META-INF/constant_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.0/1796921c7a3e2e2665a83e6c8d33399336cd39bc/kotlin-stdlib-1.8.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.0/1796921c7a3e2e2665a83e6c8d33399336cd39bc/kotlin-stdlib-1.8.0.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.0/1796921c7a3e2e2665a83e6c8d33399336cd39bc/kotlin-stdlib-1.8.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.8.0/f7197e7cc76453ac59f8b0f8d5137cc600becd36/kotlin-stdlib-common-1.8.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: E:/codes/em_u/em/splitApk/CellularLoader/build/intermediates/app_classes/release/classes.jar!/META-INF/CellularLoader_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

插件APP的lintVitalAnalyzePluginRelease 时:

Task :CellularApp:lintVitalAnalyzePluginRelease


e:E:/codes/em_u/em/utils/commonutils/build/.transforms/878ad6958c10d2fdcf0fdce495e69bf8/transformed/out/jars/classes.jar!/META-INF/commonutils_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: E:/codes/em_u/em/utils/constant/build/.transforms/4d0d0f20d32d1ab50e7e147d73e5aa11/transformed/out/jars/classes.jar!/META-INF/constant_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e:E:/codes/em_u/em/DFRUtils/MinidumpService/build/.transforms/d4b36a23016c80864ea57087e863e9e5/transformed/out/jars/classes.jar!/META-INF/MinidumpService_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: E:/codes/em_u/em/host-lib/build/.transforms/4db37a5bbe2ebdc8593bdf391790fee2/transformed/out/jars/classes.jar!/META-INF/host-lib_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.0/1796921c7a3e2e2665a83e6c8d33399336cd39bc/kotlin-stdlib-1.8.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.0/1796921c7a3e2e2665a83e6c8d33399336cd39bc/kotlin-stdlib-1.8.0.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.0/1796921c7a3e2e2665a83e6c8d33399336cd39bc/kotlin-stdlib-1.8.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e: D:/Users/wuxiaoyu/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.8.0/f7197e7cc76453ac59f8b0f8d5137cc600becd36/kotlin-stdlib-common-1.8.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

e:E:/codes/em_u/em/splitApk/CellularApp/build/intermediates/app_classes/pluginRelease/classes.jar!/META-INF/CellularApp_pluginRelease.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.5.1.

shifujun commented 1 year ago

这个报错看起来还是很清晰的。你的host-lib依赖的还是1.5版本。然后看起来也不是原始的sample工程,你改了什么也看不到。其实应该没必要更新shadow的kotlin依赖吧,应该和业务的kotlin依赖不冲突的。kotlin runtime可以被很好的混淆,打包在shadow的jar中,和业务的kotlin依赖没有关系。

最重要的是,基本要升级一个第三方依赖,也不能从1.5直接升级到1.8。跨度太大了。第三方库一般只考虑一个版本一个版本升级的兼容性提示。

VamPeng commented 1 year ago

这个问我我也遇到过,应该是要你把agp升了,貌似是版本小于7.3.0导致,试试升级到7.4.2

Sandeep145XamRN commented 1 year ago

I have also encountered this question. It should require you to upgrade agp. It seems that the version is smaller than 7.3.0. Try upgrading to 7.4.2.

thanks, it works with react native project too.

LeonWu6 commented 1 year ago

这个问我我也遇到过,应该是要你把agp升了,貌似是版本小于7.3.0导致,试试升级到7.4.2

@VamPeng @shifujun
您好,当我把Gradle升到7.5.1,再把 AGP升到7.4.2时,发生以下报错:

A problem occurred evaluating project ':CellularApp'.
> Failed to apply plugin 'com.tencent.shadow.plugin'.
   > Could not create an instance of type com.tencent.shadow.core.gradle.extensions.PackagePluginExtension.
      > Could not generate a decorated class for type PackagePluginExtension.
         > org/json/simple/JSONObject

你们有遇到过吗?

LeonWu6 commented 1 year ago

这个报错看起来还是很清晰的。你的host-lib依赖的还是1.5版本。然后看起来也不是原始的sample工程,你改了什么也看不到。其实应该没必要更新shadow的kotlin依赖吧,应该和业务的kotlin依赖不冲突的。kotlin runtime可以被很好的混淆,打包在shadow的jar中,和业务的kotlin依赖没有关系。

最重要的是,基本要升级一个第三方依赖,也不能从1.5直接升级到1.8。跨度太大了。第三方库一般只考虑一个版本一个版本升级的兼容性提示。

这个报错看起来还是很清晰的。你的host-lib依赖的还是1.5版本。然后看起来也不是原始的sample工程,你改了什么也看不到。其实应该没必要更新shadow的kotlin依赖吧,应该和业务的kotlin依赖不冲突的。kotlin runtime可以被很好的混淆,打包在shadow的jar中,和业务的kotlin依赖没有关系。

最重要的是,基本要升级一个第三方依赖,也不能从1.5直接升级到1.8。跨度太大了。第三方库一般只考虑一个版本一个版本升级的兼容性提示。

@shifujun
前辈,您好!由于我们公司的安全扫描工具识别出kotlin 1.5.31版本有安全漏洞,所以得升级kotlin版本。 再请教一下此问题,看编译log看,是我的 host-lib依赖是1.5版本的,我的host-lib其实很简单,如下面是 host-lib 的 build.gradle。 能否帮忙看看是哪个配置可能导致依赖 kotlin 1.5.1 版本。 感谢!

host-lib/build.gradle

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'com.tencent.shadow.internal.aar-to-jar'
}
android {
    def IS_EXP_VERSION = 'IS_EXP_VERSION'
    compileSdkVersion prop_compileSdkVersion
    buildToolsVersion prop_buildToolsVersion
    defaultConfig {
        minSdk project.MIN_SDK_VERSION
        targetSdk project.TARGET_SDK_VERSION
        versionCode project.VERSION_CODE
        versionName project.VERSION_NAME
    }
    buildTypes {
        debug {
            minifyEnabled false
            buildConfigField('boolean', IS_EXP_VERSION, 'false')
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled false
            buildConfigField('boolean', IS_EXP_VERSION, 'false')
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        releaseExp {
            initWith(buildTypes.release)
            buildConfigField('boolean', IS_EXP_VERSION, 'true')
        }
        debugExp {
            initWith(buildTypes.releaseExp)
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
}
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.20"
    compileOnly "com.sectools.check:olint:+"
}
shifujun commented 1 year ago

@LeonWu6 app最终打包哪个版本不是lib能决定的。编译和打包是分开的两件事。如何让gradle打包app时指定或者排除某个lib传递来的依赖,是gradle使用的知识范畴。shadow的所有部分都是lib,所有你需要在打包app时指定一个兼容的版本就行了。具体要怎么写还是自己查查gradle的文档吧。另外gradle也有打印出所有依赖的传递关系的能力。