Hanbit the Developer

Android AAR Library 추가 방법 본문

Mobile/Android

Android AAR Library 추가 방법

hanbikan 2022. 7. 7. 01:15

배경

필자가 aar 파일을 사용하고자 하였으나 'Error building Android library: Direct local .aar file dependencies are not supported' 같은 오류가 발생하여 방법을 찾아봐도 해결이 쉽지 않았습니다. 이 글에선 어떻게 aar 라이브러리를 추가하는지 알아보겠습니다.

 

모듈 추가

aar 파일을 포함하는 폴더 하나를 만들어서 모듈로서 import 해야합니다. 이를 위해 저는 libs라는 폴더를 바탕화면에 생성했고 이 폴더 내에 aar 파일을 추가하였습니다. 또, build.gradle 파일을 이 폴더 내부에 생성해준 뒤, 아래와 같은 내용을 넣어줍니다.

configurations.maybeCreate("default")
artifacts.add("default", file('YOUR_FILE_NAME.aar'))

*Android Studio 내에서 폴더를 생성한 뒤 두 파일을 넣어주게 되면 Android Studio에서 라이브러리로 인식을 하지 않는 경우가 있었습니다. 따라서 importing the folder as a module을 가능하게 하고자 이런 방법으로 수행했습니다.

 

다음으로 해당 폴더를 모듈로 추가해줍니다.

먼저 프로젝트 최상위 폴더에 우클릭한 뒤, New > Module을 클릭합니다.

다음으로 최하단에 있는 Import를 클릭한 뒤, Soruce directory에서 방금 만든 폴더를 선택한 뒤 적용해줍니다.

 

모듈 의존성 추가

방금 생성한 모듈을, aar을 써야하는 모듈이 implementation을 해주어야 합니다.

File > Project Structure를 눌러준 뒤 Dependencies 항목으로 이동합니다. 우측 All Dependencies 내부에서 aar을 써야할 모듈을 클릭해준 뒤 '+' 버튼 > 3 Module Dependency를 눌러줍니다.

마지막으로 방금 추가한 모듈을 선택하고 적용해줍니다.

 

 

마무리

Sync Project With Gradle Files, Clean Project, Rebuild Project를 해주면 적용이 되는 것을 확인할 수 있습니다!

 

References

https://stackoverflow.com/questions/60878599/error-building-android-library-direct-local-aar-file-dependencies-are-not-supp

 

Error building Android library: Direct local .aar file dependencies are not supported

We recently upgraded to Android Gradle Plugin 4.0.0-beta03. We are now seeing this error when building one of our library modules $ ./gradlew library_module:assemble Execution failed for task ':

stackoverflow.com

https://stackoverflow.com/questions/41373333/how-to-include-different-aar-depending-on-the-android-build-variant

 

How to include different .aar depending on the android build variant

I am having 3 .aar files which are included in a module and the aar module in included in a app module. Currently I have 3 build variants and for specific build variant I want to include specific ...

stackoverflow.com