본문 바로가기
Android/Android Error

안드로이드 에러 Execution failed for task ':app:checkDebugDuplicateClasses'. 원인 및 해결

by 수쓰뎁 2023. 3. 12.


Abstract.

안드로이드 개발에서 Fragment를 생성하여 사용하기로 했다. 이에 따라 Activity와 Fragment를 연결하여 먼저 뼈대를 만들고 정상적으로 연결되었는지 테스트를 했는데,  Execution failed for task ':app:checkDebugDuplicateClasses'.라는 빌드 에러가 발생했다. 상세 내용을 확인해보니 Your project has set `android.useAndroidX=true`, but configuration `:app:debugRuntimeClasspath` still contains legacy support libraries, which may cause runtime issues. This behavior will not be allowed in Android Gradle plugin 8.0. 라는 내용이 나오는데, 문제의 원인은 프로젝트에서 사용하는 라이브러리 중 일부가 AndroidX와 충돌을 일으켜서 발생하는 에러였다.

반응형

1. 에러 내용

Fragment를 만들어서 적용하고 빌드를 실행했더니 다음과 같은 에러가 발생했다.

 

자세한 내용을 확인해보면 Execution failed for task ':app:checkDebugDuplicateClasses'.라는 빌드 에러가 발생한 것인데, 뭔가 중복되는 클래스가 발견되어 충돌이 일어나는 것이었다. 


2. 에러 해결

에러 내용을 천천히 확인해보던 중 아래와 같은 내용을 확인했다. Your project has set `android.useAndroidX=true`, but configuration `:app:debugRuntimeClasspath` still contains legacy support libraries, which may cause runtime issues. This behavior will not be allowed in Android Gradle plugin 8.0. 라고 적혀있는 부분에서 현재 실행하려는 프로젝트에서 AndroidX와 충돌이 일어나는 라이브러리가 있는 것이었다.

에러 내용에서는 친절하게 해결 방법이 나와있다. set 'android.enableJetifier=true' in the 'gradle.properties'라는 부분에서 알려주는대로 gradle.properties 파일을 열어 'android.enableJetifier=true'를 설정해주면 해결된다. 정리하면 다음과 같이 에러를 해결하면 된다.

 

  • gradle.properties 파일 오픈
  • 'android.enableJetifier=true' 추가
  • Sync Now를 눌러 빌드 싱크 실행

 

다음 코드를 gradle.properties에 추가해주면 된다.

android.enableJetifier=true

 

gradle.properties 파일을 열면 다음과 같은 내용을 확인할 수 있다. 여기서 android.enableJetifier=true를 작성해주고 상단 Sync Now를 눌러주면 해당 내용이 적용된다.

useAndroidX=true는 프로젝트 생성 시 자동으로 추가되지만, enableJetifier=true는 적용되지 않는다. 따라서 위와 같이 직접 gradle.properties에 해당 코드를 넣어줘야 한다. enableJetifier는 외부 라이브러리를 안드로이드 스튜디오가 자동으로 rewrite해서 AndroidX와 충돌이 발생하지 않게 도와주는 역할을 한다.

반응형

댓글