由于是新手,所以从入门文档开始:http://code.google.com/p/zxing/wiki/GettingStarted
1.首先下载库文件
下载地址:http://code.google.com/p/zxing/downloads/list (需要vpn,你懂得)
2.编译
解压后的zxing文件夹中包含core和javase文件包,里面均有build.xml编译配置文件。需要用apache的ant工具来进行编译。ant工具的链接: http://ant.apache.org。
3.Apache ant工具介绍
ant是一个java库和命令行工具,它按照配置文件中的描述来编译文件。ant支持一系列的编译,汇编,测试java代码的功能,并且支持c,c++代码的编译。ant由java代码实现,用户也可以实现自己的”antlib“。
a。确保你已经有了java运行环境
b。下载合适的ant版本,由于我是windows选择zip文件:http://ant.apache.org/bindownload.cgi
c。将bin目录加入PATH环境变量,打开环境变量设置,添加ANT_HOME为ANT的bin路径,在Path环境变量中添加%ANT_HOME%;即可。
d。在cmd命令行执行ant,如下则说明设置成功。
C:\Users\Administrator.YHWY-PC>ant Buildfile: build.xml does not exist! Build failed
4.配置build.properties
将文件中的android-home前面注释去掉,添加android sdk的路径
5.编译zxing
cmd进入到zxing的core路径,输入ant:
E:\zxing-2.1\core>ant Buildfile: E:\zxing-2.1\core\build.xml init: build: [mkdir] Created dir: E:\zxing-2.1\core\build [javac] Compiling 190 source files to E:\zxing-2.1\core\build [javac] 警告: [options] 未与 -source 1.6 一起设置引导类路径 [javac] 注: 某些输入文件使用了未经检查或不安全的操作。 [javac] 注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。 [javac] 1 个警告 [jar] Building jar: E:\zxing-2.1\core\core.jar BUILD SUCCESSFUL Total time: 9 seconds
cmd进入core路径,输入ant build export:
E:\zxing-2.1\core>ant build export Buildfile: E:\zxing-2.1\core\build.xml init: build: init: build: export: [copy] Copying 1 file to E:\zxing-2.1\android\libs [copy] Copying 1 file to E:\zxing-2.1\androidtest\libs BUILD SUCCESSFUL Total time: 1 second
下面的命令负责产生local.properties:
cd ../android
android update project --path .
可能会出现如下错误:
E:\zxing-2.1\android>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 list列出android target id即可,如下,target id 为1.
E:\zxing-2.1\android>android list targets Available Android targets: ---------- id: 1 or "android-17" Name: Android 4.2 Type: Platform API level: 17 Revision: 1 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W XGA720, WXGA800, WXGA800-7in ABIs : armeabi-v7a
E:\zxing-2.1\android>android update project --target 1 --path . Updated project.properties Updated local.properties
生成local.properties文件,下述命令需要修改/path/to/android-sdk为你自己的sdk路径:
echo "sdk.dir=/path/to/android-sdk" > local.properties
编译:
E:\zxing-2.1\android>ant debug Buildfile: E:\wangweibo\zxing-2.1\android\build.xml -set-mode-check: -set-debug-files: -check-env: [checkenv] Android SDK Tools Revision 21.0.1 [checkenv] Installed at E:\wangweibo\adt-bundle-windows-x86\sdk -setup: [echo] Project Name: BarcodeScanner [gettype] Project Type: Application -set-debug-mode: -debug-obfuscation-check: -build-setup: [echo] Resolving Build Target for BarcodeScanner... [gettarget] Project Target: Android 4.2 [gettarget] API level: 17 [echo] ---------- [echo] Creating output directories if needed... [mkdir] Created dir: E:\wangweibo\zxing-2.1\android\bin [mkdir] Created dir: E:\wangweibo\zxing-2.1\android\bin\res [mkdir] Created dir: E:\wangweibo\zxing-2.1\android\bin\classes [mkdir] Created dir: E:\wangweibo\zxing-2.1\android\bin\dexedLibs [echo] ---------- [echo] Resolving Dependencies for BarcodeScanner... [dependency] Library dependencies: [dependency] No Libraries [echo] ---------- [echo] Building Libraries with 'debug'... [subant] No sub-builds to iterate on -pre-build: -code-gen: [mergemanifest] Merging AndroidManifest files into one. [mergemanifest] Manifest merger disabled. Using project manifest only. [echo] Handling aidl files... [aidl] No AIDL files to compile. [echo] ---------- [echo] Handling RenderScript files... [renderscript] No RenderScript files to compile. [echo] ---------- [echo] Handling Resources... [aapt] Found Deleted Target File [aapt] Generating resource IDs... [echo] ---------- [echo] Handling BuildConfig class... [buildconfig] Generating BuildConfig class. -pre-compile: -compile: [javac] Compiling 79 source files to E:\wangweibo\zxing-2.1\android\bin\clas ses [javac] 注: 某些输入文件使用或覆盖了已过时的 API。 [javac] 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 [javac] 注: 某些输入文件使用了未经检查或不安全的操作。 [javac] 注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。 -post-compile: -obfuscate: -dex: [dex] input: E:\wangweibo\zxing-2.1\android\bin\classes [dex] input: E:\wangweibo\zxing-2.1\android\libs\core.jar [dex] Pre-Dexing E:\wangweibo\zxing-2.1\android\libs\core.jar -> core-c273 465cc33a2bfd3bf4d6a6b20f0dea.jar [dex] Converting compiled files and external libraries into E:\wangweibo\z xing-2.1\android\bin\classes.dex... [dx] Merged dex A (132 defs/168.1KiB) with dex B (223 defs/399.0KiB). Res ult is 355 defs/705.5KiB. Took 0.2s -crunch: [crunch] Crunching PNG Files in source dir: E:\wangweibo\zxing-2.1\android\re s [crunch] To destination dir: E:\wangweibo\zxing-2.1\android\bin\res [crunch] Processing image to cache: E:\wangweibo\zxing-2.1\android\res\drawab le-hdpi\launcher_icon.png => E:\wangweibo\zxing-2.1\android\bin\res\drawable-hdp i\launcher_icon.png [crunch] (processed image to cache entry E:\wangweibo\zxing-2.1\android\bin \res\drawable-hdpi\launcher_icon.png: 0% size of source) [crunch] Processing image to cache: E:\wangweibo\zxing-2.1\android\res\drawab le-hdpi\shopper_icon.png => E:\wangweibo\zxing-2.1\android\bin\res\drawable-hdpi \shopper_icon.png [crunch] (processed image to cache entry E:\wangweibo\zxing-2.1\android\bin \res\drawable-hdpi\shopper_icon.png: 0% size of source) [crunch] Processing image to cache: E:\wangweibo\zxing-2.1\android\res\drawab le-xhdpi\launcher_icon.png => E:\wangweibo\zxing-2.1\android\bin\res\drawable-xh dpi\launcher_icon.png [crunch] (processed image to cache entry E:\wangweibo\zxing-2.1\android\bin \res\drawable-xhdpi\launcher_icon.png: 46% size of source) [crunch] Processing image to cache: E:\wangweibo\zxing-2.1\android\res\drawab le-xxhdpi\launcher_icon.png => E:\wangweibo\zxing-2.1\android\bin\res\drawable-x xhdpi\launcher_icon.png [crunch] (processed image to cache entry E:\wangweibo\zxing-2.1\android\bin \res\drawable-xxhdpi\launcher_icon.png: 63% size of source) [crunch] Processing image to cache: E:\wangweibo\zxing-2.1\android\res\drawab le\launcher_icon.png => E:\wangweibo\zxing-2.1\android\bin\res\drawable\launcher _icon.png [crunch] (processed image to cache entry E:\wangweibo\zxing-2.1\android\bin \res\drawable\launcher_icon.png: 0% size of source) [crunch] Processing image to cache: E:\wangweibo\zxing-2.1\android\res\drawab le\share_via_barcode.png => E:\wangweibo\zxing-2.1\android\bin\res\drawable\shar e_via_barcode.png [crunch] (processed image to cache entry E:\wangweibo\zxing-2.1\android\bin \res\drawable\share_via_barcode.png: 0% size of source) [crunch] Processing image to cache: E:\wangweibo\zxing-2.1\android\res\drawab le\shopper_icon.png => E:\wangweibo\zxing-2.1\android\bin\res\drawable\shopper_i con.png [crunch] (processed image to cache entry E:\wangweibo\zxing-2.1\android\bin \res\drawable\shopper_icon.png: 0% size of source) [crunch] Crunched 7 PNG files to update cache -package-resources: [aapt] Creating full resource package... -package: [apkbuilder] Current build type is different than previous build: forced apkbuil der run. [apkbuilder] Creating BarcodeScanner-debug-unaligned.apk and signing it with a d ebug key... -post-package: -do-debug: [zipalign] Running zip align on final apk... [echo] Debug Package: E:\wangweibo\zxing-2.1\android\bin\BarcodeScanner-deb ug.apk [propertyfile] Creating new property file: E:\wangweibo\zxing-2.1\android\bin\bu ild.prop [propertyfile] Updating property file: E:\wangweibo\zxing-2.1\android\bin\build. prop [propertyfile] Updating property file: E:\wangweibo\zxing-2.1\android\bin\build. prop [propertyfile] Updating property file: E:\wangweibo\zxing-2.1\android\bin\build. prop -post-build: debug: BUILD SUCCESSFUL Total time: 25 seconds E:\zxing-2.1\android>
OK,编译成功。
取出新鲜出炉的core.jar即可。