将字节码转换为 dex 时出错:

Error converting byte code to dex:

Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2340Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72340Library UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72340Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2340Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72340Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42340Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2340Library UP-TO-DATE
:app:prepareComCouchbaseLiteCouchbaseLiteAndroid121Library UP-TO-DATE
:app:prepareComCouchbaseLiteCouchbaseLiteAndroidSqliteDefault121Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics920Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl920Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase920Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement920Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesTasks920Library UP-TO-DATE
:app:prepareComJakewhartonButterknife810Library UP-TO-DATE
:app:prepareComMiguelcatalanMaterialsearchview140Library UP-TO-DATE
:app:preparePlTajchertWaitingdots020Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:prePackageMarkerForDebug
:app:transformClassesWithDexForDebug
To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
:app:transformClassesWithDexForDebug FAILED
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_102\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 2 mins 52.839 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console

按照以下步骤操作

您已启用 "multiDexEnabled true",很可能您并未将其安装在应用程序 class 中。

这是你应该做的

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true       //You have already did this 
         }
}


dependencies {
    compile 'com.android.support:multidex:1.0.1'   // add this in  dependencies
}

最后扩展应用程序

public class YouApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}

这是一个很好的指南https://developer.android.com/studio/build/multidex.html

您的 gradle.build 中有多个支持库声明。 Here 是一个很好的指南,可以帮助您确定问题的原因。

您也可以试试这个简单的修复方法:

android {
    dexOptions {
        preDexLibraries = false
    }
}