As I see new android Studio user face this problem when they are debugging or run the project. gradle project sync failed

However, this is not a big problem.many developers waste lot’s of time to solve this issue.
Actually we need to understand why show this error? when we run the project.

If we implement the multiple libraries in the same project. then project conflicted with both libraries.

Don’t worry we have a solution for this. In this article, I will write down 4 solution for this problem step by step.

If you face the problem please read the solution step one by one and apply the process to your error project. I hope you can solve the problem Error:Execution failed for task ':app:dexDebug'.  

gradle project sync failed

UNEXPECTED TOP-LEVEL EXCEPTION Multiple dex files define 1

the problem are duplicate dx.bat file that’s why new file are not generated by IDE

Error:Execution failed for task ':app:dexDebug'.
> Failed to run command:
 C:Androidandroid-studiosdkbuild-tools19.0.3dx.bat --dex --output C:NewprojectTraditionalMehendiappbuilddexdebug C:NewprojectTraditionalMehendiappbuildclassesdebug C:NewprojectTraditionalMehendiappbuilddependency-cachedebug C:NewprojectTraditionalMehendiappbuildpre-dexeddebugclasses-48d144ddea6f49f726182658d2cd8e370ccc3aaa.jar C:NewprojectTraditionalMehendiappbuildpre-dexeddebugclasses-9f4d5885611b2cd25e7d8eab67c143627ce2b90e.jar C:NewprojectTraditionalMehendiappbuildpre-dexeddebugcordova-2.9.0-ed7f0ff9375df6df791502102448d1e17b9157d8.jar C:NewprojectTraditionalMehendiappbuildpre-dexeddebuggoogle-play-services-951d8a946461792fa0ed722eaf024834954f8800.jar C:NewprojectTraditionalMehendiappbuildpre-dexeddebuglibGoogleAnalyticsServices-b42dc6d8aa0346a80f1328d54575ffcd87dd725e.jar C:NewprojectTraditionalMehendiappbuildpre-dexeddebugsupport-v4-19.1.0-949793351ba251d9ea726b83e38d287075a5b846.jar
Error Code:
 UNEXPECTED TOP-LEVEL EXCEPTION: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;

Solution for Fix this problem

Step 1: Your google play services library is being exported from other dependencies of your project and at the compile time the dex compiler gets confused.
If you’re using Gradle then including this in your project’s build.gradle should exclude the support library from being exported into your main project.

apply plugin: 'android'
apply plugin: 'crashlytics'

/** Must exclude exported support jars from dependencies, or get dex duplicate class error.
* we’re
configurations {
all*.exclude group: ‘’, module: ‘support-v4’
all*.exclude group: ‘’, module: ‘play-services’

If you’re using the android studio build system. Then you should go to File -> project structure and disable -> modules.

Go through each module the and click on the dependency tab, unchecked the export column for for the support library and google play services library.

Step 2:Make sure you have downloaded Support Repository to use support library dependency in build.gradle.

UNEXPECTED TOP-LEVEL EXCEPTION Multiple dex files define 2

If these all are there already installed sync your project with gradle once using the button available.

UNEXPECTED TOP-LEVEL EXCEPTION Multiple dex files define 3

Step 3:Because you may include two same libs in your project. check your build.gradle file.

dependencies {
    compile ''
    compile files('libs/android-support-v4.jar') 

if your file includes compile '' and compile files('libs/android-support-v4.jar'), it will have this problems. delete this sentence: compile files('libs/android-support-v4.jar')
To Change Make it

dependencies {
    compile '' 

Steep 4: If you are try the way but not solve the problem than this this another way . hope you will solve the problem .

Simple go to  Project Folder Remove  .gradle  .idea  folder

UNEXPECTED TOP-LEVEL EXCEPTION Multiple dex files define 4

And Go to yourprojectappsbuild Remove All Directory in this Build Folder Now go to Android Studio And sync your project with gradle once using the button.

And Sunc the project you will now debug the apps hope you never face this problem in this project again

UNEXPECTED TOP-LEVEL EXCEPTION Multiple dex files define 5

If you again face this problem then post a comment here I will hardly try to solve your problem.
But to better understand your project error. can you please show your build.gradle file information when you ask solution here.

without seeing your build.gradle file information provided a solution for you is quite hard for my side.

One last think here in this article comment section many developers solve this problem with this article help. So don’t forget to see how they solve the problem.

Affiliate Disclaimer : As an Amazon Associate I earn from qualifying purchases.