目前支持以下格式:
zxing官网说明:https://github.com/zxing/zxing/wiki/Getting-Started-Developing
源码下载:https://github.com/zxing/zxing
我下载的是releases版本:https://github.com/zxing/zxing/releases
Ant: http://ant.apache.org/bindownload.cgi
Maven: http://maven.apache.org/download.cgi
下载后在合适的目录下解压,将bin目录添加到环境变量,跟JDK方法一样。
这里只配置下ant的环境变量
1.我的电脑右键
2.点击“属性”
3.点击“环境变量”
4.点击“编辑”
添加解压后的bin到Path就可以了,记得用;结束,验证下
配置编译
确保你已经有了java运行环境,如JAVA_HOME、CLASSPATH、PATH都配置好了
进入到zxing-zxing-3.1.0\android目录,输入命令:android update project --path .
D:\zxing\zxing-zxing-3.1.0\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. D:\zxing\zxing-zxing-3.1.0\android>
但提示出错了,需要我们提供一个target,输入命令:android list targets
D:\zxing\zxing-zxing-3.1.0\android>android list targets Available Android targets: ---------- id: 1 or "android-7" Name: Android 2.1 Type: Platform API level: 7 Revision: 3 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854 ABIs : armeabi ---------- id: 2 or "android-8" Name: Android 2.2 Type: Platform API level: 8 Revision: 3 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854 ABIs : armeabi ---------- id: 3 or "android-10" Name: Android 2.3.3 Type: Platform API level: 10 Revision: 2 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854 ABIs : armeabi, x86 ---------- id: 4 or "android-11" Name: Android 3.0 Type: Platform API level: 11 Revision: 2 Skins: WXGA (default) ABIs : armeabi ---------- id: 5 or "android-12" Name: Android 3.1 Type: Platform API level: 12 Revision: 3 Skins: WXGA (default) ABIs : armeabi ---------- id: 6 or "android-13" Name: Android 3.2 Type: Platform API level: 13 Revision: 1 Skins: WXGA (default) ABIs : armeabi ---------- id: 7 or "android-14" Name: Android 4.0 Type: Platform API level: 14 Revision: 3 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W XGA720, WXGA800 ABIs : no ABIs. ---------- id: 8 or "android-15" Name: Android 4.0.3 Type: Platform API level: 15 Revision: 3 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W XGA720, WXGA800 ABIs : no ABIs. ---------- id: 9 or "android-16" Name: Android 4.1.2 Type: Platform API level: 16 Revision: 4 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W XGA720, WXGA800, WXGA800-7in ABIs : no ABIs. ---------- id: 10 or "android-17" Name: Android 4.2.2 Type: Platform API level: 17 Revision: 2 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W XGA720, WXGA800, WXGA800-7in ABIs : no ABIs. ---------- id: 11 or "android-18" Name: Android 4.3 Type: Platform API level: 18 Revision: 1 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W XGA720, WXGA800, WXGA800-7in ABIs : armeabi-v7a, x86 ---------- id: 12 or "android-19" Name: Android 4.4.2 Type: Platform API level: 19 Revision: 3 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W XGA720, WXGA800, WXGA800-7in ABIs : no ABIs. D:\zxing\zxing-zxing-3.1.0\android>根据输出的ID,加上target,命令:android update project --target 7 --path .
D:\zxing\zxing-zxing-3.1.0\android>android update project --target 7 --path . Updated and renamed default.properties to project.properties Updated local.properties No project name specified, using Activity name 'CaptureActivity'. If you wish to change it, edit the first line of build.xml. Added file D:\zxing\zxing-zxing-3.1.0\android\build.xml Added file D:\zxing\zxing-zxing-3.1.0\android\proguard-project.txt D:\zxing\zxing-zxing-3.1.0\android>会生成以下文件
其中:local.properties文件的内容是:SDK的目录
# This file is automatically generated by Android Tools. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # location of the SDK. This is only used by Ant # For customization when using a Version Control System, please read the # header note. sdk.dir=E:\\Android\\adt-bundle-windows-x86\\sdk编译jar包在zxing-zxing-3.1.0\core目录下输入:mvn -DskipTests -Dgpg.skip=true install
D:\zxing\zxing-zxing-3.1.0\core>mvn -DskipTests -Dgpg.skip=true install [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ZXing Core 3.1.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ core --- Downloading: http://repo.maven.apache.org/maven2/classworlds/classworlds/1.1/cla ssworlds-1.1.pom Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util s/2.0.5/plexus-utils-2.0.5.pom Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-f iltering/1.1/maven-filtering-1.1.pom Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte rpolation/1.13/plexus-interpolation-1.13.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.828 s [INFO] Finished at: 2014-07-23T10:46:18+08:00 [INFO] Final Memory: 8M/20M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2 .6:resources (default-resources) on project core: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources failed: Plug in org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencie s could not be resolved: Failed to collect dependencies at org.apache.maven.plug ins:maven-resources-plugin:jar:2.6 -> org.apache.maven:maven-core:jar:2.0.6 -> c lassworlds:classworlds:jar:1.1: Failed to read artifact descriptor for classworl ds:classworlds:jar:1.1: Could not transfer artifact classworlds:classworlds:pom: 1.1 from/to central (http://repo.maven.apache.org/maven2): repo.maven.apache.org : Unknown host repo.maven.apache.org -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit ch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please rea d the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResoluti onException D:\zxing\zxing-zxing-3.1.0\core>出现了以下错误信息,由于需要下载一些东西,但经常被和谐(你懂的),导致无法下载,只能用VPN
[INFO] Installing D:\zxing\zxing-zxing-3.1.0\core\pom.xml to C:\Documents and Se ttings\Administrator\.m2\repository\com\google\zxing\core\3.1.0\core-3.1.0.pom [INFO] Installing D:\zxing\zxing-zxing-3.1.0\core\target\core-3.1.0-javadoc.jar to C:\Documents and Settings\Administrator\.m2\repository\com\google\zxing\core3.1.0\core-3.1.0-javadoc.jar [INFO] Installing D:\zxing\zxing-zxing-3.1.0\core\target\core-3.1.0-sources.jar to C:\Documents and Settings\Administrator\.m2\repository\com\google\zxing\core3.1.0\core-3.1.0-sources.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 04:00 min [INFO] Finished at: 2014-07-23T10:53:25+08:00 [INFO] Final Memory: 18M/67M [INFO] ------------------------------------------------------------------------ D:\zxing\zxing-zxing-3.1.0\core>
运行完之后core目录下会生成一个target目录,其中:core-3.1.0.jar就是我们需要的jar包
在这里时可以直接下载jar包:http://repo1.maven.org/maven2/com/google/zxing/
D:\zxing\zxing-zxing-3.1.0\android>ant debug Buildfile: D:\zxing\zxing-zxing-3.1.0\android\build.xml -set-mode-check: -set-debug-files: -check-env: [checkenv] Android SDK Tools Revision 22.0.5 [checkenv] Installed at E:\Android\adt-bundle-windows-x86\sdk -setup: [echo] Project Name: CaptureActivity [gettype] Project Type: Application -set-debug-mode: -debug-obfuscation-check: -pre-build: -build-setup: [getbuildtools] Using latest Build Tools: 18.0.1 [echo] Resolving Build Target for CaptureActivity... [gettarget] Project Target: Android 4.0 [gettarget] API level: 14 [gettarget] WARNING: Attribute minSdkVersion in AndroidManifest.xml (15) is high er than the project target API level (14) [echo] ---------- [echo] Creating output directories if needed... [echo] ---------- [echo] Resolving Dependencies for CaptureActivity... [dependency] Library dependencies: [dependency] No Libraries [dependency] [dependency] ------------------ [dependency] API<=15: Adding annotations.jar to the classpath. [echo] ---------- [echo] Building Libraries with 'debug'... [subant] No sub-builds to iterate on -code-gen: [mergemanifest] Found Deleted Target File [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 75 source files to D:\zxing\zxing-zxing-3.1.0\android\binclasses [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\DecodeFormatManager.java:59: 错误: -source 1.5 中不支持 diamond 运算符 [javac] FORMATS_FOR_MODE = new HashMap<>(); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\DecodeHintManager.java:58: 错误: -source 1.5 中不支持 diamond 运算符 [javac] Map<String,String> map = new HashMap<>(); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\DecodeThread.java:59: 错误: -source 1.5 中不支持 diamond 运算符 [javac] hints = new EnumMap<>(DecodeHintType.class); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\HttpHelper.java:41: 错误: -source 1.5 中不支持 diamond 运算符 [javac] private static final Collection<String> REDIRECTOR_DOMAINS = new H ashSet<>(Arrays.asList( [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\HttpHelper.java:157: 错误: -source 1.5 中不支持 multi-catch 语句 [javac] } catch (IOException | NullPointerException ioe) { [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 multi-catch 语句) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\LocaleManager.java:46: 错误: -source 1.5 中不支持 diamond 运算符 [javac] GOOGLE_COUNTRY_TLD = new HashMap<>(); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\PreferencesFragment.java:74: 错误: -source 1.5 中不支持 diamond 运算符 [javac] Collection<CheckBoxPreference> checked = new ArrayList<>(checkBo xPrefs.length); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\ViewfinderView.java:72: 错误: -source 1.5 中不支持 diamond 运算符 [javac] possibleResultPoints = new ArrayList<>(5); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\book\SearchBookContentsActivity.java:214: 错误: -source 1.5 中不支持 diamond 运算符 [javac] List<SearchBookContentsResult> items = new ArrayList<>(cou nt); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\camera\AutoFocusManager.java:39: 错误: -source 1.5 中不支持 diamond 运算符 [javac] FOCUS_MODES_CALLING_AF = new ArrayList<>(2); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\clipboard\ClipboardInterface.java:41: 错误: -source 1.5 中不支持 multi-catch 语句 [javac] } catch (NullPointerException | IllegalStateException e) { [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 multi-catch 语句) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\encode\ContactEncoder.java:80: 错误: -source 1.5 中不支持 diamond 运算符 [javac] Collection<String> uniques = new HashSet<>(2); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\encode\QRCodeEncoder.java:316: 错误: -source 1.5 中不支持 diamond 运算符 [javac] List<String> values = new ArrayList<>(keys.length); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\encode\VCardContactEncoder.java:83: 错误: -source 1.5 中不支持 diamond 运算符 [javac] List<Map<String,Set<String>>> metadataForIndex = new ArrayList<> (); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\history\HistoryManager.java:93: 错误: -source 1.5 中不支持 diamond 运算符 [javac] List<HistoryItem> items = new ArrayList<>(); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\result\supplement\BookResultInfoRetriever.java:84: 错误: -source 1.5 中不支持 diamond 运算符 [javac] authors = new ArrayList<>(authorsArray.length()); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\result\supplement\SupplementalInfoRetriever.java:78: 错误: -source 1.5 中不支 持 diamond 运算符 [javac] textViewRef = new WeakReference<>(textView); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\share\LoadPackagesAsyncTask.java:61: 错误: -source 1.5 中不支持 diamond 运算 符 [javac] List<AppInfo> labelsPackages = new ArrayList<>(); [javac] ^ [javac] (请使用 -source 7 或更高版本以启用 diamond 运算符) [javac] 18 个错误 BUILD FAILED E:\Android\adt-bundle-windows-x86\sdk\tools\ant\build.xml:712: The following err or occurred while executing this line: E:\Android\adt-bundle-windows-x86\sdk\tools\ant\build.xml:726: Compile failed; s ee the compiler error output for details. Total time: 2 seconds D:\zxing\zxing-zxing-3.1.0\android>这里报了两个问题
一、[gettarget] WARNING: Attribute minSdkVersion in AndroidManifest.xml (15) is higher than the project target API level (14)
原因是:project.properties文件中配置的target=android-14而AndroidManifest.xml文件中<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="19"/>
修改ses-sdk android:minSdkVersion="14"就可以了。
二、是JDK版本的问题
修改:E:\Android\adt-bundle-windows-x86\sdk\tools\ant\build.xml
<property name="java.encoding" value="UTF-8" /> <property name="java.target" value="1.5" /> <property name="java.source" value="1.5" /> <property name="java.compilerargs" value="" /> <property name="java.compiler.classpath" value="" />改成
<property name="java.encoding" value="UTF-8" /> <property name="java.target" value="7" /> <property name="java.source" value="7" /> <property name="java.compilerargs" value="" /> <property name="java.compiler.classpath" value="" />前面的错误没有了,但出现新的问题
D:\zxing\zxing-zxing-3.1.0\android>ant debug Buildfile: D:\zxing\zxing-zxing-3.1.0\android\build.xml -set-mode-check: -set-debug-files: -check-env: [checkenv] Android SDK Tools Revision 22.0.5 [checkenv] Installed at E:\Android\adt-bundle-windows-x86\sdk -setup: [echo] Project Name: CaptureActivity [gettype] Project Type: Application -set-debug-mode: -debug-obfuscation-check: -pre-build: -build-setup: [getbuildtools] Using latest Build Tools: 18.0.1 [echo] Resolving Build Target for CaptureActivity... [gettarget] Project Target: Android 4.0.3 [gettarget] API level: 15 [echo] ---------- [echo] Creating output directories if needed... [echo] ---------- [echo] Resolving Dependencies for CaptureActivity... [dependency] Library dependencies: [dependency] No Libraries [dependency] [dependency] ------------------ [dependency] API<=15: Adding annotations.jar to the classpath. [echo] ---------- [echo] Building Libraries with 'debug'... [subant] No sub-builds to iterate on -code-gen: [mergemanifest] Found Deleted Target File [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 73 source files to D:\zxing\zxing-zxing-3.1.0\android\binclasses [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\camera\CameraConfigurationManager.java:57: 错误: 找不到符号 [javac] cameraResolution = CameraConfigurationUtils.findBestPreviewSizeV alue(parameters, screenResolution); [javac] ^ [javac] 符号: 变量 CameraConfigurationUtils [javac] 位置: 类 CameraConfigurationManager [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\camera\CameraConfigurationManager.java:79: 错误: 找不到符号 [javac] CameraConfigurationUtils.setFocus( [javac] ^ [javac] 符号: 变量 CameraConfigurationUtils [javac] 位置: 类 CameraConfigurationManager [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\camera\CameraConfigurationManager.java:87: 错误: 找不到符号 [javac] CameraConfigurationUtils.setInvertColor(parameters); [javac] ^ [javac] 符号: 变量 CameraConfigurationUtils [javac] 位置: 类 CameraConfigurationManager [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\camera\CameraConfigurationManager.java:91: 错误: 找不到符号 [javac] CameraConfigurationUtils.setBarcodeSceneMode(parameters); [javac] ^ [javac] 符号: 变量 CameraConfigurationUtils [javac] 位置: 类 CameraConfigurationManager [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\camera\CameraConfigurationManager.java:95: 错误: 找不到符号 [javac] CameraConfigurationUtils.setVideoStabilization(parameters); [javac] ^ [javac] 符号: 变量 CameraConfigurationUtils [javac] 位置: 类 CameraConfigurationManager [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\camera\CameraConfigurationManager.java:96: 错误: 找不到符号 [javac] CameraConfigurationUtils.setFocusArea(parameters); [javac] ^ [javac] 符号: 变量 CameraConfigurationUtils [javac] 位置: 类 CameraConfigurationManager [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\camera\CameraConfigurationManager.java:97: 错误: 找不到符号 [javac] CameraConfigurationUtils.setMetering(parameters); [javac] ^ [javac] 符号: 变量 CameraConfigurationUtils [javac] 位置: 类 CameraConfigurationManager [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\camera\CameraConfigurationManager.java:148: 错误: 找不到符号 [javac] CameraConfigurationUtils.setTorch(parameters, newSetting); [javac] ^ [javac] 符号: 变量 CameraConfigurationUtils [javac] 位置: 类 CameraConfigurationManager [javac] D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\andro id\camera\CameraConfigurationManager.java:151: 错误: 找不到符号 [javac] CameraConfigurationUtils.setBestExposure(parameters, newSettin g); [javac] ^ [javac] 符号: 变量 CameraConfigurationUtils [javac] 位置: 类 CameraConfigurationManager [javac] 9 个错误 BUILD FAILED E:\Android\adt-bundle-windows-x86\sdk\tools\ant\build.xml:712: The following err or occurred while executing this line: E:\Android\adt-bundle-windows-x86\sdk\tools\ant\build.xml:726: Compile failed; s ee the compiler error output for details. Total time: 2 seconds D:\zxing\zxing-zxing-3.1.0\android>缺少CameraConfigurationUtils类
通过搜索,在以下目录找到了这个类
直接把这个目录拷贝到D:\zxing\zxing-zxing-3.1.0\android\src\com\google\zxing\client\android\camera
-do-debug: [zipalign] Running zip align on final apk... [echo] Debug Package: D:\zxing\zxing-zxing-3.1.0\android\bin\CaptureActivit y-debug.apk [propertyfile] Creating new property file: D:\zxing\zxing-zxing-3.1.0\android\bi n\build.prop [propertyfile] Updating property file: D:\zxing\zxing-zxing-3.1.0\android\bin\bu ild.prop [propertyfile] Updating property file: D:\zxing\zxing-zxing-3.1.0\android\bin\bu ild.prop [propertyfile] Updating property file: D:\zxing\zxing-zxing-3.1.0\android\bin\bu ild.prop -post-build: debug: BUILD SUCCESSFUL Total time: 11 seconds D:\zxing\zxing-zxing-3.1.0\android>
apk就生成了。
也可以导入到Eclipse后再进行修改。
修改后没有报错,但在运行时出现以下问题
07-23 16:32:47.234: E/AndroidRuntime(18432): FATAL EXCEPTION: main 07-23 16:32:47.234: E/AndroidRuntime(18432): java.lang.ExceptionInInitializerError 07-23 16:32:47.234: E/AndroidRuntime(18432): at java.lang.Class.newInstanceImpl(Native Method) 07-23 16:32:47.234: E/AndroidRuntime(18432): at java.lang.Class.newInstance(Class.java:1319) 07-23 16:32:47.234: E/AndroidRuntime(18432): at android.app.Instrumentation.newActivity(Instrumentation.java:1053) 07-23 16:32:47.234: E/AndroidRuntime(18432): at com.lbe.security.service.core.client.internal.InstrumentationDelegate.newActivity(InstrumentationDelegate.java:234) 07-23 16:32:47.234: E/AndroidRuntime(18432): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1995) 07-23 16:32:47.234: E/AndroidRuntime(18432): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105) 07-23 16:32:47.234: E/AndroidRuntime(18432): at android.app.ActivityThread.access$600(ActivityThread.java:136) 07-23 16:32:47.234: E/AndroidRuntime(18432): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201) 07-23 16:32:47.234: E/AndroidRuntime(18432): at android.os.Handler.dispatchMessage(Handler.java:99) 07-23 16:32:47.234: E/AndroidRuntime(18432): at android.os.Looper.loop(Looper.java:137) 07-23 16:32:47.234: E/AndroidRuntime(18432): at android.app.ActivityThread.main(ActivityThread.java:4881) 07-23 16:32:47.234: E/AndroidRuntime(18432): at java.lang.reflect.Method.invokeNative(Native Method) 07-23 16:32:47.234: E/AndroidRuntime(18432): at java.lang.reflect.Method.invoke(Method.java:511) 07-23 16:32:47.234: E/AndroidRuntime(18432): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808) 07-23 16:32:47.234: E/AndroidRuntime(18432): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575) 07-23 16:32:47.234: E/AndroidRuntime(18432): at dalvik.system.NativeStart.main(Native Method) 07-23 16:32:47.234: E/AndroidRuntime(18432): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType 07-23 16:32:47.234: E/AndroidRuntime(18432): at com.google.zxing.client.android.CaptureActivity.<clinit>(CaptureActivity.java:93) 07-23 16:32:47.234: E/AndroidRuntime(18432): ... 16 more
按照网上很多说法都是把
到处搜索解决方案,终于在google的帮助下解决了。
在eclipse中 Properties -> Java Build Path -> "Order and Export"
在Order and Export选项卡中将core.jar提前到第一位 并选中它
然后clean你的工程,这一步非常重要,别忘记了,我就忘记clean反反复复折腾了好几次
重新编译运行就可以了
估计是在core.jar之前的包里已经有了同名的class所以编译之后产生的apk运行时找不到真正的引用。而且这个包也需要被同时发布到程序中去
生成办法跟core一样D:\zxing\zxing-zxing-3.1.0\javase>mvn -DskipTests -Dgpg.skip=true install
D:\zxing\zxing-zxing-3.1.0\javase>mvn -DskipTests -Dgpg.skip=true install [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ZXing Java SE extensions 3.1.0 [INFO] ------------------------------------------------------------------------ Downloading: http://repo.maven.apache.org/maven2/com/google/zxing/zxing-parent/3 .1.0/zxing-parent-3.1.0.pom Downloaded: http://repo.maven.apache.org/maven2/com/google/zxing/zxing-parent/3. 1.0/zxing-parent-3.1.0.pom (21 KB at 12.4 KB/sec) [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ javase --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory D:\zxing\zxing-zxing-3.1.0\javase\src \main\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ javase --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 11 source files to D:\zxing\zxing-zxing-3.1.0\javase\target\cla sses [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ja vase --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory D:\zxing\zxing-zxing-3.1.0\javase\src \test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ javase --- [INFO] No sources to compile [INFO] [INFO] --- maven-surefire-plugin:2.17:test (default-test) @ javase --- [INFO] Tests are skipped. [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ javase --- [INFO] Building jar: D:\zxing\zxing-zxing-3.1.0\javase\target\javase-3.1.0.jar [INFO] [INFO] --- maven-javadoc-plugin:2.9.1:jar (attach-javadocs) @ javase --- [INFO] 正在加载程序包com.google.zxing.client.j2se的源文件... 正在加载程序包com.google.zxing的源文件... 正在构造 Javadoc 信息... 标准 Doclet 版本 1.7.0_01 正在构建所有程序包和类的树... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\BufferedImageLuminanceSource.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\CommandLineEncoder.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\CommandLineRunner.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\GUIRunner.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\ImageReader.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\MatrixToImageConfig.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\MatrixToImageWriter.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\HtmlAs setTranslator.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\String sResourceTranslator.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\overview-frame.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\packag e-frame.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\packag e-summary.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\packag e-tree.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\package-frame.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\package-summary.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\package-tree.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\constant-values.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\serialized-form.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\class-use\MatrixToImageWriter.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\class-use\MatrixToImageConfig.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\class-use\ImageReader.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\class-use\GUIRunner.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\class-use\CommandLineRunner.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\class-use\CommandLineEncoder.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\class-use\BufferedImageLuminanceSource.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\class- use\StringsResourceTranslator.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\class- use\HtmlAssetTranslator.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\packag e-use.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\com\google\zxing\client \j2se\package-use.html... 正在构建所有程序包和类的索引... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\overview-tree.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\index-all.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\deprecated-list.html... 正在构建所有类的索引... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\allclasses-frame.html.. . 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\allclasses-noframe.html ... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\index.html... 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\overview-summary.html.. . 正在生成D:\zxing\zxing-zxing-3.1.0\javase\target\apidocs\help-doc.html... [INFO] Fixed Javadoc frame injection vulnerability (CVE-2013-1571) in 1 files. [INFO] Building jar: D:\zxing\zxing-zxing-3.1.0\javase\target\javase-3.1.0-javad oc.jar [INFO] [INFO] --- maven-source-plugin:2.2.1:jar-no-fork (attach-sources) @ javase --- [INFO] Building jar: D:\zxing\zxing-zxing-3.1.0\javase\target\javase-3.1.0-sourc es.jar [INFO] [INFO] --- maven-install-plugin:2.5.1:install (default-install) @ javase --- [INFO] Installing D:\zxing\zxing-zxing-3.1.0\javase\target\javase-3.1.0.jar to C :\Documents and Settings\Administrator\.m2\repository\com\google\zxing\javase\3. 1.0\javase-3.1.0.jar [INFO] Installing D:\zxing\zxing-zxing-3.1.0\javase\pom.xml to C:\Documents and Settings\Administrator\.m2\repository\com\google\zxing\javase\3.1.0\javase-3.1.0 .pom [INFO] Installing D:\zxing\zxing-zxing-3.1.0\javase\target\javase-3.1.0-javadoc. jar to C:\Documents and Settings\Administrator\.m2\repository\com\google\zxing\j avase\3.1.0\javase-3.1.0-javadoc.jar [INFO] Installing D:\zxing\zxing-zxing-3.1.0\javase\target\javase-3.1.0-sources. jar to C:\Documents and Settings\Administrator\.m2\repository\com\google\zxing\j avase\3.1.0\javase-3.1.0-sources.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:01 min [INFO] Finished at: 2014-07-24T12:47:45+08:00 [INFO] Final Memory: 14M/33M [INFO] ------------------------------------------------------------------------ D:\zxing\zxing-zxing-3.1.0\javase>
生成一个target目录
Eclipse版本号:v22.0.5-757759
Eclipse版本号:v23.0.2.1259578
经测试在Eclipse:v23.0.2.1259578版本上可以运行在v22.0.5-757759版本上会报错,如果你的程序还是报错,建议换一个高版本的Eclipse试下。
扫描结果
导入Eclipse可以编译运行的源码:http://download.csdn.net/detail/deng0zhaotai/7672273
Android二维码开源项目zxing编译,布布扣,bubuko.com
原文地址:http://blog.csdn.net/deng0zhaotai/article/details/38046913