[Android] Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 8

이지훈·2024년 3월 21일
0

TL;DR

Android Studio 에 내장된 java jdk 버전을 바꾸지 말고, 컴퓨터에 설치된 java 의 버전을 17이상으로 업데이트하면 해결된다.

문제 발생

새로운 프로젝트에 대한 설정을 완료하고 ktlint, detekt를 github action에 연동하여 잘 실행되는지 테스트를 해보던 중 다음과 같은 에러가 발생하는 것을 확인할 수 있었다.

FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users{username}\AndroidStudioProjects\unifestandroid\build.gradle.kts' line: 4
What went wrong:
Error resolving plugin [id: 'land.sungbin.dependency.handler.extensions', version: '1.1.0']
A problem occurred configuring project ':build-logic'.
Could not resolve all files for configuration ':build-logic:classpath'.
Could not resolve land.sungbin.dependency.handler.extensions:dependency-handler-extensions-plugin:1.1.0.
Required by:
project :build-logic >
land.sungbin.dependency.handler.extensions:land.sungbin.dependency.handler.extensions.gradle.plugin:1.1.0
No matching variant of land.sungbin.dependency.handler.extensions:dependency-handler-extensions-plugin:1.1.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.2' but:
Variant 'apiElements' capability land.sungbin.dependency.handler.extensions:dependency-handler-extensions-plugin:1.1.0 declares a library, packaged as a jar, and its dependencies declared externally:
Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 8
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
Get more help at https://help.gradle.org/.

    - name: Code style checks
      run: ./gradlew ktlintCheck detekt

위와 같은 step 을 github action jobs 내에 추가해두었구(해당 step 에서 fail), 마찬가지로 Android Studio terminal 에서 위 명령어(./gradle ktlintCheck detekt)를 입력할 경우 에러가 발생하였다.

에러에서 언급되고 있는 라이브러리 자체에 문제인가? 생각해 볼 수도 있지만, 해당 라이브러리를 사용하고도 정상적으로 동작하는 프로젝트들이 존재하기 때문에, 라이브러리와 내 프로젝트와의 호환 문제라고 추론할 수 있었다.

그리고 이제 에러 메세지 중에 주요 키워드를 추출해보면

The consumer was configured to find a library for use during runtime, compatible with Java 8

Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 8

먼가 Java 17, 8과 같은 자바 버전과 compatible(호환)이라는 키워드가 반복적으로 나오는 것을 알 수 있는데, 요약하자면 이 컴포넌트(라이브러리)는 자바 17과 호환이 되는데, consumer(문맥상, 프로젝트 또는 애플리케이션)는 Java 8과 호환되는 컴포넌트를 필요로 한다는 내용이다.

따라서 Android Studio 의 Project Structure 에 들어가서 jdk 버전을 jbr17과 같은 java 17버전으로 바꿔봤지만, 같은 에러가 반복되었다...

문제 해결

Android Studio 내에 내장된 jdk 가 아닌, 컴퓨터에 설치된 자바 버전을 17이상으로 업데이트, 설치되어있지 않다면 java 를 17 버전 이상으로 설치해주면 해결된다.

맥의 경우 다음과 같은 명령어로 java 의 버전을 확인할 수 있는데, 17 이상이 설치되어 설정되어있다면, 위와 같은 문제는 더이상 발생하지 않을 것이다.

java --version

관련한 에러가 검색하면 많은 글들이 나오긴하나, Android 가 아닌 대부분 Spring 과 관련한 글이었기 때문에 작성을 해보았다. 같은 언어이고 intellij 기반 IDE, gradle 을 사용하고 있다는 점에서 공통점이 많기에 에러도 공유하나보다. 코프링 먼가 배워볼만 할지도

profile
실력은 고통의 총합이다. Android Developer

0개의 댓글