如何解决安卓多DEX文件定义异常 [英] How to fix android Multiple dex files define exception

查看:711
本文介绍了如何解决安卓多DEX文件定义异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的4.2 ZBar codescan的Java应用程序需要在Windows 7 64位系统的计算机进行编译。

Android 4.2 ZBarCodescan java application needs to compiled in Windows 7 x64 computer.

它的来源$ C ​​$ c是位于此处

Its source code is located here.

Android的工作室安装和code使用Github上导入命令导入。
在文件的Gradle API改为23

Android Studio is installed, and code is imported using Github import command. In gradle file API was changed to 23

compileSdkVersion 23 

根据

<一个href=\"http://stackoverflow.com/questions/36099379/how-to-use-eclipse-project-from-github-for-android-development\">How使用Eclipse项目从GitHub为Android开发

Android的工作室构建APK命令产生的例外

Android studio Build APK command produces exception

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)

试图通过添加几行来解决这个问题。

Trying to fix this by adding lines

dexOptions {
    preDexLibraries = false
}

根据双方的gradle项目行

to both project gradle lines according to

<一个href=\"http://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility\">Multiple DEX文件定义Landroid /支持/ V4 / accessibilityservice / AccessibilityServiceInfoCompat

导致错误

Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoJellyBeanMr2;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoStubImpl;

如何解决这一问题?

How to fix this ?

<一个href=\"http://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility\">Answer这里建议检查依赖关系树。如何获得此树的Andr​​oid Studio和如何解决它?

Answer here recommends to examine dependency tree. How to get this tree in Android Studio and how to fix it ?

取出后Android的支持,v4.jar例外

After removing android-support-v4.jar exception

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)

仍会发生。

更新。我用试图importfixes分支 https://github.com/cricket007/DeviceSDK/tree/fixes
url,但测试按钮和进口农产品误差

Update. I tried to importfixes branch using https://github.com/cricket007/DeviceSDK/tree/fixes url but Test button and import produce error

错误

如何导入这个分支?

推荐答案

我做了一个拉入请求,以得到它的Andr​​oid Studio中的工作后,库。

I made a pull request to the library after getting it to work in Android Studio.

如果你试图建立的时候得到这个错误

If you get this error when trying to build

找不到SDK位置。与在local.properties文件,或与ANDROID_HOME环境变量sdk.dir定义的位置。

SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

或者你没有看到这一点,但任何错误说法 local.properties 缺少执行导入时,再加入 local.properties指向您的Andr​​oid SDK的位置文件,然后试图导入/重建。

Or you don't see that, but any error saying local.properties is missing when doing an import, then add a local.properties file that points to your Android SDK location, then trying to import/rebuild.

例如在Mac上,该文件将包含这条线,但显然在改变你们各自的SDK的位置的文件路径点

For example on a Mac, that file would contain this line, but obviously change the file path to point at your respective SDK's location

sdk.dir=/usr/local/opt/android-sdk

在与该完成的,它应该加载到Android Studio中没有问题。

Once done with that, it should load into Android Studio without a problem.

在code也被测试在4.2模拟器。

The code was also tested on a 4.2 emulator.

通过一个Git终端的简单方法(可以做使用Git桌面相同)。

The easy way via a Git Terminal (could do the same with Git Desktop).

git clone https://github.com/cricket007/DeviceSDK /path/to/download/
cd /path/to/download/
git branch fixes

然后导入/路径/要/下载/ DeviceSDK到Android的工作室作为导入项目摇篮

Then import /path/to/download/DeviceSDK into Android Studio as Import Project Gradle

在很长的路要走(通过Android的一室公寓)

The long way (via Android Studio)

使用 https://github.com/cricket007/DeviceSDK.git 作为Git的回购

Use https://github.com/cricket007/DeviceSDK.git as the Git repo

导入

打开项目,可以忽略大多数的错误,弹出

Open Project, you can ignore most errors that popup

围棋菜单栏,选择 VCS>启用版本控制集成

启用VCS

选择的Git

返回 VCS>的Git>分支机构

结帐修复作为一个新的本地分支

Checkout fixes as a new local branch

选择分支

结帐

命名分支。

选择强制结帐如果提示

我不知道有摇篮什么项目点击运行按钮,但你应该打开右侧和开放TestDemo摇篮查看,选择 installDebug

I don't know what clicking the Run button does with a Gradle project, but you should open Gradle View on the right side and open TestDemo, select installDebug

摇篮视图

从这里开始,你需要以上的 local.properties 文件解决方案,并在模拟器上物理设备或测试上启用ADB调试。

From here on you need the solution above for the local.properties file and enable ADB debugging on a physical device or test on an emulator.

这篇关于如何解决安卓多DEX文件定义异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆