This may seem to be a duplicate of many existing similar questions. But I've read almost all discussions and none is helping. My goal is to embed zxing library into my application, and scan QRCodes without needing to reference external application. Current platform I'm targeting is android 4.2.

I've completed the following steps over and over :

  1. Download zxing-2.3.0 source
  2. Compiled zxing-2.3.0/core using Maven - got the core-2.3.0.jar
  3. Created a new Project with zxing-2.3.0/android/ , added core-2.3.0.jar to /libs folder , changed switch statements to if{} clause , removed final from CaptureActivity, marked as library, build = captureactivity.jar
  4. Returned back to my original app. Added core-2.3.0.jar and captureactivity.jar to my /libs folder.
  5. Also added libs/captureactivity.jar as a library under Properties/Java Build Path/Libraries/Add JARS/.. (this makes no difference though, i'll get the same error even if i dont)
  6. I created a class called ScannerActivity extending CaptureActivity (Details Below)

When I run the application I see a lot of resource resolve problems from dalvikvm before finally getting the exception. To my understanding/testing zxing library cannot access is local Resource files or static variables when compiled as a library. It'll finally blow up with a NoClassDefFoundError trying to locate the RelativeLayout for CaptureActivity.

Here is a reduced list of error types I'm getting.

01-04 23:30:37.851: W/dalvikvm(9804): VFY: unable to resolve static field 1711 (decode_succeeded) in Lcom/google/zxing/client/android/R$id;
01-04 23:30:37.851: D/dalvikvm(9804): VFY: replacing opcode 0x60 at 0x0011
01-04 23:30:37.851: W/dalvikvm(9804): VFY: unable to resolve static field 1761 (app_name) in Lcom/google/zxing/client/android/R$string;
01-04 23:30:37.851: D/dalvikvm(9804): VFY: replacing opcode 0x60 at 0x0005
..................(more of similar)
01-04 23:30:37.875: I/dalvikvm(9804): DexOpt: unable to optimize static field ref 0x0702 at 0x0e in Lcom/google/zxing/client/android CaptureActivity;.displayFrameworkBugMessageAndExit
01-04 23:30:37.875: I/dalvikvm(9804): DexOpt: unable to optimize static field ref 0x06eb at 0x17 in Lcom/google/zxing/client/android/CaptureActivity;.displayFrameworkBugMessageAndExit
..................(more of similar)
01-04 23:30:43.617: E/AndroidRuntime(9804): FATAL EXCEPTION: main
01-04 23:30:43.617: E/AndroidRuntime(9804): java.lang.NoClassDefFoundError:$layout
01-04 23:30:43.617: E/AndroidRuntime(9804):     at
..................(rest of exception stack)


import android.os.Bundle;
import android.widget.Toast;


public class ScannerActivity extends CaptureActivity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

    public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {
        Toast.makeText(this.getApplicationContext(), "Scanned code " + rawResult.getText(), Toast.LENGTH_LONG);

Here is AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="3.0" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- uses-permission android:name="android.permission.ACCESS_WIFI_STATE" / -->
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />

        android:targetSdkVersion="17" />
    <!-- android:theme="@style/AppTheme" -->
        android:theme="@style/CustomTheme" >

            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

        <!-- service android:name="com.commonsware.cwac.updater.UpdateService"/ -->
        <!-- receiver android:name="com.commonsware.cwac.updater.WakefulReceiver"/ -->

        <receiver android:name="" >
                <action android:name="" >


What else I've tried : I've played with zxing /android source (captureactivity.jar) by modifying it, tried to remove references with direct values (hard coded), pulled out some of the classes to my own project, changed some source accessors to public, etc, and I had some success with that, I even got the camera working, but I couldn't manage it at the end, the scope is just too big to handle, so I reverted back.

From my experience the problem seems to arise from generated library(captureactivity.jar) not being able to reference it's internal resources, but i might be wrong. My problem seems to be more fundamental than technical. What am I doing wrong?

Related posts

Recent Viewed