Skip to main content

[Android] using Dependency in Gradle Build, Android Studio

- 2013.08.05 -
 Android Studio 0.2.3 에서는 repositories {} 가 기본적으로 포함되어 있다. 따라서 아래와 같은 이슈는 나타나지 않을 것이다.

Android Studio 에서도 Maven dependency 처럼 외부 library 를 다운받아서 Build 할 수 없을까? 하는 생각에 커뮤니티에 질문한 결과 답을 얻을 수 있었다.

우선, Maven Central Repository 에서 사용하고자 하는 Library 를 검색하여 Grails repository 를 알아야 한다.

예를들어 okhttp 의 Grails repo 는 다음과 같다.

compile 'com.squareup.okhttp:okhttp:1.1.1'

이제 본격적으로 Android Studio 의 build.gradle 에 적용 하도록 하자.

기본적으로 build.gradle 는 아래와 같다.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

dependencies {
    compile "com.android.support:support-v4:18.0.+"
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 17
    }
}

여기서, 검색한 Grails Repo 를 dependencies 에 추가해 주면 된다.

dependencies {
    compile "com.android.support:support-v4:18.0.+"
    compile 'com.squareup.okhttp:okhttp:1.1.1'
}

여기서 주의 할 점은, dependencies 선언한 윗 부분에 repositories 를 다시 선언 해서 mavenCentral()을 사용한다는 것을 재 명시 해 주어야 한다는 점이다. 즉 코드로 보면 아래와 같다.

repositories {
        mavenCentral()
}

dependencies {
    compile "com.android.support:support-v4:18.0.+"
    compile 'com.squareup.okhttp:okhttp:1.1.1'
}

결과적으로 전체 코드는 아래와 같다.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {

    compile "com.android.support:support-v4:18.0.+"
    compile 'com.squareup.okhttp:okhttp:1.1.1'
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 17
    }
}

이렇게 하면 Maven 에서 dependency 를 사용하는 것 처럼 Gradle 에서 도 사용할 수 있다.

Comments

Popular posts from this blog

[Android Application Testing Guide] Chapter3 jar file

Android Application Testing Guide(에이콘) 3장 Sample 을 실행시키기 위해서는 libdummy-0.0.1.jar 가 필요한데, sample file 에는 프로젝트만 존재한다. 결국 jar 를 만들어야 되는데.. ant 빌드다. 어허허... jar 파일이 없으면 예제 진행이 어려우므로. ant build 한 jar 를 첨부. libdummy-0.0.1.jar download

[Python] except, e or except as e?

python 2.x 에서 try-except 문을 활용할 때보면 다음과 같이 두가지 방법을 사용하고 있다. 1. try: pass except ErrorType, e: pass 2. try: pass except ErrorType as e: pass 두가지중 어느것을 써도 무방 하다고 한다. 다만 3.x 에서는 ErrorType as e 방식만을 허용한다고 하니 2.x 부터 습관을 들이는게 좋지 않을까. 그리고 가독성으로 보더라도 as e 방식이 이해도가 더 높다고 생각한다. 어느책에는 1번방식, 어느책에는 2번 방식으로 설명을 해 놓으니 더 어지럽다.ㅠ

[번역] A journey on the Android Main Thread - Part 1

본 문서는 square engineering blog 에 기재된 A journey on the Android Main Thread - Part 1 기사를 번역한 것 입니다. coding horrer 에 왜 우리는 소스 읽는 법 을 배워야 하는가 에 대한 기사 가 있습니다. 안드로이드의 가장 큰 특징 중 하나는 오픈소스 생태계 라는 점 입니다. PSVM (public static void main) public class BigBang {   public static void main ( String ... args ) {     // The Java universe starts here.   } } 모든 자바 프로그램은 public static void main() 메소드를 호출하면서 시작합니다. 이는 자바 데스크탑 프로그램, JEE 서블릿 컨테이너, 안드로이드 애플리케이션 이 모두 동일 합니다. 안드로이드 시스템은 부팅 단계에서 ZygoyteInit 이라 불리는 리눅스 프로세스를 실행합니다. 이 프로세스는 달빅VM 으로, 쓰레드에 안드로이드 SDK 의 대부분의 클래스 를 로드 하고 대기합니다. 새로운 안드로이드 애플리케이션을 시작할 때, 안드로이드 시스템은 ZygoteInit 프로세스를 포크 하게 됩니다. 포크된 자식 프로세스의 쓰레드는 대기를 해제하고, ActivityThread.main() 메소드를 호출합니다. 위키피디아 에 정의된 zygote 란 수정란을 의미합니다. Loopers 계속 진행하기 앞서, 우리는 Looper (이하 루퍼) 클래스를 살펴 볼 필요가 있습니다. 루퍼를 사용하는 것은 하나의 쓰레드가 메시지들을 연속해서 실행하도록 하는 좋은 방법 입니다. 각각의 루퍼는 메시지 객체의 큐를 지니고 있습니다. (이를 메시지 큐 MessageQueue 라고 합니다.) 루퍼는...