Android Studio 에 androidannotations 적용하기 (1)
안드로이드 스튜디오( Android Studio )에다가 androidannotations 적용하기가 여간 까다롭네요.
이전에 올라왔던 글들을 보면 업데이트가 되서 그런지 않되는 경우가 많이 있구요,
그래서 최신버전으로 다시 적용 방법을 보겠습니다.
이글은 2015-05-04일에 작성되었습니다.
우선 프로젝트를 생성한 이후 Gradle Scripts를 확인해 보시면 build에 관련하여
두개의 gradle을 확인 하실 수있습니다.
두개의 gradle중 Module: app 을 선택하여 진입합니다.
프로젝트 생성시 기본적인 셋팅이 되어있는 것을 확인 하실수 있습니다.
우리는 androidannotations를 셋팅하기위해서 gradle 의 내용을 바꾸어 줘야 합니다.
buildscript {
repositories {
mavenCentral()
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:1.0+' // 버전에 맞게 변경.
// the latest version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
mavenCentral()
mavenLocal()
}
apply plugin: 'android'
apply plugin: 'android-apt'
def AAVersion = '3.3' // 현재 최신버전 3.3으로 되어있으나 버전에 따라 변경.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'org.androidannotations:androidannotations:3.3'
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName '[현재 프로젝트의 패키지]'
}
}
android {
compileSdkVersion 21
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "[현재 프로젝트의 패키지]"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
sourceSets {
main {
// manifest.srcFile 'src/main/AndroidManifest.xml'
// java.srcDirs = ['src/main/java']
// resources.srcDirs = ['src/main/resources']
// res.srcDirs = ['src/main/res']
// assets.srcDirs = ['src/main/assets']
}
}
}
위에 내용으로 바꾸어 줍니다.
버전에 맞게 내용을 변경 하시면 됩니다.
그리고 [현재 프로젝트의 패키지]를 자신의 프로젝트에 맞게 변경하시면 됩니다.
제가 사용하는 패키지는 "tc.wo.mbseo.applyandroidannotations" 이기 때문에 맞게 변경합니다.
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'tc.wo.mbseo.applyandroidannotations'
}
}
defaultConfig {
applicationId "tc.wo.mbseo.applyandroidannotations"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
저장한 이후 rebuild project 합니다.
이제 실행하시면 됩니다.
위와 같이 나오면 정상적으로 적용된것입니다.