Android二维码开源项目zxing编译

首先这里是自己花了整整一个下午的时间查找整理出来的,借鉴了一个比较不错博客,也很感谢他的详细步骤。

支持的格式如下:

我的环境是win8.1专业版。

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

然后下载的东西都解压我的是桌面临时创建的一个文件夹test

下面就是分别配置ant和Maven环境变量了,至于怎么进入系统环境变量,我就不那么墨迹的说了,只给截图我认为关键的地方。

两个方法一样,我这里配置ant一个给大家看看:

就是你刚刚解压的位置我的如下到bin目录下复制

C:\Users\xiang\Desktop\test\apache-ant-1.9.4-bin\apache-ant-1.9.4\bin;

path里面最后加英文分号,然后把我的那个路径贴进去,你们的都要贴自己的路径,

然后运行cmd,输入ant验证

这就ok了。

Maven的配置方法不在赘述,

这就ok了。

确保你已经有了java运行环境,如JAVA_HOME、CLASSPATH、PATH都配置好了

进入到zxing-master\android目录,输入命令:android update project --path .

(上面的命令不要省略“--”和后面的点)

 1 C:\Users\xiang\Desktop\test\zxing-master\android>android update project --path.
 2 Error: Flag ‘--path.‘ is not valid for ‘update project‘.
 3 
 4        Usage:
 5        android [global options] update project [action options]
 6        Global options:
 7   -h --help       : Help on a specific command.
 8   -v --verbose    : Verbose mode, shows errors, warnings and all messages.
 9      --clear-cache: Clear the SDK Manager repository manifest cache.
10   -s --silent     : Silent mode, shows errors only.
11 
12                          Action "update project":
13   Updates an Android project (must already have an AndroidManifest.xml).
14 Options:
15   -l --library    : Directory of an Android library to add, relative to this
16                     project‘s directory.
17   -p --path       : The project‘s directory. [required]
18   -n --name       : Project name.
19   -t --target     : Target ID to set for the project.
20   -s --subprojects: Also updates any projects in sub-folders, such as test
21                     projects.

出错了,需要我们提供一个target,输入命令:android list targets

C:\Users\xiang\Desktop\test\zxing-master\android>android list targets
Available Android targets:
----------
id: 1 or "android-8"
     Name: Android 2.2
     Type: Platform
     API level: 8
     Revision: 3
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
 Tag/ABIs : default/armeabi
----------
id: 2 or "android-18"
     Name: Android 4.3.1
     Type: Platform
     API level: 18
     Revision: 3
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : default/armeabi-v7a, default/x86
----------
id: 3 or "android-19"
     Name: Android 4.4.2
     Type: Platform
     API level: 19
     Revision: 4
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : default/armeabi-v7a, default/x86
----------
id: 4 or "android-21"
     Name: Android 5.0
     Type: Platform
     API level: 21
     Revision: 1
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : android-tv/armeabi-v7a, android-tv/x86, default/armeabi-v7a, default
/x86, default/x86_64
----------
id: 5 or "Google Inc.:Google APIs:8"
     Name: Google APIs
     Type: Add-On
     Vendor: Google Inc.
     Revision: 2
     Description: Android + Google APIs
     Based on Android 2.2 (API level 8)
     Libraries:
      * com.google.android.maps (maps.jar)
          API for Google Maps
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
 Tag/ABIs : default/armeabi
----------
id: 6 or "Google Inc.:Google APIs:18"
     Name: Google APIs
     Type: Add-On
     Vendor: Google Inc.
     Revision: 3
     Description: Android + Google APIs
     Based on Android 4.3.1 (API level 18)
     Libraries:
      * com.google.android.media.effects (effects.jar)
          Collection of video effects
      * com.android.future.usb.accessory (usb.jar)
          API for USB Accessories
      * com.google.android.maps (maps.jar)
          API for Google Maps
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : default/armeabi-v7a
----------
id: 7 or "Google Inc.:Glass Development Kit Preview:19"
     Name: Glass Development Kit Preview
     Type: Add-On
     Vendor: Google Inc.
     Revision: 10
     Description: Preview of the Glass Development Kit
     Based on Android 4.4.2 (API level 19)
     Libraries:
      * com.google.android.glass (gdk.jar)
          APIs for Glass Development Kit Preview
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : no ABIs.
----------
id: 8 or "Google Inc.:Google APIs:19"
     Name: Google APIs
     Type: Add-On
     Vendor: Google Inc.
     Revision: 8
     Description: Android + Google APIs
     Based on Android 4.4.2 (API level 19)
     Libraries:
      * com.google.android.media.effects (effects.jar)
          Collection of video effects
      * com.android.future.usb.accessory (usb.jar)
          API for USB Accessories
      * com.google.android.maps (maps.jar)
          API for Google Maps
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : default/armeabi-v7a
----------
id: 9 or "Google Inc.:Google APIs (x86 System Image):19"
     Name: Google APIs (x86 System Image)
     Type: Add-On
     Vendor: Google Inc.
     Revision: 8
     Description: Android x86 + Google APIs
     Based on Android 4.4.2 (API level 19)
     Libraries:
      * com.google.android.media.effects (effects.jar)
          Collection of video effects
      * com.android.future.usb.accessory (usb.jar)
          API for USB Accessories
      * com.google.android.maps (maps.jar)
          API for Google Maps
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : default/x86
----------
id: 10 or "Google Inc.:Google APIs:21"
     Name: Google APIs
     Type: Add-On
     Vendor: Google Inc.
     Revision: 1
     Description: Android + Google APIs
     Based on Android 5.0 (API level 21)
     Libraries:
      * com.google.android.media.effects (effects.jar)
          Collection of video effects
      * com.android.future.usb.accessory (usb.jar)
          API for USB Accessories
      * com.google.android.maps (maps.jar)
          API for Google Maps
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : no ABIs.

根据输出的ID,加上target,命令:android update project --target 2 --path .

C:\Users\xiang\Desktop\test\zxing-master\android>android update project --target
 2 --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 C:\Users\xiang\Desktop\test\zxing-master\android\build.xml
Added file C:\Users\xiang\Desktop\test\zxing-master\android\proguard-project.txt

会生成以下文件:

上面生成的文件我已经标注出来了。

其中: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=D:\\adt-bundle-windows-x86_64-20130917\\sdk

编译jar包在zxing-master\core目录下输入:mvn -DskipTests -Dgpg.skip=true install

这里有些地方可能被和谐,导致无法下载,至于FQ或者怎么的,各自显神通吧。

我的成功后如下,你们看看

这就表明ok了。

运行完之后core目录下会生成一个target目录,其中:core-3.1.0.jar就是我们需要的jar包

这个后缀名跟选的版本有点关系,都能使用,我选的这个是id为2的,也就是4.3.1。

我也选过5.0那个,出来的效果是一样的,直接就可以使用了。

下面开始编译Android项目,生成apk了,这里有两种方法:

一、命令实现

继续在cmd下执行,进入zxing-master\android里输入ant debug

C:\Users\xiang\Desktop\test\zxing-master\android>ant debug
Buildfile: C:\Users\xiang\Desktop\test\zxing-master\android\build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 23.0.5
 [checkenv] Installed at D:\adt-bundle-windows-x86_64-20130917\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: 21.0.2
     [echo] Resolving Build Target for CaptureActivity...
[gettarget] Project Target:   Android 4.3.1
[gettarget] API level:        18
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: C:\Users\xiang\Desktop\test\zxing-master\android\bin
    [mkdir] Created dir: C:\Users\xiang\Desktop\test\zxing-master\android\bin\re
s
    [mkdir] Created dir: C:\Users\xiang\Desktop\test\zxing-master\android\bin\rs
Obj
    [mkdir] Created dir: C:\Users\xiang\Desktop\test\zxing-master\android\bin\rs
Libs
    [mkdir] Created dir: C:\Users\xiang\Desktop\test\zxing-master\android\gen
    [mkdir] Created dir: C:\Users\xiang\Desktop\test\zxing-master\android\bin\cl
asses
    [mkdir] Created dir: C:\Users\xiang\Desktop\test\zxing-master\android\bin\de
xedLibs
     [echo] ----------
     [echo] Resolving Dependencies for CaptureActivity...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency]
[dependency] ------------------
     [echo] ----------
     [echo] Building Libraries with ‘debug‘...
   [subant] No sub-builds to iterate on

-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...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:

-compile:
    [javac] Compiling 75 source files to C:\Users\xiang\Desktop\test\zxing-maste
r\android\bin\classes
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:57: 错误: 找不到符号
    [javac]     cameraResolution = CameraConfigurationUtils.findBestPreviewSizeV
alue(parameters, screenResolution);
    [javac]                        ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:79: 错误: 找不到符号
    [javac]     CameraConfigurationUtils.setFocus(
    [javac]     ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:87: 错误: 找不到符号
    [javac]         CameraConfigurationUtils.setInvertColor(parameters);
    [javac]         ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:91: 错误: 找不到符号
    [javac]         CameraConfigurationUtils.setBarcodeSceneMode(parameters);
    [javac]         ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:95: 错误: 找不到符号
    [javac]         CameraConfigurationUtils.setVideoStabilization(parameters);
    [javac]         ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:96: 错误: 找不到符号
    [javac]         CameraConfigurationUtils.setFocusArea(parameters);
    [javac]         ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:97: 错误: 找不到符号
    [javac]         CameraConfigurationUtils.setMetering(parameters);
    [javac]         ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:151: 错误: 找不到符号
    [javac]     CameraConfigurationUtils.setTorch(parameters, newSetting);
    [javac]     ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:154: 错误: 找不到符号
    [javac]       CameraConfigurationUtils.setBestExposure(parameters, newSettin
g);
    [javac]       ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] 9 个错误

BUILD FAILED
D:\adt-bundle-windows-x86_64-20130917\sdk\tools\ant\build.xml:720: The following
 error occurred while executing this line:
D:\adt-bundle-windows-x86_64-20130917\sdk\tools\ant\build.xml:734: Compile faile
d; see the compiler error output for details.

Total time: 4 seconds

C:\Users\xiang\Desktop\test\zxing-master\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版本的问题

修改:D:\adt-bundle-windows-x86_64-20130917\sdk\tools\ant\build.xml

<!-- compilation options -->
    <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="" />

为如下

<!-- compilation options -->
    <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="" />

改好之后又有新问题了

C:\Users\xiang\Desktop\test\zxing-master\android>ant debug
Buildfile: C:\Users\xiang\Desktop\test\zxing-master\android\build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 23.0.5
 [checkenv] Installed at D:\adt-bundle-windows-x86_64-20130917\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: 21.0.2
     [echo] Resolving Build Target for CaptureActivity...
[gettarget] Project Target:   Android 4.3.1
[gettarget] API level:        18
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: C:\Users\xiang\Desktop\test\zxing-master\android\bin\rs
Obj
    [mkdir] Created dir: C:\Users\xiang\Desktop\test\zxing-master\android\bin\rs
Libs
     [echo] ----------
     [echo] Resolving Dependencies for CaptureActivity...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency]
[dependency] ------------------
     [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...
     [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 C:\Users\xiang\Desktop\test\zxing-maste
r\android\bin\classes
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:57: 错误: 找不到符号
    [javac]     cameraResolution = CameraConfigurationUtils.findBestPreviewSizeV
alue(parameters, screenResolution);
    [javac]                        ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:79: 错误: 找不到符号
    [javac]     CameraConfigurationUtils.setFocus(
    [javac]     ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:87: 错误: 找不到符号
    [javac]         CameraConfigurationUtils.setInvertColor(parameters);
    [javac]         ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:91: 错误: 找不到符号
    [javac]         CameraConfigurationUtils.setBarcodeSceneMode(parameters);
    [javac]         ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:95: 错误: 找不到符号
    [javac]         CameraConfigurationUtils.setVideoStabilization(parameters);
    [javac]         ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:96: 错误: 找不到符号
    [javac]         CameraConfigurationUtils.setFocusArea(parameters);
    [javac]         ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:97: 错误: 找不到符号
    [javac]         CameraConfigurationUtils.setMetering(parameters);
    [javac]         ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:151: 错误: 找不到符号
    [javac]     CameraConfigurationUtils.setTorch(parameters, newSetting);
    [javac]     ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxin
g\client\android\camera\CameraConfigurationManager.java:154: 错误: 找不到符号
    [javac]       CameraConfigurationUtils.setBestExposure(parameters, newSettin
g);
    [javac]       ^
    [javac]   符号:   变量 CameraConfigurationUtils
    [javac]   位置: 类 CameraConfigurationManager
    [javac] 9 个错误

BUILD FAILED
D:\adt-bundle-windows-x86_64-20130917\sdk\tools\ant\build.xml:720: The following
 error occurred while executing this line:
D:\adt-bundle-windows-x86_64-20130917\sdk\tools\ant\build.xml:734: Compile faile
d; see the compiler error output for details.

Total time: 4 seconds

C:\Users\xiang\Desktop\test\zxing-master\android>

没有CameraConfigurationUtils类

搜索下就可以找到,应该在android-core里面有这个类

直接把这个目录拷贝到C:\Users\xiang\Desktop\test\zxing-master\android\src\com\google\zxing\client\android\camera里面

然后再编译,效果图如下,不用多说了

apk已经生成了。你看看

看bin里已经有对应的apk了,自己跑跑看。

二、第二种方法就是直接导入到Eclipse,这种方法我不再详细演示了,直接导入android项目,然后把添加lib文件夹,放入前面生成的jar包,

加入对应的那个类

运行的时候可能会报错。

12-11 17:36:01.470: E/AndroidRuntime(13311): FATAL EXCEPTION: main
12-11 17:36:01.470: E/AndroidRuntime(13311): java.lang.ExceptionInInitializerError
12-11 17:36:01.470: E/AndroidRuntime(13311):     at java.lang.Class.newInstanceImpl(Native Method)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at java.lang.Class.newInstance(Class.java:1319)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at com.lbe.security.service.core.client.b.x.newActivity(Unknown Source)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1996)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2106)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at android.app.ActivityThread.access$600(ActivityThread.java:137)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at android.os.Looper.loop(Looper.java:137)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at android.app.ActivityThread.main(ActivityThread.java:4819)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at java.lang.reflect.Method.invokeNative(Native Method)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at java.lang.reflect.Method.invoke(Method.java:511)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-11 17:36:01.470: E/AndroidRuntime(13311):     at dalvik.system.NativeStart.main(Native Method)
12-11 17:36:01.470: E/AndroidRuntime(13311): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
12-11 17:36:01.470: E/AndroidRuntime(13311):     at com.google.zxing.client.android.CaptureActivity.<clinit>(CaptureActivity.java:93)
12-11 17:36:01.470: E/AndroidRuntime(13311):     ... 16 more

按照网上很多说法

到处搜索解决方案,终于在google的帮助下解决了。
在eclipse中 Properties -> Java Build Path -> "Order and Export"
在Order and Export选项卡中将core.jar提前到第一位 并选中它 
然后clean你的工程,这一步非常重要,别忘记了
重新编译运行就可以了

估计是在core.jar之前的包里已经有了同名的class所以编译之后产生的apk运行时找不到真正的引用。而且这个包也需要被同时发布到程序中去

如果还是有错误的话,那就缺少了javase-3.1.0.jar库

生成办法跟core一样C:\Users\xiang\Desktop\test\zxing-master\javase>mvn -DskipTests -Dgpg.skip=true install

后面我就不贴图了,同样把对应的包放入lib然后add buildpath编译,还有问题,你就考虑考虑吧Eclipse换个高版本的吧。

至于扫描效果图,我真机也就不展示了,截个图给你们看看吧

正常运行代码我稍后添加。

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。