Android 응용 프로그램(APK)의 컴 파일 패키지 과정
 우리 가 중점적으로 관심 을 가 지 는 것 은(1)이 과정의 입력 은 무엇 입 니까?(2)이 과정의 출력 은 무엇 입 니까?(3)이 과정 에서 어떤 도 구 를 사 용 했 습 니까?어떤 인 자 를 사용 하 는 지 에 대해 서 는 명령 에 대응 하 는 도움말 파일 을 직접 보 거나 인터넷 에서 검색 할 수 있 습 니 다.이것 은 본 고의 중점 이 아 닙 니 다.
aapt->
aidl -> javac-> dx(dex)-> apkbuilder-> jarsigner-> zipalign
단계 에서 언급 한 도 구 는 다음 표 와 같다.
명칭.
기능 소개
운영 체제 에서 의 경로
aapt
Android 자원 패키지 도구
${ANDROID_SDK_HOME}/platform-tools/appt
aidl
Android 인터페이스 기술 언어 가 자바 파일 로 바 뀌 는 도구
${ANDROID_SDK_HOME}/platform-tools/aidl
javac
Java Compiler
${JDK_HOME}/javac 또는/usr/bin/javac
dex
Davik VM 에서 식별 할 수 있 는.dex 파일 로.class 파일 전환
${ANDROID_SDK_HOME}/platform-tools/dx
apkbuilder
apk 패키지 생 성
${ANDROID_SDK_HOME}/tools/opkbuilder
jarsigner
.jar 파일 서명 도구
${JDK_HOME}/jarsigner 또는/usr/bin/jarsigner
zipalign
바이트 코드 정렬 도구
${ANDROID_SDK_HOME}/tools/zipalign
첫 번 째 단계:자원 파일 을 압축 하여 R.자바 파일 생 성
R.자바 류 를 컴 파일 하려 면 Androidsdk 가 제공 하 는 aapt 도 구 를 사용 해 야 합 니 다.aapt 매개 변수 가 많 습 니 다.다음은 주요 매개 변수 입 니 다.
-d one or more device assets to include, separated by commas 
 -f force overwrite of existing files 
 -g specify a pixel tolerance to force images to grayscale, default 0 
 -j specify a jar or zip file containing classes to include 
 -k junk path of file(s) added 
 -m make package directories under location specified by -J 
 -u update existing packages (add new, replace older, remove deleted files) 
 -v verbose output 
 -x create extending (non-application) resource IDs 
 -z require localization of resource attributes marked with 
 localization="suggested" 
 -A additional directory in which to find raw asset files 
 -G A file to output proguard options into. 
 -F specify the apk file to output 
 -I add an existing package to base include set 
 -J specify where to output R.java resource constant definitions 
 -M specify full path to AndroidManifest.xml to include in zip 
 -P specify where to output public resource definitions 
 -S directory in which to find resources. Multiple directories will be scann aapt 컴 파일 R.java 파일 은 구체 적 으로 다음 과 같 습 니 다.프로그램 디 렉 터 리 에 들 어가 야 합 니 다.gen 디 렉 터 리 를 새로 만 듭 니 다.gen 디 렉 터 리 가 없 으 면 명령 에 파일 을 찾 을 수 없 는 오류 가 발생 합 니 다!
명령 이 성공 적 으로 실행 되면 gen 디 렉 터 리 에서 패키지 구조의 디 렉 터 리 트 리 와 R.자바 파일 을 생 성 합 니 다!
열:
두 번 째 단계:AIDL 파일 을 처리 하고 해당 하 는 자바 파일 을 생 성 합 니 다.(물론 AIDL 을 사용 하지 않 은 프로젝트 가 많 습 니 다.이 과정 을 절약 할 수 있 습 니 다)
.aidl 파일 을.java 파일 로 만 들 려 면 AndroidSDK 가 자체 적 으로 가지 고 있 는 aidl 도 구 를 사용 해 야 합 니 다.이 도구 의 구체 적 인 매개 변 수 는 다음 과 같 습 니 다.
-I<DIR> search path for import statements. 
-d<FILE> generate dependency file. 
-p<FILE> file created by --preprocess to import. 
-o<FOLDER> base output folder for generated files. 
-b fail when trying to compile a parcelable. 주의해 야 할 것 은 이 도구 의 매개 변수 와 매개 변수 값 사이 에 빈 칸 이 있어 서 는 안 되 며 Google 에 도 임금 에 만족 하지 않 는 엔지니어 가 있 습 니 다!예:
 세 번 째 단계:자바 파일 을 컴 파일 하여 대응 하 는.class 파일 을 생 성 합 니 다.
javac 명령 은 다음 과 같 습 니 다:
가능 한 옵션 은 다음 과 같 습 니 다.
 -g           
 -g:none            
 -g:{lines,vars,source}           
 -nowarn          
 -verbose                    
 -deprecation          API      
 -classpath <  >                     
 -cp <  >                      
 -sourcepath <  >              
 -bootclasspath <  >            
 -extdirs <  >              
 -endorseddirs <  >              
 -proc:{none,only}            /   。 
 -processor <class1>[,<class2>,<class3>...]             ;          
 -processorpath <  >               
 -d <  >                
 -s <  >                
 -implicit:{none,class}                  
 -encoding <  >              
 -source <  >              
 -target <  >      VM        
 -version       
 -help            
 -Akey[=value]              
 -X             
 -J<  >      <  >          예:
 
javac -encoding utf-8 -target 1.5 -bootclasspath E:\Androiddev\android-sdk-windows2.2\platforms\android-3\android.jar -d bin src\com\byread\reader\*.java gen\com\byread\reader\R.java 네 번 째 단계:.class 파일 을 Davik VM 이 지원 하 는.dex 파일 로 변환 합 니 다.프로젝트 빈 디 렉 터 리 의 class 파일 을 classes.dex 로 컴 파일 합 니 다.Android 가상 머 신 은 dex 파일 만 실행 할 수 있 습 니 다!
예:
 다섯 번 째 단계:서명 되 지 않 은.apk 파일 을 압축 하여 생 성 합 니 다.
[입력]포 장 된 자원 파일,포 장 된 클래스 파일(.dex 파일),libs 파일(.so 파일 포함,물론 많은 프로젝트 에 이런 파일 이 없습니다.C/C++개발 을 사용 하지 않 으 면)
[출력]서명 되 지 않 은.apk 파일
[도구]apkbuilder 도구
apkbuilder 도구 사용법 은 다음 과 같 습 니 다.
-v Verbose. 
-d Debug Mode: Includes debug files in the APK file. 
-u Creates an unsigned package. 
-storetype Forces the KeyStore type. If ommited the default is used. 
-z Followed by the path to a zip archive. 
 Adds the content of the application package. 
-f Followed by the path to a file. 
 Adds the file to the application package. 
-rf Followed by the path to a source folder. 
 Adds the java resources found in that folder to the application 
 package, while keeping their path relative to the source folder. 
-rj Followed by the path to a jar file or a folder containing 
 jar files. 
 Adds the java resources found in the jar file(s) to the application 
 package. 
-nf Followed by the root folder containing native libraries to 
 include in the application package.<span style="color: rgb(0, 0, 255); font-family:   ; line-height: 20px;font-size:18px; ">I:    ,  jarsigner            APK      </span> 
열:
apkbuilder ${output.apk.file} -u -z ${packagedresource.file} -f ${dex.file} -rf ${source.dir} -rj ${libraries.dir} 여섯 번 째 단계:서명 되 지 않 은.apk 파일 에 서명 하기[입력]서명 되 지 않 은.apk 파일
[출력]서명 한.apk 파일
[도구]jarsigner
  :jarsigner [  ] jar      
jarsigner -verify [  ] jar    
[-keystore <url>]            
[-storepass <  >]                 
[-storetype <  >]           
[-keypass <  >]             (    ) 
[-sigfile <  >]      .SF/.DSA       
[-signedjar <  >]          JAR       
[-digestalg <  >]          
[-sigalg <  >]            
[-verify]                 JAR    
[-verbose]           /          
[-certs]                         
[-tsa <url>]                 
[-tsacert <  >]                   
[-altsigner < >]                 
[-altsignerpath <    >]            
[-internalsf]                .SF    
[-sectionsonly]                  
[-protected]                   
[-providerName <  >]         
[-providerClass < >               
[-providerArg <  >]] ...              
STEP 7:서명 한.apk 파일 정렬(정렬 처리 하지 않 으 면 Google Market 에 게시 할 수 없 음)[입력]서명 한.apk 파일
[출력]정렬 된.apk 파일
[도구]zipalign 도구
이러한 세부 사항 을 알 게 된 후에 우 리 는 우리 가 실현 하고 싶 은 것 을 많이 실현 할 수 있다.예 를 들 어 자동화,우 리 는 어떤 스 크 립 트 를 사용 할 수 있다.예 를 들 어 윈도 우즈 의 일괄 처리,linux 의 Bash,자바 의 Ant,Python,Perl 과 같은 스 크 립 트 언어,심지어 자바,.net 등 강 한 유형의 언어 를 직접 사용 해도 된다.
이상 은 본 고의 모든 내용 입 니 다.본 고의 내용 이 여러분 의 학습 이나 업무 에 어느 정도 도움 이 되 기 를 바 랍 니 다.또한 저 희 를 많이 지지 해 주시 기 바 랍 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.