RedMadRobot/gradle-infrastructure

Kotlin 1.7.0: Failed to apply plugin 'kotlin-android'

osipxd opened this issue · 2 comments

Can't apply com.redmadrobot.application because of Failed to apply plugin 'kotlin-android' error

An exception occurred applying plugin request [id: 'com.redmadrobot.application']
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.exceptionOccurred(DefaultPluginRequestApplicator.java:206)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:188)
	... 180 more
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin 'kotlin-android'.
	at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:173)
	... 180 more
Caused by: org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension.
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:69)
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.newInstanceWithDisplayName(DependencyInjectingInstantiator.java:50)
	at org.gradle.internal.extensibility.DefaultConvention.instantiate(DefaultConvention.java:216)
	... 209 more
Caused by: java.lang.NoSuchFieldError: Companion
	at org.jetbrains.kotlin.gradle.dsl.ToolchainSupport$Companion.createToolchain$kotlin_gradle_plugin(ToolchainDsl.kt:33)
	at org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension.<init>(KotlinProjectExtension.kt:66)
	at org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension.<init>(KotlinProjectExtension.kt:106)
	at org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension.<init>(KotlinProjectExtension.kt:115)
	at org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension.<init>(KotlinProjectExtension.kt:282)
	at org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension_Decorated.<init>(Unknown Source)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at org.gradle.internal.instantiation.generator.AsmBackedClassGenerator$InvokeConstructorStrategy.newInstance(AsmBackedClassGenerator.java:2070)
	at org.gradle.internal.instantiation.generator.AbstractClassGenerator$GeneratedClassImpl$GeneratedConstructorImpl.newInstance(AbstractClassGenerator.java:488)
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:64)
	... 231 more

Environment:

  • Infrastructure 0.16.2
  • Kotlin 1.7.0
  • Gradle 7.3.2, 7.5

After some investigation, figured out that the issue occurs only with Kotlin 1.7+ and it looks like not related to infrastructure. Maybe AGP 7.1.3 conflicts with the new version of Kotlin.
Need more time to investigate

Looks like after update to Kotlin Gradle Plugin 1.7.10 the issue gone