안드로이드 hiltAggregateDepsDebug 에러 대안
Dagger 2.50 이상부터 dagger-compiler 내부에서 JavaPoet 라이브러리가 사용되기 시작했다. 이전에는 Hilt와 관련된 클래스 집계 및 코드 생성 작업에서 주로 다른 방식(예: AutoValue 및 직접적인 코드 생성)을 활용했으나, 2.50 버전 이후로 Square의 JavaPoet 라이브러리를 적극적으로 사용하며 내부적인 변화가 발생했다.
2.50 이전의 방식과 비슷하게 사용해서 프로젝트를 빌드한 경우의 Gradle Sync Issue다.
> Task :presentation:hiltAggregateDepsDebug FAILED
Unable to find method ''java.lang.String com.squareup.javapoet.ClassName.canonicalName()''
'java.lang.String com.squareup.javapoet.ClassName.canonicalName()'
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에 다음을 작성
hilt {
enableAggregatingTask = false
}
Hilt는 기본적으로 Aggregating Task를 사용하여, 모든 애노테이션 프로세싱 결과를 하나의 중앙 집계 파일에 모아 코드 생성을 수행한다. 하지만, 특정 환경에서, 특히 JavaPoet 라이브러리의 버전 불일치나 Gradle 설정 문제로 인해 canonicalName() 메서드를 찾지 못하는 문제가 발생할 수 있다고 한다.
enableAggregatingTask = false를 설정하면, Hilt가 비집계(non-aggregating) 모드로 작동한다. 이 모드는 집계를 위해 전체 클래스 경로를 분석하지 않고 개별적인 소스 파일로 나눠 처리하고 결과적으로, 문제가 발생하는 메서드 호출을 피할 수 있다.
<대안>의 방식을 사용한다면, 집계 방식이 달라지므로 빌드 속도나 코드 생성 방식에 약간의 영향을 미칠 수 있다.
아직 어떤 부분에서 충돌이 발생하는지 정확하게 찾지 못했으며, 발견한다면 해결 방법을 업데이트 하겠다.
- Reference