Dex加载器无法执行多个dex文件定义
好吧,现在我真的被困在这里了。我不知道该做什么,去哪里,什么都不知道!
我一直在尝试卸载、重新安装 SDK 和 Eclipse 版本,并尝试通过 Google 搜索到此信息,但是……什么也没有!
我可以在模拟器中运行我的应用程序,但我无法导出它......
[2011-10-07 16:35:30 - Dex Loader] 无法执行 dex:多个 dex 文件定义 Lcom/dreamhawk/kalori/DataBaseHelper;
这是 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);
}
}
我怀疑:
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
但我不知道该怎么办...请帮助! :'(
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 !!! :'(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
库和应用程序项目都包含相同的 DataBaseHelper.java 文件。只需将其从 App 项目中排除即可。
Both the Library and the App projects contain the same a DataBaseHelper.java file. Just exlude it from the App project.
当我有同一个库的两个副本时(我有 Android 支持库版本 4 的两个不同修订版),我就遇到了这种情况。一旦我删除了其中一个 - 项目就编译好了并且我能够运行它。
担
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
哇终于...
这个错误非常可怕。我最终所做的是下载最新版本的 Eclipse Java EE,然后将 ADT 插件安装到新的 Eclipse 中。
请参阅安装 Eclipse 插件。
之后,我像平常一样配置了我的项目,并使用了此处找到的导出指南:
签署您的应用程序
但无论如何我已经看到了很多答案..而实际问题极难诊断。
问题可能在于ADT插件和Eclipse IDE不兼容。
我只知道使用最新版本将使事情正常运行(截至 2012 年 9 月 5 日)。
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).
尝试执行以下步骤:
禁用“项目->自动构建”选项,然后“清理”和“构建”项目,然后尝试运行。
对我有用。
可以将“自动构建”选项设置为“开”
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
我还看到“多个 dex 文件定义”消息。在阅读了有关 R14 中的一些更改后,我删除了项目的 bin 目录,按照上面 @abbandon 的描述清理并重建项目,然后重新启动 Eclipse。这些步骤为我解决了问题。
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.
对我来说,当我遇到这个问题时,我正在使用 Android studio,我正在使用 Google Admob 和 Analytics 外部 SDK。
现在他们将它们与 kitkat SDK 一起提供,这导致了冲突,解决方案是打开 project.iml 文件并删除以下行:
希望它有帮助,小心..
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 :
Hope it helps, take care..
通过从 libs 文件夹中删除第 3 方库来修复此问题。
最初我尝试使用 ant 构建 ActionBarSherlock 和 MenuDrawer 的 jar,但它不起作用。
从 libs 目录中删除这些 jar 修复了该错误
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
就我而言,libs 文件夹中包含两个不同的 jar 文件。
我删除了其中之一,它解决了我的问题。
In my case there were two different jars files included in libs folder.
I have removed one of them it solve my issue.
如果您要从另一个项目导入支持 jar,您需要转到
*Java 构建路径
* 在“订购和导出”上单击支持 jar 并将其放在依赖项之上
重建项目。
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.
在 Cordova 中,libs 文件夹中有一个我们在构建路径中设置的文件。我已经更新了 cordova 并更新了 jar 文件,但忘记删除 libs 文件夹中的旧 jar 文件。删除了旧的,项目工作得非常顺利!
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!
这里的建议都没有为我解决这个问题。这就是我修复它的方法:
在文件 /proj.android/jni/Application.mk 的第三行中,它指定在“mips”中构建。我将其更改为 APP_ABI:=armeabi-v7a,以便它可以正确找到所有预构建的库。
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.
删除项目中的Libs文件夹,新建Lib_src文件夹,再次导入jar。
并右键单击项目 ->构建路径->配置构建路径,选择Libs文件夹并单击删除,单击按钮添加文件夹->选择 Lib_src ->好的
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
bin/dexedLibs 中有一个文件
libs 中存在相同的文件
将其删除在 libs 中,它应该可以工作。
对我来说是 android-support-v4.jar。
希望这有帮助
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
通过以下简单步骤修复它:
图书馆
Fixed it by following simple steps
libraries
这对我有用..:)
This worked for me.. :)
我今天(2011 年 10 月 21 日)更新了 eclipse(
帮助->检查
更新),现在我没有看到错误。在此之前,我遇到错误“无法执行 dex:多个 dex 文件定义
”。希望这有帮助。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.问题解决了。
在升级之前,我有3个android项目:App1、App2和Lib。 Lib 是一个 Android 库项目,App1 和 App2 使用它。
升级 ADT 和 SDK 后,我看到了类似的错误
解决方案是删除 App1 和 App2 中名为“Lib_src”的文件夹。
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
The solution was to remove in both App1 and App2 the folder called "Lib_src".