개발/안드로이드

[Android] 모듈 갖고 오기

도넛의용기 2023. 9. 5. 11:53

프로젝트에 여러개의 모듈을 두고 쓰고 있는 경우

해당 모듈의 클래스 등을 이용하기 위해서는 implementation을 해주어야 한다.

 

메인으로 사용할 모듈의(여기서는 app 모듈) 빌드에 해당 클래스를 implementation해주도록 하자.

 

dependencies {
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    
    implementation project(path: ':secondappmodule')// 추가한 모듈
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

그리고 secondappmodule에 있는 MyClass를 이용하려면

 

import com.example.secondappmodule.MyClass

위와 같이 import해서 사용해주면 된다.

'개발 > 안드로이드' 카테고리의 다른 글

[Android] 모듈: 코드의 재사용  (1) 2023.08.09
[Android] 패키지 구조  (4) 2023.08.09
[Android] Coroutine(기초)  (2) 2023.05.30
[Android] Utility  (0) 2023.05.30
[Android] Android Weekly  (0) 2023.05.28