Android二维码开源项目zxing编译
ZXing是一个开放源代码的,用Java实现的多种格式的1D/2D条码图像处理库,它包括了联系到其它语言的port。Zxing能够实现使用手机的内置的摄像头完毕条形码的扫描及解码。该项目可实现的条形码编码和解码。
眼下支持下面格式:
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
我下载的是Windows版的。假设是Linux须要下载Linux版。这里仅仅尝试Windows下编译。
下载后在合适的文件夹下解压,将bin文件夹加入到环境变量。跟JDK方法一样。
这里仅仅配置下ant的环境变量
1.我的电脑右键
2.点击“属性”
3.点击“环境变量”
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGVuZzB6aGFvdGFp/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
4.点击“编辑”
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGVuZzB6aGFvdGFp/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
加入解压后的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>
会生成下面文件
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGVuZzB6aGFvdGFp/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
当中: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\core\
3.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\core\
3.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/
编译Android项目,生成apk
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\bin\
classes
[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\bin\
classes
[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类
通过搜索。在下面文件夹找到了这个类
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGVuZzB6aGFvdGFp/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
直接把这个文件夹复制到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你的project,这一步很重要。别忘记了,我就忘记clean反重复复折腾了好几次
又一次编译执行就能够了
预计是在core.jar之前的包里已经有了同名的class所以编译之后产生的apk执行时找不到真正的引用。并且这个包也须要被同一时候公布到程序中去
但对于我的project还是会报这个错误,后来还是在网上找到的解决的方法。缺少了javase-3.1.0.jar库
生成办法跟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文件夹
加入到project后
Eclipse版本:v22.0.5-757759
Eclipse版本:v23.0.2.1259578
经測试在Eclipse:v23.0.2.1259578版本号上能够执行在v22.0.5-757759版本号上会报错,假设你的程序还是报错,建议换一个高版本号的Eclipse试下。
扫描结果
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGVuZzB6aGFvdGFp/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
导入Eclipse能够编译执行的源代码:http://download.csdn.net/detail/deng0zhaotai/7672273
Android二维码开源项目zxing编译的更多相关文章
- Android二维码开源项目zxing用例简化和生成二维码、条形码
上一篇讲到:Android二维码开源项目zxing编译,编译出来后有一个自带的測试程序:CaptureActivity比較复杂,我仅仅要是把一些不用的东西去掉,用看起来更方便,二维码和条形码的流行性自 ...
- 二维码识别项目zxing横屏改为竖屏
第1步: 在AndroidManifest中将CaptureActivity的screenOrientation属性做如下修改: android:screenOrientation="por ...
- android 二维码生成+扫描
android 二维码生成+扫描 1.在Android应用当中,很多时候都要用到二维码扫描,来避免让用户手动输入的麻烦. Google官方自己推出了一个二维码开源项目:ZXing库. 2.这里简单介绍 ...
- Android二维码识别 开源项目ZXing的编译
Android二维码识别 开源项目ZXing的编译 Android端的条形码/二维码识别功能 因为手机端的输入不是很方便,所以条形码/二维码的扫描是一种很有效的解决手段. 比较流行的手机应用中,常用的 ...
- Android二维码扫描、生成
Android二维码扫描.生成 现在使用二维码作为信息的载体已经越来越普及,那么二维码的生成以及扫描是如何实现的呢 google为我们提供了zxing开源库供我们使用 zxing GitHub源码地址 ...
- 个性二维码开源专题<替换元素点>
基础方法:ChangeFillShape //修改填充形状 ChangeFillShape(...) // 摘要: // 修改填充形状 // // 参数: // g: // 图形画板 // // Fo ...
- 个性二维码开源专题<替换定位点>
基础方法: ChangeFillShape //修改填充形状 ChangeFillShape(...) // 摘要: // 修改填充形状 // // 参数: // g: // 图形画板 // // F ...
- 个性二维码开源专题<液化/圆角/效果>
基础方法: ChangeFillShape //修改填充形状 ChangeFillShape(...) // 摘要: // 修改填充形状 // // 参数: // g: // 图形画板 // // F ...
- Android二维码功能实现,在程序内嵌入ZXing项目
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9526247 最近二维码真是越来越火了,随便电视上.网络上.商场里,到处都是二维码. ...
随机推荐
- jQuery判断元素是否是隐藏的代码
if($("#elem_id").is(":hidden")) { } 实例代码1: 复制代码 代码如下: <!DOCTYPE HTML PUBLIC & ...
- 总结 XSS 与 CSRF 两种跨站攻击
前言 在那个年代,大家一般用拼接字符串的方式来构造动态 SQL 语句创建应用,于是 SQL 注入成了很流行的攻击方式.在这个年代, 参数化查询 [1] 已经成了普遍用法,我们已经离 SQL 注入很远了 ...
- 频繁模式挖掘apriori算法介绍及Java实现
频繁模式是频繁地出如今数据集中的模式(如项集.子序列或者子结构).比如.频繁地同一时候出如今交易数据集中的商品(如牛奶和面包)的集合是频繁项集. 一些基本概念 支持度:support(A=>B) ...
- ubuntu14.04下arm-linux-gcc 4.5.1的安装与配置
使用的是友善之臂mini6410自带光盘中的. 1.对新版本arm-linux-gcc-5.4.1进行解压(注意,下面的C是大写的) tar zxvf arm-linux-gcc-4.5.1-v6-v ...
- [Manacher][HDU3613][Best Reward]
题意: 将一段字符串 分割成两个串 如果分割后的串为回文串,则该串的价值为所有字符的权值之和(字符的权值可能为负数),否则为0. 问如何分割,使得两个串权值之和最大 思路: 裸的: 枚举分割点,计算, ...
- Xshell同时向多个会话发送指令的方法
我们平时使用XSHELL.SecureCRT.putty等ssh连接工具连接到远程主机,每次输入指令都是在单一会话窗口,如果有很多台会话,需要同时输入同样的指令,我们就不用一一输入,浪费时间和精力.可 ...
- Letter of application, e-mail version
Subject line: (logical to recipient!) Application for sales representative for mid-Atlantic area Apr ...
- CAD2014以上版本不信任加载项解决方法
前一段时间做CAD插件支持版本升级遇到了一个很棘手的问题,CAD2014以上版本增加了受信任功能,每次用程序启动CAD并加载arx文件时都弹出对话框询问是否加载 我的解决方法如下:(仅供参考) 读取注 ...
- PhpExcel使用方法
下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...
- Git 添加空文件夹的方法
转自stackoverflow: http://stackoverflow.com/questions/115983/how-do-i-add-an-empty-directory-to-a-git- ...