ANT build System을 통한 Android APK 빌드하기

2012. 6. 25. 14:41·Android Development
반응형

* Android apk build system 구성하기


1. Apache ANT project 에서 ant 설치하기. 

http://ant.apache.org/bindownload.cgi#Verify Releases


다운로드 후 해당 압축파일 해제. 적당한 root directory 에 압축 해제.

내 컴퓨터 속성 --> 시스템 속성 --> 환경변수 --> System Path 에 해당 bin 폴더 경로 추가. 

* 자바 환경 설정.

자바 SDK 설치 후 환경 설정을 해야 한다. 동일하게 path에 java 설치 경로를 추가한다.


2. build.xml 및 default.properties, local.properties 생성하기.

해당 eclipse 작업 폴더에서 

android update project --path "프로젝트폴더명"


* 만약 아래와 같은 에러가 발생할 경우.

Error: The project either has no target set or the target is invalid.

Please provide a --target to the 'android.bat update' command.


android target 버전을 모르는 경우이다. 이런 경우에는,

android list targets 

로 타겟 버전 숫자를 확인하여  android update project -p "<프로젝트명>" -t "타겟숫자" 

로 처리한다.


3. ant 를 통한 apk build 작업 진행.

http://developer.android.com/guide/developing/building/building-cmdline.html


ant 를 통해서 apk build 를 하려면 해당 작업 폴더 root directory 에서 

ant release  또는 ant debug 를 실행한다.


빌드 성공할 경우, 이제 관련된 옵션을 통해서 빌드를 제어할 텐데 관련 내용은 링크 참조. 


* build.xml 

이 파일은 빌드 시 관련된 설정이 들어간 파일이다. 잘 설정해서 사용하면 유용하다.

이와 관련된 내용은 

http://jcstyle.tistory.com/218

링크에 설명이 잘 되어 있다. 


* 빌드 오류가 난다면



 
오류가 난다면 오류내용에 보면 참고 하고 있는 rule의 xml 파일을 알려줍니다.
해당 xml파일을 열어서 자신의 프로젝트에 필요한 부분을 복사해서 build.xml 에 추가하면 문제가 해결 됩니다.
추가할때는 <setup/> 위쪽에 넣어주면 됩니다. 자세한 내용은 build.xml 의 주석부분을 참고하시면 됩니다.

ant의 xml파일은 Makefile 과 비슷하게 target과 depend 란 개념으로 구성되어 있으니 쉽게 이해할 수 있습니다.

${}로 만들어져 있는 변수들은 properties 로 관리가 되는데 자동으로 만들어진 두개의 properties는 android 가 관리하고 있으므로 수정하지 않고 build.properties를 별도로 만들어서 사용합니다.

추가로 사용하는 소스 폴더가 있다면 이것을 여기에  추가해주고 build.xml에서 compile target을 복사해와서 적절히 수정해서 사용해야 합니다.

또한 sign과정을 자동화 하고 싶다면 key와 password를 build.properties 에 등록해두면 됩니다.

build.properties

 1 key.store=../ssbooks_android_keystore
 2 key.alias=ssbooks
 3 key.store.password=1234
 4 key.alias.password=1234
 5
 6 ss.source.dir=../common
~                                


build.xml
35     <property name="ss.source.absolute.dir" location="${ss.source.dir}" />

63     <macrodef name="release-install-helper">
64         <sequential>
65             <echo>Installing ${out.release.file} onto default emulator or device...</echo>
66             <exec executable="${adb}" failonerror="true">
67                 <arg line="${adb.device.arg}" />
68                 <arg value="install" />
69                 <arg value="-r" />
70                 <arg path="${out.release.file}" />
71             </exec>
72         </sequential>
73     </macrodef>
74
75     <target name="ri" depends="release"
76                 description="Installs/reinstalls the debug package onto a running
77                             emulator or device. If the application was previously installed,
78                             the signatures must match." >
79         <release-install-helper />
80     </target>
81
82     <!-- Generates java classes from .aidl files. -->
83     <target name="-ss.aidl" depends="-dirs">
84                 <echo>Compiling aidl files into Java classes...</echo>
85                 <aidl executable="${aidl}" framework="${android.aidl}"
86                         genFolder="${gen.absolute.dir}">
87                     <source path="${ss.source.absolute.dir}"/>
88                     <source refid="android.libraries.src"/>
89                 </aidl>
90     </target>


92     <target name="compile" depends="-resource-src, -ss.aidl, -pre-compile"
93                 description="Compiles project's .java files into .class files">
94         <if condition="${manifest.hasCode}">
95             <then>
96                 <!-- If android rules are used for a test project, its classpath should include
97                      tested project's location -->
98                 <condition property="extensible.classpath"
99                         value="${tested.project.absolute.dir}/bin/classes"
100                         else=".">
101                     <isset property="tested.project.absolute.dir" />
102                 </condition>
103                 <condition property="extensible.libs.classpath"
104                         value="${tested.project.absolute.dir}/libs"
105                         else="./libs">
106                     <isset property="tested.project.absolute.dir" />
107                 </condition>
108                 <javac encoding="euc-kr" target="1.5" debug="true" extdirs=""
109                         destdir="${out.classes.absolute.dir}"
110                         bootclasspathref="android.target.classpath"
111                         verbose="${verbose}"
112                         classpath="${extensible.classpath}"
113                         classpathref="android.libraries.jars">
114                     <src path="${source.absolute.dir}" />
115                     <src path="${ss.source.absolute.dir}" />
116                     <src path="${gen.absolute.dir}" />
117                     <src refid="android.libraries.src" />
118                     <classpath>
119                         <fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
120                         <fileset dir="${extensible.libs.classpath}" includes="*.jar" />
121                     </classpath>
122                 </javac>
123             </then>
124             <else>
125                 <echo>hasCode = false. Skipping...</echo>
126             </else>
127         </if>
128     </target>



대충 이런식입니다.
ss.source 의 내용을 컴파일에 포함시고 ri 라는 target 을 만들어서 signed-release apt파일을 설치하는 것을 추가했습니다.

javac의 encoding의 경우 euc-kr로 설정했다. 소스파일이 utf8로 저장되어 있다면 utf8로 변경하면 됩니다.

이제 ant ri 를 실행하면 signed release apt가 만들어지고 이것은 현재 연결되어 있는 단말기에 install 이 됩니다.

참고로 ant debug 는 기본 target 에 포함되어 있습니다. 그리고 ant install의 경우 debug apt를 install 하는 것이므로 개발 과정에서 사용하면 됩니다. 


저작자표시 비영리 변경금지 (새창열림)

'Android Development' 카테고리의 다른 글

Support Library ( Compatibility Package)  (0) 2012.08.21
OOM 및 LMK 에 대한 정리  (0) 2012.08.21
[MAT] Memory leak analysis tool  (0) 2012.06.08
android.os.TransactionTooLargeException  (0) 2012.06.03
ListView setTextFilterEnabled  (0) 2012.05.02
'Android Development' 카테고리의 다른 글
  • Support Library ( Compatibility Package)
  • OOM 및 LMK 에 대한 정리
  • [MAT] Memory leak analysis tool
  • android.os.TransactionTooLargeException
fogthegreat
fogthegreat
아주 오랫동안 이것 저것 개발하면서 배우고 찾아 본 것들을 적거나 모았습니다. 불편한 점이 있다면 알려주세요. (과거에 불펌한 글들을 모두 제거하고 있는 중이에요. 🙏)
  • fogthegreat
    꿈소년의 개발 이야기
    fogthegreat
  • 전체
    오늘
    어제
    • 전체보기 (242)
      • Software Engineering (56)
      • Android Development (78)
      • 일상다반사 (63)
      • 책에 대한 거의 모든 것 (11)
      • 영어공부 (1)
      • ETC (0)
      • 챌린지 (1)
      • Do it 스터디! (32)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 향로
    • 청하가 제안하는 소프트웨어 엔지니어로써 재미있게 사는 …
    • WhoRU? Story...♡
    • Snapshot
    • 두잇! - 이지스퍼블리싱
    • 제이펍의 참 똑똑한 2비트 책 이야기
    • Inpa Dev
  • 공지사항

  • 인기 글

  • 태그

    java
    하버드
    build.gradle
    보안
    css
    구글
    Eclipse
    js
    C++
    kotlin
    안드로이드 개발
    linux
    gradle
    자바
    Android
    개발
    코틀린
    안드로이드
    hcj
    google
    노개북
    git
    Android 4.1
    html
    리눅스
    안철수
    ActiveX
    JavaScript
    OOM
    탐지기법
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
fogthegreat
ANT build System을 통한 Android APK 빌드하기
상단으로

티스토리툴바