103

Split lib_main was defined multiple times

In "com.android.tools.build:gradle:2.0.0-alpha3" build success, But the errors that occur in the "com.android.tools.build:gradle:2.0.0-alpha5".

console error


finally instant run work!! com.android.tools.build:gradle:2.0.0-alpha8 and gradle.properties "org.gradle.jvmargs = -Xmx8g" was resolved to change.

shinhyo
  • 1,128
  • 2
  • 7
  • 10
  • Having exactly the same problem. Are you using product flavors, and applicationIdSuffix by chance? – Michael De Soto Jan 15 '16 at 02:51
  • Unfortunately, do not using "product flavors" and "applicationIdSuffix". but using "MultiDex". – shinhyo Jan 15 '16 at 03:55
  • 6
    same error here, disabling instant run helps. Happens only for devices that are run Android 6. Android Studio 2.0 5 Using applicationIdSuffix, MultiDex, Not using product flavour – Happy Dev Jan 15 '16 at 05:06
  • @Happydev Any way to avoid this error? – TeeTracker Jan 15 '16 at 10:13
  • 1
    @Happydev Solved by disabling instantrun! – shinhyo Jan 15 '16 at 12:35
  • I have build variants and multidex, disabling InstaRun did the trick. – Pedro Varela Jan 15 '16 at 16:57
  • @Happydev - you should get the points for the right answer. Post it and so we can upvote it :-) – bkurzius Jan 15 '16 at 19:05
  • 1
    @bkurzius it does not seams like an solution to me, whole point of update was instant run. I hoped someone will find something like remove some library or plugin... because instant run works awesome on Marshmallow on another project. – Happy Dev Jan 16 '16 at 03:03
  • @Happydev - for what its worth I still think you have the right answer to this particular question - its not the ideal solution but it is the only way I have been able to resolve this error so far... – bkurzius Jan 19 '16 at 16:41

6 Answers6

162

Just delete build folder of appmodule and Rebuild the project!

This will fix the issue!.

AskQ
  • 3,629
  • 4
  • 27
  • 54
103

For those who wonder what InstantRun is (first setting in the picture): enter image description here

And yes disabling that setting fixes the issue.

Edit 01/19/16

'com.android.tools.build:gradle:2.0.0-alpha6' was released three days ago. Using that new version, the "Split lib_main was defined multiple times" error is gone and installation of the app succeeds but now I get a runtime error:

java.lang.RuntimeException: Unable to instantiate application
com.android.tools.fd.runtime.BootstrapApplication:
java.lang.ClassNotFoundException: Didn't find class
"com.android.tools.fd.runtime.BootstrapApplication" on path:
DexPathList[[zip file "/data/app/com.onegravity.k10.pro2-2/base.apk",
zip file "/data/app/com.onegravity.k10.pro2-/split_lib_main.apk"]

Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.android.tools.fd.runtime.BootstrapApplication" on path:
DexPathList[[zip file "/data/app/com.onegravity.k10.pro2-2/base.apk",
zip file "/data/app/com.onegravity.k10.pro2-2/split_lib_main.apk"]

Suppressed: java.io.IOException: No original dex files found for dex location
/data/app/com.onegravity.k10.pro2-2/base.apk

Suppressed: java.lang.ClassNotFoundException:
com.android.tools.fd.runtime.BootstrapApplication

Turning off instant run eliminates that error. Let's wait for com.android.tools.build:gradle:2.0.0-alpha7...

Edit 01/25/16

'com.android.tools.build:gradle:2.0.0-alpha7' was released two days ago.

Getting the same exception as with 2.0.0-alpha6

Emanuel Moecklin
  • 25,943
  • 11
  • 66
  • 78
  • 2
    well I guess that kind of defeated the whole point of my updating this morning :-/ – bkurzius Jan 15 '16 at 19:03
  • 3
    I seem to spend more and more time fighting the build system. It's as if Android development becomes more and more build/deployment oriented and less coding... Pity really because I like the flexibility of the Gradle build system. – Emanuel Moecklin Jan 15 '16 at 19:07
  • 1
    well if they can nail instant run it would be worth the pain but so far my experience with it has not been good :-( – bkurzius Jan 15 '16 at 19:08
  • Even in other apps that run with instant run I had to turn it off. There are too many cases the instant run just doesn't work. Still alpha I guess... – Emanuel Moecklin Jan 21 '16 at 17:16
  • Thanks .. I was getting this on stable ver 2.3.1 – shadygoneinsane May 20 '17 at 07:28
  • Even wiping the data on the simulator didn't fix this problem, but disabling InstantRun did. A shame, too, I was beginning to like InstantRun before it went all psycho on me. – aroth Feb 14 '18 at 06:44
  • This worked, I had an issue when I moved where my app was located on my PC and this fix worked immediately. – trevren11 Feb 15 '18 at 00:12
49

I ran into this issue after refactoring and changing app name in gradle. Following AskQ's lead, I rebuilt the project (following a slightly different path):

Build-> Clean Project

followed by

Build-> Rebuild Project

Solved the issue

tony gil
  • 9,063
  • 6
  • 72
  • 89
11

Recovery:

Deleting the (projectFolder)/app/build folder and re-building worked for me. (as answered by @AskQ)

I wonder if Build > Clean Project would have worked as well; from the Android Studio GUI menus.

Avoidance:

In my case the problem seems to have occurred because I had copy pasted a project, so 2 projects had the same name.
There are like other causes too, learning what they are can help users avoid this concern.

Brian Davis
  • 295
  • 4
  • 8
3

It might happen because of your package name is in uppercase, so you must change it back to lowercase.

2

Android studio 2.3.3 It worked for me after disabling Instant run in settings...

Go to Settings-> Build,Execution and Development-> Instant Run -> Uncheck Enable Instant Run to hotswap then clean project and Rebuild your project again!!

Suhas
  • 119
  • 1
  • 10