UNEXPECTED TOP-LEVEL EXCEPTION while adding google play services - android

I am developing an android app where I am integrating Google Plus Login. For this, I've added google play services library to my project. When I run my app, it gives me following error :
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
This is my build.gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.genes_x.googleplus"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
//compile 'com.google.android.gms:play-services-plus:7.0.0'
//compile 'com.google.android.gms:play-services-identity:7.0.0'
compile files('E:/google plus/GooglePlus/libs/google-play-services.jar')
}
I've been gone through many questions on stackoverflow but didn't get solution. Anything wrong in my build.gradle file..??

The error is pretty obvious. You are compiling google play services twice. Should be:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
//compile 'com.google.android.gms:play-services-plus:7.0.0'
//compile 'com.google.android.gms:play-services-identity:7.0.0'
//compile files('E:/google plus/GooglePlus/libs/google-play-services.jar')
}

Related

issue in getting dex file while adding google play service and osm jar android

i m implement osm app with google play store so i add below jars.
When i run my project i getting below error
Error Code:2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/api/client/googleapis/notifications/json/gson/GsonNotificationCallback;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.pkg.name"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile project(':mapsForgeForOsmdroid')
compile project(':oSMBonusPack')
compile 'com.android.support:gridlayout-v7:22.2.0'
compile files('libs/picasso-2.5.2.jar')
compile 'com.google.api-client:google-api-client:1.20.0'
compile 'com.google.api-client:google-api-client-android:1.20.0'
compile 'com.google.api-client:google-api-client-gson:1.20.0'
compile 'com.google.apis:google-api-services-calendar:v3-rev125-1.20.0'
compile 'com.google.android.gms:play-services:7.5.0'
/* compile 'com.google.android.gms:play-services:7.5.0'
compile files('libs/google-api-client-appengine-1.20.0.jar')
compile files('libs/google-api-client-1.20.0 (2).jar')
compile files('libs/google-api-client-gson-1.19.0.jar')
compile files('libs/google-api-services-calendar-v3-rev133-1.20.0.jar')
compile files('libs/google-api-client-android-1.20.0 (1).jar')*/
//compile files('libs/google-api-client-util-1.2.1-alpha.jar')
}
I think OsmBonusPack brings in a copy of Gson. Try adding an exclusion for it.
Edit:
You can find the offending library using
gradle dependencies
once it's located, you can exclude it using (a few examples)
compile('group:artifact:version') {
exclude module: 'cglib' //by artifact name
exclude group: 'org.jmock' //by group
exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group
}

unexpected top level exception in android studio

I am trying to build my app but when i try to make it a signed apk it says this:
Error:Execution failed for task ':app:dexRelease'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\rik\AppData\Local\Android\sdk\build-tools\21.1.0\dx.bat --dex --output C:\Users\rik\Desktop\CCApp\app\build\intermediates\dex\release --input-list=C:\Users\rik\Desktop\CCApp\app\build\intermediates\tmp\dex\release\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lbolts/AggregateException;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
its really anoying me and i need to build the app very soon,
hope someone can help me
EDIT added build.gradle
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "it.experium.ccapp"
minSdkVersion 9
targetSdkVersion 21
versionCode 3
versionName "3.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: 'libs', include: 'ParseCrashReporting-*.jar')
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
}
EDIT file tree of the libs folder
parse-1.8.2-javadoc (Folder)
ParseCrashReporting-1.8.2-javadoc (Folder)
bolts-android-1.1.4 (Jar)
bolts-android-1.1.4 (Properties File)
bolts-android-1.1.4-javadoc (Jar)
Parse-1.8.2 (Jar)
Parse-1.8.2 (Properties file)
Rooster (In english Schedule, i have this because i request json's with this file. Jar)
third_party_licenses (TXT)
It seems like you are using here multiple jar files for same reference it may take some difference version of it..
So, it's better to remove below lines
compile fileTree(dir: 'libs', include: 'ParseCrashReporting-*.jar')
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
Because 1st and 3rd line of this code included in single line so, no need to put those extra lines..
compile fileTree(dir: 'libs', include: ['*.jar'])
You are here putting external jar bolts-android-1.1.4 (Jar) as a reference from lib folder so, no need to add this gradle dependency..
compile 'com.parse.bolts:bolts-android:1.+'
So, after removing those 3 line sync project you will get your project running without any issue..
Let us know if anything needed...

Android studio does not let me compile project

I have googled to find a solution, but I have tried all the ways and any of them works. First my project works with any problem, later I added some changes and this happened. When I delete all the changes, the problem has not dissapeared. When I try to complie the project, gradle console shows:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/user/Android/Sdk/build-tools/22.0.0/dx --dex --no-optimize --output /home/projectpath/app/build/intermediates/dex/debug --input-list=/home/projectpath/app/build/intermediates/tmp/dex/debug/inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lbolts/AggregateException;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
This is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
applicationId "application.com.name"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:palette-v7:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:cardview-v7:22.0.+'
compile 'com.jakewharton:butterknife:5.1.2'
compile 'com.jakewharton.timber:timber:2.5.0'
compile 'fr.tvbarthel.lib.blurdialogfragment:lib:1.1.0#aar'
compile 'com.github.chenupt.android:multiplemodel:1.1.0#aar'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.google.guava:guava:18.0'
compile 'com.jpardogo.materialtabstrip:library:1.0.8'
compile 'com.getbase:floatingactionbutton:1.7.0'
compile 'com.squareup.picasso:picasso:2.5.0'
compile 'com.facebook.android:facebook-android-sdk:3.21.1'
}
dependencies {
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile fileTree(dir: 'libs', include: 'ParseCrashReporting-*.jar')
}
This kind of issue UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException:
happens when you are using the same library with a different version.
The problem is here:
You are using
compile 'com.parse.bolts:bolts-android:1.+'
Currently the version is 1.2
The facebook (3.21.1) library is using the 1.1.2 version
Also you are using
compile 'com.android.support:appcompat-v7:+'
It means the release 22.
The facebook library uses the 20-21.

UNEXPECTED TOP LEVEL EXCEPTION in android studio

I was trying to code a simple android app and i get this error message.Please help
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
D:\Users\user\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Users\user\Desktop\SocialNetworking\app\build\intermediates\dex\debug --input-list=C:\Users\user\Desktop\SocialNetworking\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lbolts/AggregateException;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
My gradle build is as follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "jason.orchid.com.socialnetworking"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories { mavenCentral() }
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.parse.bolts:bolts-android:1.1.4'
compile 'com.facebook.android:facebook-android-sdk:3.23.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
}
It is because you have included 'com.parse.bolts:bolts-android:x.x' twice in your dependencies. Remove any one of them and the problem will be resolved.

Android Studio error, multiple dex files

I am unable to build my project, it is returning me one error. There are no errors in the files themselves, only upon a build.
This is the following error:
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Jay\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Users\Jay\Desktop\UploadToServer\app\build\intermediates\dex\debug --input-list=C:\Users\Jay\Desktop\UploadToServer\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
I have read on a few other post that it could be multiples of the same jar files in the libs folder but currently my folder is empty, I am not to sure what the issue is, I would appreciate if someone could help.
Here is my module build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.jay.uploadtoserver"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.android:support-v4:r6'
compile 'org.apache.httpcomponents:httpmime:4.2.3'
}
Some of your jar files does not compile. You should go into your build.gradle file in your project, and look in your dependencies, if your just import some jar files, you could try to remove them, and add one at a time, to see which one of them makes the error.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.android:support-v4:18.0.+'
}
Remove compile 'com.google.android:support-v4:r6'. AppCompat already has this library

Categories

Resources