通过ant脚本,编译打包android工程

通过ant脚本,编译打包android工程


1.Android程序编译、打包、签名、发布的三种方式: 
方式一:命令行手动编译打包 
方式二:使用ant自动编译打包 
方式三:使用eclipse+ADT编译打包 

2.Android编译、打包的步骤: 
2.1第一步 生成R.java类文件: 
Eclipse中会自动生成R.java,ant和命令行使用android SDK提供的aapt.ext程序生成R.java。 

2.2第二步 将.aidl文件生成.java类文件: 
Eclipse中自动生成,ant和命令行使用android SDK提供的aidl.exe生成.java文件。 

2.3第三步 编译.java类文件生成class文件: 
Eclipse中自动生成,ant和命令行使用jdk的javac编译java类文件生成class文件。 

2.4第四步 将class文件打包生成classes.dex文件: 
Eclipse中自动生成,ant和命令行使用android SDK提供的dx.bat命令行脚本生成classes.dex文件。 

2.5第五步 打包资源文件(包括res、assets、androidmanifest.xml等): 
Eclipse中自动生成,ant和命令行使用Android SDK提供的aapt.exe生成资源包文件。 

2.6第六步 生成未签名的apk安装文件: 
Eclipse中自动生成debug签名文件存放在bin目录中,ant和命令行使用android SDK提供的apkbuilder.bat命令脚本生成未签名的apk安装文件。 

2.7第七步 对未签名的apk进行签名生成签名后的android文件: 

Eclipse中使用Android Tools进行签名,ant和命令行使用jdk的jarsigner对未签名的包进行apk签名。 


通过ant脚本,编译打包android工程_第1张图片

通过命令打包的脚本:见附件bulid0.xml,这个ant脚本只能编译打包一个单独的android工程或依赖一个library 的android工程




	
	
	

	
	
	
	
	
	
	
	
	
	
	
	
	

	
	
	
	
	
	

	
	

	
	

	
	
	
	

	
	
	
	
	
	
	
	
	
	
	

	
	
	

	
	
	
	

	
	
	

	
	
	

	
	

	
	
	


	
	
		Initializing all output directories...
		
		
		
	

	
	
		Generating R.java from the resources...
		


		

			

			

			

			

			

			

			

			

			

			

			

			

			

			

			

			

			

		
	


	
	
		Compiling .aidl into java files...
		
			
			
			
			
			
			
			
			
				
			
		
	

	
	
		Compiling java source code...
		
			
			
			
			
				
				
				
					
				
			
		
	

	
	
		Converting compiled files and external libraries into a .dex
			file...
		
		
			
			
			
			
			
			
			
		
	


	
	
	
		Packaging resources and assets...
		
			
			
			
			
			
			

			
			

			
			

			
			

			
			
			
			

			
		
	


	
	
		Packaging unsigned apk for release...
		
			
			
			
			
			
			
			
			
			
			
			
		
		It will need to be signed with jarsigner before being published.
		
	


	
	
		Packaging signed apk for release...
		
			
			
			
			
			
			
			
			
			
			
			
		
	

	
	
		
		
		APK is released. path:${out-signed-package-ospath}
	





Android官方提供的打包脚本: 1400多行,我加了中文注释,希望能看懂。

详见build.xml



	
	
	
	
	
	
	

	
	

	
	

	
	

	


	
	
	

	
	
	
	
	

	
	
	
	

	
	

	
	
	
	
	
		
	

	
	

	

	

	

	

	

	

	

	

	
	
	
		
		
	
	
	


	
	

	
	
	
	
	
	
	
	
	

	
	
	
	
	

	
	
	
	
		
	
	
		
	
	
	
	
	
	
	

	
	
	
	

	
	


	
	
		
	

	
	
	
		
			
			
			
		
	
	
		
			
			
			
		
	

	
	

	
	

	
	
	
		
		
		
			
				
					
				
				
					@{elseText}
				
			
		
	

	
	
		
		
		
			
				
					
				
				
					
						
							
						
						
							@{elseText}
						
					
				
			
		
	


	
	
		
		
		
			
			

			
			
				
					
				
				
					
						
					
				
			

			
				
				
				
			
		
	

	
	
		
		
			
				
				
				
				
				
				
			
		
	

	
	
		
		
		
			
		
	

	
		
		
		
			Running tests ...
			
				
				
				
				
				
				
				
				
				
				
			
		
	

	
		
		
		
			
				
			
		
	

	
		
			
			
			
			
		
	

	
		
		
			Uninstalling @{app.package} from the default emulator or device...
			
				
				
				
			
		
	

	

	
	

	
	
		
		

		
		
			
				
				
					
					
					
				
			
		

		
			
				
			
			
				
				
					
					
				
			
		
	

	
	
		
			
				
					
				
			
			
				
				Gathering info for ${ant.project.name}...
				
				

				
				
					
				
				
					
				

				
				
					
						
					
				
			
		
	

	
	

		
		
		
		
		
		
		
		

		
		
			
				
			
			
				Building Libraries
				
				
				
				############################################
				**** Back to project ${ant.project.name} ****
				############################################
			
		

		
		
			
				
				
					
				

				Building tested project at ${tested.project.absolute.dir}
				
					
				
				
				
				############################################
				**** Back to project ${ant.project.name} ****
				############################################
			
		

		
		

		
		
			
			
		

		
		
			
				
					
					
				
			
			
				Switching from instrumented to non-instrumented build.
				Deleting previous compilation output:
				
			
		

		Creating output directories if needed...
		
		
		
		
		
			
			
		
	

	
	

	
	
		
			----------
			Handling aidl files...
			
				
			

			
			----------
			Handling RenderScript files...
			
				
			

			----------
			Handling Resources...
			
				
			
		
	

	
	

	
	
		
			
			
				
			
			
				
			
			
				
				
				
					
				
			
			
			
				
					Creating library output jar file...
					
					
						
							
						
						
							Custom jar packaging exclusion: ${android.package.excludes}
						
					
					
						
						
					
				
			

			
			
				
					Instrumenting classes from ${out.absolute.dir}/classes...
					
					
						
						
						
					
				
			
		
	

	
	

	
	
		
			
				
				
				
				
				

				
				
				

				
				
					
						
						
					
				

				
				
					
					
				
				
				
					
						
						
					
				

				
				
				
				
				
                    @${proguard.config}
                    -injars       ${project.jars}
                    -outjars      "${obfuscated.jar.file}"
                    -libraryjars  ${android.libraryjars}
                    -dump         "${obfuscate.absolute.dir}/dump.txt"
                    -printseeds   "${obfuscate.absolute.dir}/seeds.txt"
                    -printusage   "${obfuscate.absolute.dir}/usage.txt"
                    -printmapping "${obfuscate.absolute.dir}/mapping.txt"
                
			
		
	

	
	
		
			
			
				
				
					
						
							
								
							
						
					
					
						
					
				
			
		
	

	
	
		
			
			
			
			
			
			
		
	

	
	
		
		
			
				
				
				
				
			
		
	

	
	
		
		
			
				
					
						
							
							
						
					
				
				
					
				
			
		
	

	
		
	

	

	
	
	

		
		
	

	
		
		

		

		
		

		
		

	

	
	
		
		
	

	
	
		
		
			
				
				Debug Package: ${out.final.file}
			
		
	

	
	
		
	


	
	

	
	
		
		
		
	

	
	
		
		
			
				No key.store and key.alias properties found in build.properties.
				Please sign ${out.packaged.file} manually
				and run zipalign from the Android SDK tools.
			
		
		
	


	
	
		
			
				
				
			
		
		
			
				
				
			
		
	

	
		
		

		
		

		

		
		

		
		

		
			
				*************************************************
				****  Android Manifest has debuggable=true   ****
				**** Doing DEBUG packaging with RELEASE keys ****
				*************************************************
			
			
				
				
			
		
	

	
	

		
		
			
				

				
				Signing final apk...
				

				
				
				Release Package: ${out.final.file}
			
		
		
	

	
	

	

	
		
		

		
		
	

	
	
		
		
			
				
				Instrumented Package: ${out.final.file}
			
		
		
	

	
	

	
	
		
	

	
	
		
		
			
				
			
			
				
			
		
	

	

		

		

		
		
		

		

		
			
				WARNING: Code Coverage is currently only supported on the emulator and rooted devices.
				
					
						
						
						
					
				
				Downloading coverage file into project directory...
				
					
					
					
					
				
				Extracting coverage report...
				
					
						
						
							
							
						
						
						
					
				
				Cleaning up temporary files...
				
				
				Saving the report file in ${basedir}/coverage/coverage.html
			
			
				
			
		
	


	
	

	
		
		
			
				
					
				
				
					
						
							
								
							
						
						
							Installing ${out.final.file} onto default emulator or device...
							
								
								
								
								
							

							
							
							
								
									
								
								
									

									
									
										
									
									
										
									
								
							
						
						
							
						
					
				
				
					Install file not specified.
					
					
					'ant install' now requires the build target to be specified as well.
					
					
					
					
					    ant debug install
					    ant release install
					    ant instrument install
					This will build the given package and install it.
					
					
					Alternatively, you can use
					    ant installd
					    ant installr
					    ant installi
					    ant installt
					to only install an existing package (this will not rebuild the package.)
					
				
			
		
	

	
	
	
	


	
	
		
		

		
			
				
			
			
				
			
			
				Could not find application package in manifest. Cannot run 'adb uninstall'.
			
		

		
		
		
			
				
			
			
				

				
				
				
					
						
					
					
						
					
					
						Could not find tested application package in manifest. Cannot run 'adb uninstall'.
					
				
			
		

	


	
		
		Android Ant Build. Available targets:
		   help:      Displays this help.
		   clean:     Removes output files created by other targets.
		              The 'all' target can be used to clean dependencies
		              (tested projects and libraries)at the same time
		              using: 'ant all clean'
		   debug:     Builds the application and signs it with a debug key.
		   release:   Builds the application. The generated apk file must be
		              signed before it is published.
		   instrument:Builds an instrumented package and signs it with a
		              debug key.
		   test:      Runs the tests. Project must be a test project and
		              must have been built. Typical usage would be:
		                  ant [emma] debug installt test
		   emma:      Transiently enables code coverage for subsequent
		              targets.
		   install:   Installs the newly build package. Must either be used
		              in conjunction with a build target (debug/release/
		              instrument) or with the proper suffix indicating
		              which package to install (see below).
		              If the application was previously installed, the
		              application is reinstalled if the signature matches.
		   installd:  Installs (only) the debug package.
		   installr:  Installs (only) the release package.
		   installi:  Installs (only) the instrumented package.
		   installt:  Installs (only) the test and tested packages.
		   uninstall: Uninstalls the application from a running emulator or
		              device.
	



你可能感兴趣的:(android_tools,android)