pinkred's mobile program

pinkred mobile programer

Archive for 1월 2017

Android Jack Compiler

leave a comment »

전혀 알지 못한 컴파일러 였다. 이 컴파일러를 아는데 도움을 준 realm강의 고마움을 표시합니다.

들어봤으면 해보고 싶은 마음이 굴뚝 같아서 진행해보기로하였다. 구글 가이드 문서

1.일단 가장 간단하게 Jack Compiler를 Gradle에 넣는다. (참고 : http://tools.android.com/tech-docs/jackandjill)

android {
...
buildToolsVersion ‘25.0.2’
defaultConfig {
// Enable the experimental Jack build tools.
jackOptions {
enabled true
}
}
...
}

여기서 만일 java 1.8버전의 문법 약간이나마 사용하고 싶은 경우에는

android {
...
buildToolsVersion ‘21.1.2’
defaultConfig {
// Enable the experimental Jack build tools.
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

...
}

2. 이후 컴파일 후에 APT에 이슈가 발생하였다. 몰랐는데 APT가 2.2.0이후 버전인가에서는 APT가 통합되어 있어서 APT 로 시작하는 ‘com.neenbedankt.android-apt’ 여러가지 라이브러리를 삭제하고 다음과 같이 넣어주면 된다.(참조 : https://github.com/nickwph/annotation-processor-with-java8-jack-and-jill-android)

dependencies {
 // dagger 2
 compile 'com.google.dagger:dagger:2.5'
 annotationProcessor 'com.google.dagger:dagger-compiler:2.5'
 // auto-value
 compile 'com.google.auto.value:auto-value:1.2'
 annotationProcessor 'com.google.auto.value:auto-value:1.2'
 // butterknife
 compile 'com.jakewharton:butterknife:8.1.0'
 annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0'
 // logan square
 compile 'com.bluelinelabs:logansquare:1.3.6'
 annotationProcessor 'com.bluelinelabs:logansquare-compiler:1.3.6'
}

3. 기존에 오래된 라이브러리가 지원을 하지 않는 경우가 발생 하였다. Google Conversion Tracking and Remarketing for Android의 라이브러리가 지원하지 않아 문제였는다. 다행이 사용하지 않는 라이브러리여서  과감히 삭제후 재 빌드.

4. 거의다 왔다. 컴파일을 시작해보자. 빌드 시간이 대략 15분 걸렸다. ㅜㅜ 생각보다 너무 오래 걸려서 놀랐다 2번 연속으로 하면 out of memory 가 발생하기도 한다. 충분한 android studio 에 메모리를 잡아주었지만 발생하였다.

5. 결과는 기존 릴리즈 버전은 8.8메가 정도의 APK 크기이고 Jack Compiler을 이용해서 릴리즈 버전을 생성시키면 8.4메가 정도의 APK 가 생성된다. 고생 무지 했는데 0.4메가 줄임. ㅜㅜ

6. 여기서 이슈발생 Android 5.0이하에서는 MultiDex가 제대로 동작하지 않아서 실행시 “java.lang.NoClassDefFoundError” 가 발생하여 앱이 종료된다.

7. https://code.google.com/p/android/issues/detail?id=213483 나온데로 진행해 보았지만 아직 안됨. 추후에 MultiDex 이슈가 해결되면 다시 진행해 볼 예정입니다.

Written by pinkredmobile

2017/01/19 at 5:50 pm