سؤال

I try to integrate the zxing-Library into an Android app, so the user does not have to have zxing installed.

What I did:

  • Download Zxing-2.2.zip
  • creating an own build.xml (in core/... was none):

    <?xml version="1.0" encoding="utf-8" ?>
    <project name="core" default="jar" basedir=".">
        <target name="compile" description="Compile source">
            <mkdir dir="bin" />
            <javac srcdir="src" includes="**" destdir="bin"/>
            <copy todir="bin">
                <fileset dir="src" />
            </copy>
        </target>
        <target name="jar" description="Package into JAR" depends="compile">
            <jar destfile="core.jar" basedir="bin" compress="true" />
        </target>
    </project>
    
  • creating an core.jar with ant -f core/build.xml

  • in Eclipse creating Android Project from existing code
  • creating folder in eclipse for core.jar ("libs")
  • pasting jar in there
  • also doing the last 2 steps in the app which will call the zxing-lib
  • in "xzing-lib-app" preferences => android => check as library
  • in the calling app preferences => android => librarys => add => "xzing-lib-app"

What I also tried:

  • adding the core.jar to the library via configure build path (in addition to the automatically added)
  • setting the checkbox at the export tab
  • moving the library to the top there
  • cleaning the both projects
  • ...

And this is the upper part of the appearing errors

02-21 11:34:55.055: E/AndroidRuntime(8797): FATAL EXCEPTION: main
02-21 11:34:55.055: E/AndroidRuntime(8797): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.hit.scantohit/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity

the Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.hit.scantohit"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.CAMERA"/>

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="14" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.hit.scantohit.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

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

                <data
                    android:host="scanclinet"
                    android:scheme="hitscheme" />
                <!-- myscheme://myhost ==> hitscheme://scanclinet -->
            </intent-filter>
        </activity>
        <activity
            android:name="com.google.zxing.client.android.CaptureActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="landscape"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="stateAlwaysHidden" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.zxing.client.android.SCAN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

the layout xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/btn_start_hit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/btn_start_scan"
        android:layout_alignBottom="@+id/btn_start_scan"
        android:layout_marginLeft="63dp"
        android:layout_toRightOf="@+id/btn_start_scan"
        android:text="HIT" />

    <Button
        android:id="@+id/btn_start_scan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="42dp"
        android:layout_marginLeft="83dp"
        android:text="SCAN" />

</RelativeLayout>

Does anyone knows any help?

هل كانت مفيدة؟

المحلول 3

I could solve the problem by using Zxing 2.1 instead of 2.2. like descriped here:
http://khurramitdeveloper.blogspot.ch/p/android-barcode-scan-using-zxing-library.html

And here you can get the Zxing 2.1
https://code.google.com/p/zxing/downloads/detail?name=ZXing-2.1.zip

نصائح أخرى

try it out

 In ZXing:

 1. Right click on project 
   2. Click Properties 
3. Click Android in the left hand side menu 
 4. Check Is Library 

  In my app: 
 1. Right click on project 
 2. Click Properties 
 3. Click Android in the left hand side menu 
  4. Click Add 
  5. Select the ZXing project

The way I have the ZXing library included in my code is having the Core.jar file (the pre-built one) in the libs folder of the project in Eclipse (no need to change the Build path manually) and I have the ZXing project (which is a library) in my Eclipse workspace. What you need to do is just right click on your project in Eclipse and go to Properties->Android->Library section, click add and choose the ZXing android project (which has to be marked as a library).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top