Saturday, April 23, 2011

ZXing

How I set up ZXing
  1. download ZXing file
  2. Follow the directions in here under "Run" stop at "Run on Android".
      A test [URL] can be, in .../zxing-read-only, $ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner http://www.idautomation.com/ucc_ean_128.jpeg
      http://www.idautomation.com/ucc_ean_128.jpeg (format: CODE_128, type: TEXT): Raw result: 81007123452112345678 Parsed result: 81007123452112345678 Also, there were 2 result points. Point 0: (12.5,26.0) Point 1: (167.5,26.0)
  3. You should set up a new Android project by doing: File > New > Project > Select "Android Project" under Android > Next > Create project from existing source and navigate to the "android" folder of your downloaded ZXing file. Put a name. and a platform.
  4. At this point, I got errors like this:
    The import com.google.zxing.BarcodeFormat cannot be resolved (at least in src > com.google.zxing.client.android > CaptureActivity.java)
    Here is the way to fix these errors, adapted from here.
    Right click on Project Name
    - Go to New -> Source Folder
    - For Folder name, call it "srccore"
    - Click on Finish

    Right click on "srccore"
    - Click on Import
    - Click on File System > Next
    - For "From directory:" type in [full path to]/zxing/core/src
    - Make sure the checkbox next to "src" is checked
    - Finish

    Go to Project -> Clean
  5. Run it (might take a while), you should see the square moves around:


  6. Done! Btw, if you want to resize your emulator.
I don't have a real phone, should look at this to fake a camera.

Old notes with things that didn't work
haoqili@stay-focused-hq:13:04:51:~/Desktop/6.857/proj/zxing-read-only$ cd core
haoqili@stay-focused-hq:13:04:52:~/Desktop/6.857/proj/zxing-read-only/core$ ant
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar
Buildfile: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build.xml

clean:

build:

init:

compile:
    [mkdir] Created dir: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
    [javac] Compiling 177 source files to /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build

BUILD FAILED
/home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build.xml:54: The following error occurred while executing this line:
/home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build.xml:37: Error running javac compiler

Total time: 1 second

http://ubuntuforums.org/archive/index.php/t-870670.html


haoqili@stay-focused-hq:13:12:51:~/Desktop/6.857/proj/zxing-read-only/core$ sudo update-alternatives --config java
[sudo] password for haoqili:
There is only one alternative in link group java: /usr/lib/jvm/java-6-openjdk/jre/bin/java
Nothing to configure.


http://www.webupd8.org/2010/10/sun-java-finally-uploaded-to-ubuntu.html

sudo apt-get update

sudo apt-get install sun-java6-jre

sudo apt-get install sun-java6-jdk




haoqili@stay-focused-hq:15:57:05:/usr/lib/jvm$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).


  Selection    Path                                      Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java       63        manual mode


Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-6-sun/jre/bin/java to provide /usr/bin/java (java) in manual mode.

haoqili@stay-focused-hq:15:23:34:~/Desktop/6.857/proj/zxing-read-only/core$ sudo update-java-alternatives -l
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
haoqili@stay-focused-hq:15:25:49:~/Desktop/6.857/proj/zxing-read-only/core$ sudo update-java-alternatives -l
[sudo] password for haoqili: 
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun
haoqili@stay-focused-hq:15:58:54:~/Desktop/6.857/proj/zxing-read-only/core$ ant
Buildfile: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build.xml

clean:
   [delete] Deleting directory /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build

build:

init:

compile:
    [mkdir] Created dir: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
    [javac] Compiling 177 source files to /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
      [jar] Building jar: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/core.jar

BUILD SUCCESSFUL
Total time: 8 seconds
haoqili@stay-focused-hq:15:59:20:~/Desktop/6.857/proj/zxing-read-only/core$ cd ../javase
haoqili@stay-focused-hq:16:03:32:~/Desktop/6.857/proj/zxing-read-only/javase$ ls
build.xml  pom.xml  src
haoqili@stay-focused-hq:16:03:33:~/Desktop/6.857/proj/zxing-read-only/javase$ ant
Buildfile: /home/haoqili/Desktop/6.857/proj/zxing-read-only/javase/build.xml

init:

build:
    [mkdir] Created dir: /home/haoqili/Desktop/6.857/proj/zxing-read-only/javase/build
    [javac] Compiling 6 source files to /home/haoqili/Desktop/6.857/proj/zxing-read-only/javase/build
      [jar] Building jar: /home/haoqili/Desktop/6.857/proj/zxing-read-only/javase/javase.jar

BUILD SUCCESSFUL
Total time: 6 seconds
haoqili@stay-focused-hq:16:03:44:~/Desktop/6.857/proj/zxing-read-only/javase$ 



haoqili@stay-focused-hq:16:04:27:~/Desktop/6.857/proj/zxing-read-only$ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner [URL]
Exception in thread "main" java.net.URISyntaxException: Illegal character in path at index 0: [URL]
at java.net.URI$Parser.fail(URI.java:2809)
at java.net.URI$Parser.checkChars(URI.java:2982)
at java.net.URI$Parser.parseHierarchical(URI.java:3066)
at java.net.URI$Parser.parse(URI.java:3024)
at java.net.URI.<init>(URI.java:578)
at com.google.zxing.client.j2se.CommandLineRunner.decodeOneArgument(CommandLineRunner.java:210)
at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:104)

haoqili@stay-focused-hq:16:04:49:~/Desktop/6.857/proj/zxing-read-only$ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner http://www.idautomation.com/ucc_ean_128.jpeg
http://www.idautomation.com/ucc_ean_128.jpeg (format: CODE_128, type: TEXT):
Raw result:
81007123452112345678
Parsed result:
81007123452112345678
Also, there were 2 result points.
  Point 0: (12.5,26.0)
  Point 1: (167.5,26.0)



===========
Android



[2011-04-23 16:45:51 - ZXing] ERROR: Unable to open class file /home/haoqili/workspace/ZXing/gen/com/google/zxing/client/android/R.java: No such file or directory

Then I run emulator, when I click on the scan barcode ap, goes black blank and goes to front page again.

===
Second (Android) part of: 
http://code.google.com/p/zxing/wiki/GettingStarted

android-home=/home/haoqili/Desktop/6.857/proj/android-sdk-linux_x86
proguard-jar=/home/haoqili/Desktop/6.857/proj/proguard4.6/lib/proguard.jar


haoqili@stay-focused-hq:17:39:53:~/Desktop/6.857/proj/zxing-read-only/core$ ant clean build-no-debug
Buildfile: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build.xml

clean:
   [delete] Deleting directory /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
   [delete] Deleting: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/core.jar

clean:

build-no-debug:

init:

compile:
    [mkdir] Created dir: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
    [javac] Compiling 177 source files to /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
      [jar] Building jar: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/core.jar

BUILD SUCCESSFUL
Total time: 6 seconds


I copied the contents of android to workspace/ZXing, so I went there to "build android"

haoqili@stay-focused-hq:17:41:28:~/workspace/ZXing$ ant
Buildfile: /home/haoqili/workspace/ZXing/build.xml

BUILD FAILED
/home/haoqili/workspace/ZXing/build.xml:64: taskdef class com.android.ant.SetupTask cannot be found
 using the classloader AntClassLoader[]

Total time: 0 seconds

===
Looks like I shouldn't have moved it. 
Eck. Try again by building a project from the file (see top)

The scanner worked [insert pictures]

==
last step of Building android is stil bad

haoqili@stay-focused-hq:22:11:37:~/Desktop/6.857/proj/zxing-read-only/android$ ant
Buildfile: /home/haoqili/Desktop/6.857/proj/zxing-read-only/android/build.xml

BUILD FAILED
/home/haoqili/Desktop/6.857/proj/zxing-read-only/android/build.xml:64: taskdef class com.android.ant.SetupTask cannot be found
 using the classloader AntClassLoader[]

Total time: 0 seconds


3 comments:

  1. Unbelievable. You are the b e s t !!!
    I tried to run the barcode scanner project at least a week from several different articles with no luck. with your article it works like a charm.

    Thank you so much :)
    Chen

    ReplyDelete
  2. It works!! Thanks you so much!!

    sorry for my poor english.. OwQ

    ReplyDelete
  3. Hi, I tried what you suggested for the import. I still get errors like this for example: The method encode(String, BarcodeFormat, int, int, Map) of type MultiFormatWriter must override a superclass method. It seems like every override is giving me this error. What do you think? Thanks.

    ReplyDelete