Whenever I am Trying to Re-Build or Run my Code, following Error is coming: Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

> 
> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
> 
> 
> 

I have checked many solutions but none solved it. Following is the link.
 [Unable to Merge Dex - Android Studio 3.0](https://stackoverflow.com/questions/46949761/unable-to-merge-dex-android-studio-3-0/46971548#46971548)

Running gradle console with stack tree gave 4 errors:

1. Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
2. Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
3. Error:com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
4. Error:com.android.dex.DexException: Multiple dex files define Landroid/arch/lifecycle/LiveData;

Running with debug-option gave :

> 
> Error:10:49:47.799 [ERROR] [system.err] Note: Some input files use or
>  override a deprecated API. 10:49:47.799 [ERROR] [system.err] Note:
>  Recompile with -Xlint:deprecation for details. 10:50:01.875 [ERROR]
>  [org.gradle.internal.buildevents.BuildExceptionReporter] 10:50:01.875
>  [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
>  FAILURE: Build failed with an exception. 10:50:01.875 [ERROR]
>  [org.gradle.internal.buildevents.BuildExceptionReporter] 10:50:01.875
>  [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] \*
>  What went wrong: 10:50:01.875 [ERROR]
>  [org.gradle.internal.buildevents.BuildExceptionReporter] Execution
>  failed for task
>  ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
>  10:50:01.875 [ERROR]
>  [org.gradle.internal.buildevents.BuildExceptionReporter] >
>  com.android.builder.dexing.DexArchiveMergerException: Unable to merge
>  dex 10:50:01.875 [ERROR]
>  [org.gradle.internal.buildevents.BuildExceptionReporter] 10:50:01.875
>  [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] \*
>  Try: 10:50:01.875 [ERROR]
>  [org.gradle.internal.buildevents.BuildExceptionReporter] Run with
>  --stacktrace option to get the stack trace. 10:50:01.875 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:50:01.875
>  [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] \* Get
>  more help at <https://help.gradle.org> 10:50:01.875 [ERROR]
>  [org.gradle.internal.buildevents.BuildResultLogger] 10:50:01.875
>  [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD
>  FAILED in 1m 7s
> 
> 
> 

Please, Help I am making a Chat App using Firebase. I am stuck here for 2 days, I am unable to continue further.

My (build.gradle) file.

```
    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.imalok.saapchat"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
dexOptions {
    preDexLibraries = false
    javaMaxHeapSize "4g"
}
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support:design:27.1.0'
    implementation 'com.android.support:multidex:1.0.3'
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-auth:11.0.4'
    implementation 'com.android.support:support-v4:27.1.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.google.firebase:firebase-database:11.0.4'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
    implementation 'com.firebaseui:firebase-ui-database:2.3.0'
    implementation 'id.zelory:compressor:2.0.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.google.firebase:firebase-storage:11.0.4'

    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

apply plugin: 'com.google.gms.google-services'

```

build.gradle

```
    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

```

AndroidManifest.xml

```
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.imalok.saapchat">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application

    android:name="android.support.multidex.MultiDexApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".StartActivity" />
    <activity
        android:name=".RegisterActivity"
        android:parentActivityName=".StartActivity" />
    <activity
        android:name=".LoginActivity"
        android:parentActivityName=".StartActivity" />
    <activity android:name=".SettingsActivity" />
    <activity
        android:name=".StatusActivity"
        android:parentActivityName=".SettingsActivity" />
    <activity
        android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
        android:theme="@style/Base.Theme.AppCompat" />
    <activity
        android:name=".UsersActivity"
        android:parentActivityName=".MainActivity" />
    <activity android:name=".ProfileActivity"></activity>
</application>

```

Edit:1
Will you guys remove the duplicate level. Mine issue was different and so was the solution, as I posted.