Android Gradle - Gradle Scripts(2)
모듈 build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion '30'
defaultConfig {
applicationId "test.com.mvpexample"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
implementation "com.android.support:design:$supportLibVersion"
implementation "com.google.dagger:dagger:$daggerVersion"
}
모듈 build.gradle은 각 모듈에 필요한 빌드 설정을 지정할 수 있다
- plugin 설정
- 안드로이드 앱 모듈은 ‘com.android.application’ 지정
- 안드로이드 라이브러리 모듈은 ‘com.android.library’ 지정
- 플러그인은 여러 개 사용 가능하지만 Android 플러그인과 Java 플러그인은 공존할 수 없다
-‘com.android.application’ 플러그인과 ‘com.android.library’ 은 동시에 지정할 수 없다
- android 블록
- 안드로이드용 각종 파라마터를 설정한다.
- compileSdkVersion, buildToolsVersion 설정외에도 manifest를 지정하는 defaultConfig 블록,
서명을 설정하는 signingConfigs, 빌드 타입이나 특성을 지정하는 블록으로 구성된다
- dependencies 블록
1. libs 폴더의 JAR파일을 추가
- implementation fileTree(dir: 'libs', include: ['*.jar'])
2. 외부 라이브러리 참조
- implementation ‘group ID(라이브러리 패키지 이름):artifact ID(라이브러리 이름):version’ :버전명
ex) 'androidx.appcompat:appcompat:1.0.2'
3. 다른 모듈의 소스 코드 참조하기
- implementation project(‘:mylibrary’)
4. AAR(Android Archive package)파일 참조하기
- 라이브러리 압축 파일
- 자바를 개발할때 쓰는 jar(Java Archive package)와 비슷
- lib 폴더에 aar 파일 복사
- app 레벨의 build.gradle 파일의 dependencies에
implementation '[package 명]:[파일 명]:[버전정보]@aar' 넣어주기
- repositories 블록 변경
repositories{
flatDir{
dirs 'libs'
}
}
5. so(JNI)파일 참조하기
- libs 폴더 하위에 플랫폼(ARM/x86)과 32/64bit에 따라 폴더 설정, 그에 맞는 .so 파일을 복사
- 메인 소스의 jniLibs.srcDirs 항목을 libs로 지정
android {
sourceSets{
main{
jniLibs.srcDirs = ['libs']
}
}
}
# api 와 implementation의 차이점
api : 모듈을 수정하면 직접 혹은 간접 의존하는 모듈 모두 재빌드
implementation : 모듈을 수정하면 직접 의존하고 있는 모듈 재빌드
Reference
- 유동환, 안드로이드를 위한 Gradle, 한빛미디어