Zxing 的集成 ---- Maven 對應 Gradle 的寫法
剛剛想耍耍二維碼,想到了zxing
和zbar
,又想到zxing
是Google
老爹的,想想就算了吧,雖然zbar
快但是識別錯誤率也高不少.隨手Google
了下*zxing 集成*
好像都是說什么拷貝項目到自己的工程中,我不信Gradle
集成這么方便了為何不用.於是我來到zxing
的 Github 主頁 https://github.com/zxing/zxing,在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: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.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'
}
其他的項目集成以此類推.