dependency-analysis-gradle-plugin icon indicating copy to clipboard operation
dependency-analysis-gradle-plugin copied to clipboard

Could not create an instance of type com.android.build.api.component.analytics.AnalyticsEnabledLayered

Open CChuYong opened this issue 1 year ago • 4 comments

Build scan link build scan link

Plugin version 1.29.0

Gradle version 8.2

JDK version 17.0.2

(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version org.jetbrains.kotlin.android => 1.8.10

(Optional) Android Gradle Plugin (AGP) version com.android.application => 8.2.1

Describe the bug ./gradlew buildHealth or ./gradlew app:projectHealth makes same exception

> Could not create task ':app:explodeXmlSourceBenchmarkTest'.
   > Could not create an instance of type com.android.build.api.component.analytics.AnalyticsEnabledLayered.
      > Null value provided in parameters [null, id: 3

To Reproduce Steps to reproduce the behavior:

  1. ./gradlew buildHealth

CChuYong avatar Jan 26 '24 10:01 CChuYong

Thanks for the issue!

Hopefully the build scan will be enough, but do you have a minimal reproducer?

autonomousapps avatar Jan 26 '24 19:01 autonomousapps

Sure. Here's my same dependency copied version of my project Archieve.zip

CChuYong avatar Jan 27 '24 03:01 CChuYong

I had this same issue, seems that it works fine on 1.28.0 👍

mrjano avatar Jan 31 '24 11:01 mrjano

I had this same issue, seems that it works fine on 1.28.0 👍

Yes, it seems likely this was caused by the migration to the new, non-deprecated AGP APIs in 1.29.0.

autonomousapps avatar Feb 01 '24 00:02 autonomousapps

I had this same issue, seems that it works fine on 1.28.0 👍

This solved my issue of "com.android.build.api.component.analytics.AnalyticsEnabledLayered", but another error "org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunnerKt" has been occured.

For anyone who using jetpack compose with this plugin, set root kotlin version to 1.9.0 like

plugins {
    id("org.jetbrains.kotlin.android") version "1.9.0" apply false
}

and set app module's compose compiler version to 1.5.0 (due to kotlin version compatibility) as

composeOptions {
    kotlinCompilerExtensionVersion = "1.5.0"
}

this solved my issue.

CChuYong avatar Feb 09 '24 03:02 CChuYong

I cannot reproduce this issue with the reproducer provided, and the changes suggested in this comment. This seems like it might be a Kotlin incompatibility. This plugin currently uses Kotlin 1.9 and is only tested against Kotlin 1.9. Removing from the next milestone until I have reason to believe the problem is in this plugin itself.

autonomousapps avatar Feb 13 '24 23:02 autonomousapps

Resolved via https://github.com/autonomousapps/dependency-analysis-gradle-plugin/pull/1132

autonomousapps avatar Feb 14 '24 23:02 autonomousapps

Still experiencing this with the plugin 1.30.0

Could not determine the dependencies of task ':common-android:synthesizeProjectViewDebug'.
> Could not create task ':common-android:explodeXmlSourceDebug'.
   > Could not create an instance of type com.android.build.api.component.analytics.AnalyticsEnabledLayered.
      > Null value provided in parameters [null, id: 1
        is_debug: true
        minify_enabled: false
        variant_type: LIBRARY
        min_sdk_version {
          api_level: 24
        }
        target_sdk_version {
          api_level: 24
        }
        dex_builder: D8_DEXER
        dex_merger: D8_MERGER
        test_execution: HOST
        ...
        
        
org.gradle.api.internal.tasks.TaskDependencyResolveException: Could not determine the dependencies of task ':common-android:synthesizeProjectViewDebug'.
	at org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext.getDependencies(CachingTaskDependencyResolveContext.java:68)
	...
Caused by: org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type com.android.build.api.component.analytics.AnalyticsEnabledLayered.
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:69)
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:55)
	at org.gradle.api.internal.model.DefaultObjectFactory.newInstance(DefaultObjectFactory.java:90)
	at com.android.build.api.component.analytics.AnalyticsEnabledSources.getRes(AnalyticsEnabledSources.kt:69)
	at com.android.build.api.component.analytics.AnalyticsEnabledSources_Decorated.getRes(Unknown Source)
	at com.autonomousapps.internal.analyzer.DefaultAndroidSources.getAndroidRes(AndroidSources.kt:85)
	at com.autonomousapps.internal.analyzer.AndroidAnalyzer$registerExplodeXmlSourceTask$1.invoke(AndroidProjectAnalyzer.kt:87)
	at com.autonomousapps.internal.analyzer.AndroidAnalyzer$registerExplodeXmlSourceTask$1.invoke(AndroidProjectAnalyzer.kt:86)

This is with AGP 8.2.0, Kotlin 1.9.22 and compose compiler 1.5.9.

Here is the reproducer: https://github.com/inovait/android-architecture-playground/tree/add_dependency_analysis

matejdro avatar Feb 20 '24 07:02 matejdro

Thanks for the repro link. I note your case is not for test sources, but "production" debug sources. I can also see that the library that is failing has no res (and also no source, but this is unrelated). I'm almost certain this is a bug in AGP itself, but I think I can workaround it... probably by just try/catching the error 😞

autonomousapps avatar Feb 20 '24 17:02 autonomousapps