Dex Loader Unable to execute Multiple dex files define

DreamHawk picture DreamHawk · Oct 7, 2011 · Viewed 73.9k times · Source

Okay, now i'm really stuck here. I don't know what to do, where to go or ANYTHING!

I have been trying to uninstall, reinstall, both SDK and Eclipse-versions, trying to Google this out, but nu-uh... Nothing!!!

I CAN run my app in emulator, but i cant EXPORT it...

[2011-10-07 16:35:30 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/dreamhawk/kalori/DataBaseHelper;

this is dataBaseHelper

package com.dreamhawk.kalori;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;



public class DataBaseHelper extends SQLiteOpenHelper {

    // The Android's default system path of your application database.
    private static String DB_PATH = "/data/data/com.dreamhawk.kalori/databases/";

    private static String DB_NAME = "livsmedel_db";
    private DataBaseHelper myDBHelper;
    private SQLiteDatabase myDb;

    private final Context myContext;

    private static final String DATABASE_TABLE = "Livsmedel";
    public static String DB_FILEPATH = "/data/data/com.dreamhawk.kalori/databases/lifemedel_db";
    public static final String KEY_TITLE = "Namn";
    public static final String KEY_BODY = "Kcal";
    public static final String KEY_ROWID = "_id";
    private static final int DATABASE_VERSION = 2;

    /**
     * Constructor Takes and keeps a reference of the passed context in order to
     * access to the application assets and resources.
     * 
     * @param context
     */
    public DataBaseHelper(Context context) {

        super(context, DB_NAME, null, 1);
        this.myContext = context;

        // checking database and open it if exists
        if (checkDataBase()) {
            openDataBase();
        } else {
            try {
                this.getReadableDatabase();
                createDatabase();
                this.close();
                openDataBase();

            } catch (IOException e) {
                throw new Error("Error copying database");
            }
            Toast.makeText(context, "Livsmedelsdatabasen importerad",
                    Toast.LENGTH_LONG).show();
        }

    }

    private boolean checkDataBase() {
        SQLiteDatabase checkDB = null;
        boolean exist = false;
        try {
            String dbPath = DB_PATH + DB_NAME;
            checkDB = SQLiteDatabase.openDatabase(dbPath, null,
                    SQLiteDatabase.OPEN_READONLY);
        } catch (SQLiteException e) {
            Log.v("db log", "database does't exist");
        }

        if (checkDB != null) {
            exist = true;
            checkDB.close();
        }
        return exist;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // db.execSQL(DATABASE_CREATE);
    }

     @Override
     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

           Log.w("Kalori", "Upgrading database from version " + oldVersion + " to "
               + newVersion + ", which will destroy all old data");
           db.execSQL("DROP TABLE IF EXISTS Livsmedel");
           onCreate(db);

       }

    public DataBaseHelper open() throws SQLException {
        myDBHelper = new DataBaseHelper(myContext);
        myDb = myDBHelper.getWritableDatabase();
        return this;
    }

    public void createDatabase() throws IOException {

        InputStream assetsDB = myContext.getAssets().open("livsmedel_db");
        // OutputStream dbOut = new FileOutputStream(DB_PATH);
        String outFileName = DB_PATH + DB_NAME;
        OutputStream dbOut = new FileOutputStream(outFileName);

        Log.d("DH", "index=" + assetsDB);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = assetsDB.read(buffer)) > 0) {
            dbOut.write(buffer, 0, length);
        }

        dbOut.flush();
        dbOut.close();
        assetsDB.close();
    }

    public Cursor fetchAllNotes() {

        return myDb.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_TITLE,
                KEY_BODY }, null, null, null, null, null);
    }

    public void openDataBase() throws SQLException {
        String dbPath = DB_PATH + DB_NAME;
        myDb = SQLiteDatabase.openDatabase(dbPath, null,
                SQLiteDatabase.OPEN_READWRITE);
    }

}

I suspect:

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

But I don't know what to do... Please help !!! :'(

Answer

Ahmed Zaidi picture Ahmed Zaidi · Dec 9, 2012

There is a file in bin/dexedLibs The same file exists in libs

Delete it in libs and it should work.

For me it was the android-support-v4.jar.

Hope this helps