개발학습일지

[Android Studio] 네트워크 라이브러리 _ Retrofit2 라이브러리 사용을 위한 설정 본문

Android Studio

[Android Studio] 네트워크 라이브러리 _ Retrofit2 라이브러리 사용을 위한 설정

처카푸 2024. 6. 13. 16:02

네트워크 라이브러리 

_ Retrofit2 라이브러리 사용을 위한 설정

 

1. 오픈 소스 라이브러리를 다운로드한다.

- retrofit2

: 네트워크 통신용 라이브러리

- converter-gson

: json을 바로 클래스로 만들어 주는 라이브러리

 

- logging-interceptor 

: 네트워크를 어떻게 주고 어떻게 받았는지 확인할 수 있는 개발자용 라이브러리이다.

 

- build.gradle.kts (Module)에 설치하기

dependencies {
    implementation("com.squareup.retrofit2:retrofit:2.11.0")
    implementation("com.squareup.retrofit2:converter-gson:2.11.0")
    implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
    implementation("com.github.bumptech.glide:glide:4.16.0")
}

 

2. 네트워크 권한 설정하기

- app/manifests/AndroidManifest.xml 파일에 작성

<uses-permission android:name="android.permission.INTERNET"/>

 

3. retrofit2 사용 준비 완료!

 

 


* retrofit 오픈 소스 라이브러리

https://github.com/square/retrofit

 

GitHub - square/retrofit: A type-safe HTTP client for Android and the JVM

A type-safe HTTP client for Android and the JVM. Contribute to square/retrofit development by creating an account on GitHub.

github.com

 

*  converter-gson

https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-gson

 

* logging-interceptor 

https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor