zXing 1.7 for Android, on eclipse

7

Self Advertisement
—–Start of Advertisement——-
BUILD CAR POOL SOLUTIONS ON ANY DEVICE TO RUN ANYWHERE (www.mcruiseon.com). Introducing mCruiseOn, the java library /json api’s that you can use to build a car pool solution. Be the next avego.com, carpooling.com, zimride.com. mCruiseOn is your one stop API on EC2.
——End of Advertisement——-

The zxing guys have made it easier to create a android project with 1.7. Its not as painful as it used to be. This is a quick blog for anyone who would like to create a zxing project for android quickly.

- Checkout the zxing sources from zxing.org
- Create a Android project on your eclipse
- Delete main.xml
- Right click on “src” directory and hit import. Browse to the following directories in the order mentioned. As you add them for import one by one, ensure that you have the src directory in the edit field of the import wizard. And that you select only the “com” directory on the left directory tree. Do not select src.
* core
* android-integration
* android
- Ensure that your android sdk version is 9, anything lesser and androidmanifest.xml will cry.
- Strings.xml in one of the languages will crib, just put a / before the ‘ character

A android project for zxing 1.7 (June 20 checkout).

http://www.4shared.com/file/bFx8Y5Ys/zXingJune2010.html

Edited
One more interesting blog to help you out

http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/

Self Advertisement :)
BUILD CAR POOL SOLUTIONS ON ANY DEVICE TO RUN ANYWHERE (www.mcruiseon.com). Introducing mCruiseOn, the java library that you can use to build a car pool solution. Be the next avego.com, carpooling.com, zimride.com. mCruiseOn is your one stop API on EC2.

zXing Library License for the legally not initiated folks

2

This blog by no means takes any responsibility of understanding of the legal clause’s mentioned in the zXing library. Also this blog is restricted to the version of the license agreement that was visible online on 11th April 2011, not earlier and not later. http://www.apache.org/licenses/LICENSE-2.0

So, don’t come crying to me or hold me responsible for any legal action that zXing dudes may choose to hit you with. If you agree, carry on reading.

So this is what I understand from the license.
If you download the source code, include it in your project or use it as a library, you need to bring to the notice of all your fellow/future developers that this is code that has been downloaded from zXing. The way you do that is, “dont mess, edit or alter any part of the license agreement”. And include their license text in every file / project that you use.

You are free to use, alter or distribute, distribute for free or sell for a cost any application that includes zXing. zXing will have no part in the profit for those application, nor do you need to pay zXing for usage.

In short, enjoy its usage, but acknowledge the zXing dudes of their hard work, dont take that away.

Thats what I think, will try to get a confirmation of this in a few days. And update the blog.

zxing documentation, “the file dx.jar was not loaded from the sdk folder!”, conversion to dalvik format failed with error 1, zxing into android functionality,

0

We all know that android sdk comes complete with java sdk build in. This sdk is light weight and customized for use by the dalvik engine. Now, if we also add java jar’s along with the android app, obviously the android system will have trouble converting that java jar to dalvik. Hence the “conversion to dalvik” issue.

So now that you know what happens, lets figure out why it happens.

The zxing library today does not allow a clean way to include the library into your project. Ideally they should provide a android_zxing.jar file that we can just include and freak out. But, we need to download the source, take the relevant folders import it into a new project and add that project as a dependent project to our customized app.

Now, when you do the import a whole lotta things happen. Each directory that you import from the zxing download has androidmanifest.xml, default.properties.. So things get over written again and again and again. So once you have imported the directories, close the project. Delete it, reimport the “just imported project” and try. Should work.

Refer to my blog (http://mcondev.wordpress.com/2011/03/02/zxing-into-android-for-barcode-reading-functionality-original-project-100mb-imported-3mb/) on this for the import process.

Dont forget to import the “android” folder last.

Have fun. If you get issues, post comments, I’ll try to respond.

zXing into Android for Barcode reading functionality (original project 100Mb, imported 3Mb)

17

The zXing documentation is rather complex. A simple task of integrating the zXing library can be painful. Here I am trying to document the steps needed for including zXing as part of your android application.

We have 2 choices. Either to include all the source as part of the android application project itself, or create a new project and import relevant files into this new project. Obviously if you create a new project we need to add the zxing project as a dependent project to your android app project.

This is what I did and things worked for me. I was able to only include 3Mb worth files, instead of the entire 105 Mb.
- checkout the sources from (using svn) http://code.google.com/p/zxing/source/checkout
- Use svn export on the checkedout project, so that you dont get the .svn folders (if u miss this step, you will not be able to import this project into your svn server)
- Create a new java project
- Right click on src directory and hit import
- Select only the “src” sub directory of the following zXing project directories
* core
* javase
* android
* androidtest
* android-integration
- Do not import the test directories from core/javase/android/androidtest/android-integration at first. Do the src imports, get things to work and then play around with test (the same way you did the src).

In your AndroidManifest.xml

In your button click

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
intent.putExtra("SCAN_MODE", "ONE_D_MODE");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myAndroidAppActivity.startActivityForResult(intent,0) ;

In your response listener (source of below code snippet, http://stackoverflow.com/questions/2050263/using-zxing-to-create-an-android-barcode-scanning-app)

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}

Troubleshooting
Q : Getting multiple errors in the src directory of my new project. The import changed the package name to something like “android.src.com.google……”.
A1 : While you import you need to “right click” on the “src” folder of your new project. And hit import. You may have selected import on your project instead of the “src” folder.
A2 : While importing you may have selected the folder “android”, instead of “android/src”.