Dex Loader Unable to execute Multiple dex files de

2019-01-31 17:14发布

问题:

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 !!! :'(

回答1:

I updated eclipse (Help->Check for updates) today (21st October,2011) and now I don't see the error. Before it I had error "Unable to execute dex: Multiple dex files define". Hope this helps.



回答2:

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



回答3:

Fixed it by following simple steps

  • right click project
  • go to properties
  • click Java Build Path
  • on 'order and export' tab uncheck jar files and dependencies libraries
  • rebuilt project.


回答4:

  1. Restart eclipse,
  2. Delete bin & gen folder and
  3. Finally clean up the project and build it again.

This worked for me.. :)



回答5:

Problem solved.

Before upgrading, I had 3 android projects: App1, App2 and Lib. Lib is an Android Library project and App1 and App2 use it.

After upgrading both ADT and SDK I saw errors like

[2012-12-05 15:54:10 - Dex Loader] Unable to execute dex: Multiple dex files define Lxxx;
[2012-12-05 15:54:10 - TrailGuide] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lxxx;

The solution was to remove in both App1 and App2 the folder called "Lib_src".



回答6:

Both the Library and the App projects contain the same a DataBaseHelper.java file. Just exlude it from the App project.



回答7:

I had this happen to me when I had two copies of the same lib (I had two different revisions of the Android support library version 4). Once I removed one of them - the project compiled and I was able to run it. Dan



回答8:

WOW finally...

This error was quite gruesome. What I did eventually was download the latest version of Eclipse Java EE, then I installed the ADT plugin into the new Eclipse. See Installing the Eclipse Plugin.

Afterwards, I configured my project like normal, and used the exporting guidelines found here: Signing Your Applications

But anyways I've seen many answers... and the actual problem is extremely difficult to diagnose. Possibility is that the problems lies in incompatibility between ADT plugin and Eclipse IDE. I just know that using the most recent versions will make things work (as of Sep 5th, 2012).



回答9:

Try follow steps: Disable "Project->Build Automatically" option, then "Clean" and "Build" project, then try to run. works for me. can set back "Build Automatically" option to On



回答10:

I was also seeing the "Multiple dex files define" message. After reading about some of the changes in R14, I deleted the the bin directory for my project, cleaned and rebuilt the project as described by @abbandon above and restarted Eclipse. These steps cleared the problem for me.



回答11:

for me, I was using Android studio when I hit this issue, I was using Google Admob and Analytics external SDKs.

Now they are shipping them with the kitkat SDK, which caused the conflict, the solution was to open project.iml file and remove the following lines :

<orderEntry type="module-library">
  <library>
    <CLASSES>
      <root url="jar://$USER_HOME$/Downloads/Ads/lib/amazon-ads-4.0.9.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
</orderEntry>
<orderEntry type="module-library">
  <library>
    <CLASSES>
      <root url="jar://$USER_HOME$/Downloads/Folx/application/GoogleAdMobAdsSdk-6.2.1/Add-ons/googleanalyticsandroid/libGoogleAnalyticsV2.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
</orderEntry>

Hope it helps, take care..



回答12:

Fixed it by deleting 3rd party libraries from the libs folder.

Initially i tried to build jars of ActionBarSherlock and MenuDrawer using ant but it didn't work.

Deleting these jars from libs directory fixed the bug



回答13:

In my case there were two different jars files included in libs folder.

I have removed one of them it solve my issue.



回答14:

if you are importing a support jar from another project you need to go to *Java Build Path * on 'order and export' click on the support jar and put it on top of your dependencies rebuilt project.



回答15:

In Cordova, in libs folder there is a file that we set in build path. i have updated cordova and update the jar file but forget to delete the old jar file in libs folder. removed the old one and project worked like a charm!



回答16:

None of the suggestions here resolved it for me. This was how I fixed it:

Inside the file /proj.android/jni/Application.mk on the 3rd line, it was specifying to build in "mips". I changed this to APP_ABI:=armeabi-v7a so it can find all the prebuilt libraries correctly.



回答17:

Removed Libs folder in project, new Lib_src folder, import jar again. and right click project -> Build Path -> Config Build path, selected Libs folder and click Remove, Click Button Add Folder -> select Lib_src -> OK