My favorites | Sign in
Google
                
Search
for
Updated Jun 26, 2009 by dswit...@gmail.com
Labels: Featured
GettingStarted  
How to start developing with zxing

Getting Started

Please also read CodingStyle if you'd like to contribute to the project. You can also see DeveloperNotes for more information.

Download

Grab the latest distribution. Or, retrieve the latest source code from our Subversion repository.

Build

You will find the code lives in several subdirectories, corresponding to the various subcomponents, like "core" and "javase". Within each, there is a build.xml Ant build file which controls building of that component. If Apache's ant tool is already present on your system, simply type "ant" to build that component. See http://ant.apache.org for details on how to obtain this free, standard build tool for Java.

To build everything, simply use the build.xml file found in the top-level directory, above all components. Yes, just type ant there.

Run

The quickest way to run the code is to run the "javase" component's com.google.zxing.client.j2se.CommandLineRunner class against a URL.

As above, first build core and javase:

 cd core
 ant
 cd ../javase
 ant

After building, simply run this class with java:

 cd ..
 java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner [URL]

Windows users take note; path syntax is different on Windows. Here and elsewhere you will need to use ';' rather than ':' to separate classpath elements, and likely need to use the '\' path separator. So that last command should be:

 java -cp javase\javase.jar;core\core.jar com.google.zxing.client.j2se.CommandLineRunner [URL]

Run on your phone

You can build the J2ME client too.

  • Download and install Sun's Java Wireless Toolkit 2.5.2
  • At the top level of the project, edit build.properties to reference the location where you installed WTK.
  • Download Proguard, and copy proguard.jar to the bin directory under the WTK 2.5.2 installation directory.
  • Build core and then javame:
  •  cd core
     ant
     cd ../javame
     ant
  • Refer to instructions for your particular phone model to learn how to load this application onto your device

Run on Android

  • Download and install the latest public Android SDK.
  • Edit build.properties at the top level of the project, and change the android-home property to point to the SDK install location
  • Build core and then android. Note that core must be built without debug symbols to avoid an incompatibility between proguard and the Android tool chain:
  •  cd core
     ant clean build-no-debug
     cd ../android
     ant
  • The application should be built to bin/BarcodeScanner-debug.apk. Install with Android's adb tool:
  •  adb install bin/BarcodeScanner-debug.apk

Comment by nanodeath, Mar 12, 2008

Can we see some android-specific "Getting Started" comments? Thanks!

Comment by sro...@gmail.com, Mar 12, 2008

Will do. It's about the same. At the moment we only have a build available that works with the M3 SDK, not M5 or later. So you can't run this on the emulator at the moment (but the additional changes needed for M5 are small). But even if you could run it, you wouldn't have a video feed to decode (though there are workarounds for that even...) For the moment, for testing reasons, it's convenient for us to stick on M3 -- while it's of little use to anyone else. But yeah we need to move forward soon in any event.

Comment by nanodeath, Mar 16, 2008

Okay. It's not a huge hurry -- the first gphones are still a ways off (I think) and I still have plenty of other things to work on.

Oh, and great work so far. I actually was able to port everything from M3 to M5 myself except for a couple of important things that...coincidentally were essential to the library's functioning. Some stuff related to bitmaps, I believe.

Comment by sro...@gmail.com, Mar 16, 2008

Can you file an issue or start a thread at http://groups.google.com/group/zxing/ describing the issue? I got it compiling on M5 but have not verified it works completely, since there's no real video feed available to the emulator.

Comment by christopher.orr, May 15, 2008

Note that building core (i.e. not only the J2ME version) requires WTK.

Comment by matt.hall, Jul 09, 2008

For Mac users you can use some of the information at http://javablog.co.uk/2008/01/17/j2me-development-on-os-x-revisited/ to put together a semi working WTK out of the Linux WTK download and the preverify binary from the phoneme project. It seems to be enough to compile the project at least.

Comment by leroyale, Sep 27, 2008

Does not work with the last android sdk android-sdk-windows-1.0_r1 since packages are different from android-sdk-windows-0.9_beta

Comment by leybzon, Oct 28, 2008

With the latest Android emulator, I can not upload test image into the emulator:

adb push c:barcode.jpg /tmp/barcode.jpg failed to copy 'c:barcode.jpg' to '/tmp/barcode.jpg': No such file or directory

Also can not create /tmp directory within the device: adb shell mkdir /tmp mkdir failed for /tmp, Read-only file system

Comment by sro...@gmail.com, Oct 29, 2008

Looks like you have a typo in your command line? "c:barcode.jpg"? I don't think you need to create /tmp, it should already be there.

Continue this on the Google Group instead? http://groups.google.com/group/zxing/

Comment by nambrot, Nov 08, 2008

Hi does the iphone version support openURL schemes to open Applications? Would be really nice, as deveopers can display a code on the screen and opens an application.

Comment by ryivar, Dec 08, 2008

Hi..I am a beginner and trying to do a barcode scanning project.could anyone tell me how to scan a barcode using webcam/android emulator? Please advise me where to start from. Your help is always appreciated.

Comment by credentiality, Jan 06, 2009

ZXing doesn't seem to work with proguard 3.9, which is what you get with Ubuntu Hardy as of January 2009. Download version 4.1 or later.

If proguard is too old you'll get errors like "unknown option -target".

Comment by email.rafa, Feb 10, 2009

Is there a getting started guide for iPhone developers? thanks!

Comment by weiguo10, May 19, 2009

I cannot build the android version for cupcake(1.5), it give following error

..\zxing\android\build.xml:125: Execute failed: java.io.IOException: Cannot run program "D:\android-sdk-windows-1.5_r1\tools\aapt.exe": CreateProcess? error=2, ?????????

aapt can only be found in android 1.1 and before

Comment by sro...@gmail.com, May 19, 2009

Yes, at the moment the code compiles against the 1.1 SDK so that the application can be built and used on 1.1 devices. Not every device has 1.5 yet, but 1.5 can run the 1.1-built application. Later when 1.5 is the norm we can change the build process to work with the 1.5 SDK.

Comment by michael573114, Jun 24, 2009

Perhaps you could provide a 1.5 SDK version as well as the 1.1? There's little reason to develop new apps for 1.1 anymore, regardless of wether "not all device has 1.5 yet"

Comment by janrunejohansen, Jun 26, 2009

I do agree with Michael. 1.5 devices is not the future. Its allready here...

Comment by m.kaeppler, Aug 04, 2009

The Android build fails with: Execute failed: java.io.IOException: Cannot run program "/home/matthias/devel/frameworks/android-sdk/tools/aapt": java.io.IOException: error=2, No such file or directory

What is AAPT? There is no such program in the tools folder of the 1.5 SDK.

The android-integration build also fails:

javac? /home/matthias/Desktop/zxing/android-integration/src/com/google/zxing/integration/android/IntentIntegrator?.java:154: cannot find symbol javac? symbol : variable Activity javac? location: class com.google.zxing.integration.android.IntentIntegrator? javac? if (resultCode == Activity.RESULT_OK) { javac? ^ javac? 20 errors

BUILD FAILED /home/matthias/Desktop/zxing/android-integration/build.xml:35: Compile failed; see the compiler error output for details.

Comment by sro...@gmail.com, Aug 04, 2009

It would be better to post a message on the discussion group at http://groups.google.com/group/zxing/

I believe the first one indicates you are using Android 1.5, but are using the code as of the last release, which was written for Android 1.1. The latest in SVN works with 1.5.

The second one, same ultimate reason. Try the latest from SVN.

Comment by drhu00, Aug 06, 2009

C:\svn-win32-1.4.6\bin\zxing-read-only\android>ant Buildfile: build.xml BUILD FAILED C:\svn-win32-1.4.6\bin\zxing-read-only\android\build.xml:64: taskdef class com.android.ant.SetupTask? cannot be found what's the problem?

Comment by drhu00, Aug 06, 2009

the above problem solved, but new problem dex:

echo? Converting compiled files and external libraries into bin/classes.dex...
apply? error: no command specified apply? usage: apply? dx --dex --debug? --verbose? --positions=<style>? --no-locals? apply? --no-optimize? --statistics? --[no-?optimize-list=<file>] --no-strict? apply? --keep-classes? --output=<file>? --dump-to=<file>? --dump-width=<n>? apply? --dump-method=<name>[*?] --verbose-dump? --no-files? --core-library? apply? | <file>.{zip,jar,apk} | <directory>? ... apply? Convert a set of classfiles into a dex file, optionally embedded in a apply? jar/zip. Output name must end with one of: .dex .jar .zip .apk. Positions apply? options: none, important, lines. apply? dx --annotool --annotation=<class> types>? apply? types>? apply? dx --dump --debug? --strict? --bytes? | --rop-blocks? apply? --width=<n>? | <file>.txt? ... apply? Dump classfiles in a human-oriented format. apply? dx --junit -wait? <TestClass> apply? Run the indicated unit test. apply? dx -J<option> ... <arguments, in one of the above forms> apply? Pass VM-specific options to the virtual machine that runs dx. apply? dx --version apply? Print the version of this tool (1.2). apply? dx --help apply? Print this message.

BUILD FAILED C:\svn-win32-1.4.6\bin\zxing-read-only\android\build.xml:218: apply returned: 1

Comment by sro...@gmail.com, Aug 06, 2009

Please use the discussion group or issue tracker, not wiki comments.

It sounds like dx can't be found; maybe you are not using Android 1.5 or haven't set the android-home var.

Comment by bansalcooldheeraj, Aug 24, 2009

How to run the application after building it from command prompt

Comment by sro...@gmail.com, Aug 24, 2009

Please use the discussion group for questions, not the wiki. http://groups.google.com/group/zxing/

You didn't specify which application you are talking about. But the page already tells you how to proceed to run all of them. Please read it.

Comment by bas5winkel, Sep 17, 2009

If java throws the following warning : Exception in thread "main" java.lang.NoClassDefFoundError?: com/google/zxing/clie nt/j2se/CommandLineRunner?

when you try to decode a barcode with the javase commandline utility (java -cp javase\javase.jar;core\core.jar com.google.zxing.client.j2se.CommandLineRunner? c:\temp\some_mysterous_barcode.jpg)
then notice that you're probably still inside the javase folder. Just go return to the parent folder and try again.=) I missed the 'cd..' command.

Comment by wenchao_...@163.com, Nov 17, 2009

today, I download ZXing V1.4, use follow command: java -cp javase\javase.jar;core\core.jar com.google.zxing.client.j2se.GUIRunner and then select a PDF417 picture in "data" fold, unfortunately, it doesn't work. I wonder if ZXing can't decode PDF417. Thanks!

Comment by sro...@gmail.com, Nov 17, 2009

Please use the discussion group for questions, not the wiki. http://groups.google.com/group/zxing/


Sign in to add a comment