Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android二維碼開源項目zxing編譯

Android二維碼開源項目zxing編譯

編輯:關於Android編程

ZXing是一個開放源碼的,用Java實現的多種格式的1D/2D條碼圖像處理庫,它包含了聯系到其他語言的端口。Zxing可以實現使用手機的內置的攝像頭完成條形碼的掃描及解碼。該項目可實現的條形碼編碼和解碼。

目前支持以下格式:

\

zxing官網說明:https://github.com/zxing/zxing/wiki/Getting-Started-Developing

源碼下載:https://github.com/zxing/zxing

我下載的是releases版本:https://github.com/zxing/zxing/releases<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGltZyBzcmM9"/uploadfile/Collfiles/20140725/20140725091720126.png" alt="\">

需要的工具:

Ant: http://ant.apache.org/bindownload.cgi

\

Maven: http://maven.apache.org/download.cgi

\

我下載的是Windows版的,如果是Linux需要下載Linux版,這裡只嘗試Windows下編譯。

下載後在合適的目錄下解壓,將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\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 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 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 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 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 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 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>> 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 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 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文件中

修改ses-sdk android:minSdkVersion="14"就可以了。

二、是JDK版本的問題

修改:E:\Android\adt-bundle-windows-x86\sdk\tools\ant\build.xml


    
    
    
    
改成


    
    
    
    
前面的錯誤沒有了,但出現新的問題

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類

通過搜索,在以下目錄找到了這個類

\

直接把這個目錄拷貝到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.(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運行時找不到真正的引用。而且這個包也需要被同時發布到程序中去

但對於我的工程還是會報這個錯誤,後來還是在網上找到的解決辦法,缺少了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目錄

\

添加到工程後

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

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved