Monday, July 25, 2016

How to Compile ZXING Barcode Scanner App in Android Studio Part 1

In this post, I will cover how to compile stand-alone zxing's Barcode Scanner app in Android Studio.

First, download the zxing's latest source files from here or run git clone:
$ git clone

Next, launch Android Studio and choose Import project (Eclipse ADT, Gradle, etc) and choose zxing/android folder. Select all three check boxes when prompted, and finish importing.

In the app module's build.gradle file, edit compileSdkVersion, buildToolsVersion, minSdkVersion, and targetSdkVersion values if necessary.

Try to compile the project. It will complain with the following error:
Error:(19, 24) error: cannot find symbol class Result

That is, in the file, importing cannot be resolved. This is because we need to link zxing/core library. You could either import zxing/core source files and compile, or simply include pre-built jar file.

In this post, I will go through the method of linking pre-built jar file. If you are curious as to how to compile the project all from source files, go straight to my follow up post.

To compile using pre-built jar files, go to zxing's maven release repository and navigate to zxing/core/ and download the latest version of jar file. I downloaded core-3.2.1.jar file.

Next, create app/src/main/libs directory in the project and copy core-3.2.1.jar file here. Now we need to include this file as a library in Android Studio. You could do this by right-clicking this jar file in Android Studio Project pane and selecting Add to Library,which will add the following lines of code in app's build.gradle file:
dependencies {
    compile files('src/main/libs/core-3.2.1.jar')

You can try to compile the project again, but it will probably prompt another error:
Error:(124, 24) error: cannot find symbol variable CameraConfigurationUtils

Again, this is because we need zxing/android-core library in order to compile the app. Similar to zxing/core library, we go to the zxing's release repository and navigate to zxing/android-core/ and download the latest version of jar file. I downloaded android-core-3.2.1.jar file.

Similar to the core library file, we need to copy this file into app/src/main/libs directory in the project and select Add to Library. Your app's build.gradle should read:
dependencies {
    compile files('src/main/libs/core-3.2.1.jar')
    compile files('src/main/libs/android-core-3.2.1.jar')

Now, you should be able to compile the app!


  1. Congratulations for the post, it was very hard to find your this solution.