这两天对gradle进行了升级,出现以下错误提示,当时十分费解,找不到原因,后来经过排查插件引入,找到原因。
Unable to find method ''void com.android.build.api.dsl.ApplicationExtension.onVariantProperties(kotlin.jvm.functions.Function1)''
'void com.android.build.api.dsl.ApplicationExtension.onVariantProperties(kotlin.jvm.functions.Function1)'
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
过程中发现Gradle plugin版本只要是高于4.2.0就会出现这个错误,换回4.1.3并使用7.0.2的Gradle就没有出现这个问题。
于是我新建了一个项目使用高版本的gradle和gradleplugin,发现并没有出现该问题,所以我开始排查其它plugin的兼容性。
最后发现com.getkeepsafe.dexcount:dexcount-gradle-plugin的版本没有升级,,dex分包插件的低版本没有kotlin代码分包的功能。而gradle最近的高版本(目前测试6.7.0以后含kotlin编译,7.0以后更是主方向为kotlin)所以dex分包插件也要升级到高版本,含kotlin分包。至此问题解决。希望帮到遇到问题的人。