剛剛想耍耍二維碼,想到了zxing和zbar,又想到zxing是Google老爹的,想想就算了吧,雖然zbar快但是識別錯誤率也高不少.隨手Google了下*zxing 集成*好像都是說什么拷貝項目到自己的工程中,我不信Gradle集成這么方便了為何不用.於是我來到zxing的 Github 主頁 ,在README的引導下來到Get Start頁面,里面有如下說明:
Maven
core/, javase/, android-integration and zxingorg can be used directly in a Maven-based project without any download or installation. Instead, add as dependencies from groupID com.google.zxing artifactIDs core, javase, android-integration or zxingorg:
<dependencies>
...
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>(the current version)</version>
</dependency>
</dependencies>
雖然沒說明 Gradle 如何集成,但是發布過lib到jcenter的應該知道,maven和Gradle的關系.
上面maven倉庫信息對應的Gradle為:
compile 'com.google.zxing:core:3.3.0'
compile '<groupId>:<artifactId>:<version>'
記起來也很簡單,就是把上面三個參數用:連接即可.
其中 version對應版本有很多,建議使用最新的,我現在看到最新的Release版本為3.3.0.
所以在 Android studio 的工程 Module的build.gradle下添加一行依賴即可:
dependencies {
compile fileTree(dir: 'libs', include: ['*.www.22yigouyule.cn/ jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', http://xucaizxyl.com/ module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.www.acnet.cn/1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
//添加 zxing
compile 'com.google.zxing:core:3.3.0'