Android Studio Google endpoints causing UNEXPECTED_TOP_LEVEL_EXCEPTION - android

I searched for ages to determine why my google endpoints module was causing a UNEXPECTED_.._EXCEPTION when I tried to run the App on a emulator.
Research indicated that a library is being called more than once. But I could find no clear error with regard to this:
My app build.gradle:
compile project(path: ':kk_endpoint', configuration: 'android-endpoints')
compile'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:cardview-v7:22.2.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.squareup.picasso:picasso:2.3.2'
And my Google endpoint module build.gradle:
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.19'
compile 'com.google.appengine:appengine-endpoints:1.9.19'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.19'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.googlecode.objectify:objectify:5.1.1'
compile 'com.ganyo:gcm-server:1.0.2'
Clearly nothing is being called twice on face level. What could be the cause of this problem?

After hours of research I found that the problem was coming from the guava lib, and all I needed to do was exclude that lib:
compile (project(path: ':kk_endpoint', configuration: 'android-endpoints')) {
exclude(module: 'guava-jdk5')
}
Please note brackets need to be exactly as above or won't work.
compile project(path: ':kk_endpoint', configuration: 'android-endpoints'){
exclude(module: 'guava-jdk5')}
Doesn't work.
I hope this helps someone save hours

Related

Getting MultiDex error while adding dependency for gcm and onesignal push notification

Problem: When I add the below dependencies in build.gradle, I am getting a multiDex error. I know this happens if I have unnecessary dependency but I am not able to sort it out. I am doing this for one single push notification in my app.
I added following dependencies to my build.gradle file:
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.onesignal:OneSignal:2.+#aar'
compile 'com.google.android.gms:play-services-analytics:8.1.0'
compile 'com.google.android.gms:play-services-location:8.1.0'
Before this my app was working fine. All of tthe dependecies in my gradle file are listed below (including the above dependencies)
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/android-support-v4.jar')
compile files('libs/Parse-1.3.0.jar')
compile files('libs/signpost-commonshttp4-1.2.1.2.jar')
compile files('libs/signpost-core-1.2.1.2.jar')
compile files('libs/signpost-jetty6-1.2.1.2.jar')
testCompile 'junit:junit:4.12'
compile files('libs/volley.jar')
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.onesignal:OneSignal:2.+#aar'
compile 'com.google.android.gms:play-services-analytics:8.1.0'
compile 'com.google.android.gms:play-services-location:8.1.0'
}
Any help on how to fix this?
If your intention is just to add Gcm. you dont need those many dependencies. Especially google play services full version.
compile 'com.google.android.gms:play-services:8.1.0'
Its always good to add smaller dependencies which fits your usecase such as
compile 'com.google.android.gms:play-services-gcm:8.1.0'
If you still are still exceeding 65k limit and need multidex, you must enable in your module gradle file.
multiDexEnabled true
in your module grandle file in defaultConfig.
Along with this, its better enable proguard to keep following attributes as well to make sure you dont bloat up the apk size
minifyEnabled true
shrinkResources true
Note that enabling proguard has its own problems which you will have deal with by carefully reviewing proguard-rules.pro
if you can't solve your application's dependencies.
multi dex application supporting can be solution for that.
http://android-developers.blogspot.kr/2014/12/google-play-services-and-dex-method.html
http://developer.android.com/tools/building/multidex.html

Failed to resolve firebase-ui:0.4.0

Trying to update my firebaseui. But Why doesn't this work in my gradle file?
compile 'com.firebaseui:firebase-ui:0.4.0'
UPDATE
Still same problem.
My other dependicies ar also updated:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.google.maps:google-maps-services:0.1.12'
compile 'com.google.maps.android:android-maps-utils:0.4.3'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.google.android.gms:play-services-ads:9.0.0'
compile 'com.google.android.gms:play-services-auth:9.0.0'
compile 'com.google.android.gms:play-services-gcm:9.0.0'
compile 'com.google.android.gms:play-services-location:9.0.0'
compile 'com.firebase:firebase-simple-login:1.4.2'
compile "com.google.firebase:firebase-database:9.0.0"
compile 'com.firebaseui:firebase-ui:0.4.0'
Update:
The bug has been fixed and the new build is already pushed. Here's the last official reply from the bug post.
Ok I just pushed a fix for this. There will be some propagation delay.
If you can try it in >= 1hr and let me know if it works that
would be great. Just build your project with the gradle flag
--refresh-dependencies to make sure it re-downloads deps and does not use the cached copy.
FirebaseUI is moved to jCenter in 0.4.0, thus it can't be found in mavenCentral. If it's still giving error, try to add Database and Auth dependencies separately, like this
compile 'com.firebaseui:firebase-ui-database:0.4.0'
compile 'com.firebaseui:firebase-ui-auth:0.4.0'
This has been marked as a bug already here. You can read the bug post to read more about this issue.
Here's the official reply on the bug
Ok I'm glad that solved your problem. For what it's worth,
com.firebaseui:firebase-ui:0.4.0 is just an empty library that
declares dependencies on those libraries for convenience.
I will leave this issue open until I can figure out what's going on
with my jCenter configuration, thanks for the report!
For some reason 0.4.0 is not avaible through bintray or mavencentral..
0.3.1 works though, so try that for now. I will look into it later.
'com.firebaseui:firebase-ui:0.3.1'
maoke sure you are using Jcenter.
if compile 'com.firebaseui:firebase-ui-database:0.4.0' and
compile 'com.firebaseui:firebase-ui-auth:0.4.0' still not work for you, try to go to Settings-> Build,execution, Deployment -> and disable offline Work

More than 8 hours and Android Studio is still not finished building my app (w/ Proguard-minify on)

I expected the build to take a significant amount of time but not as long as it is now. It's already past 8 hrs (9PM - 6AM) after I began but it's still not finished.
Details:
My PC is relatively powerful (built for gaming)
I extensively use external libraries, here they are:
Code:
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'org.adw.library:discrete-seekbar:1.0.0'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:cardview-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.android.support:support-v13:23.2.0'
compile 'com.android.support:gridlayout-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.flipboard:bottomsheet-core:1.5.0'
compile 'com.flipboard:bottomsheet-commons:1.5.0'
compile 'com.guerwan:transitionbackport:1.1'
compile 'com.nhaarman.listviewanimations:lib-manipulation:3.1.0#aar'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.ogaclejapan.smarttablayout:library:1.6.0#aar'
compile 'com.github.traex.rippleeffect:library:1.3'
compile 'asia.ivity.android:drag-sort-listview:1.0'
compile 'org.adw.library:discrete-seekbar:1.0.0'
compile 'com.liulishuo.filedownloader:library:0.1.9'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.github.castorflex.smoothprogressbar:library:1.0.1-SNAPSHOT#aar'
compile 'org.jetbrains:annotations-java5:15.0'
QUESTION:
Why is that the case? Is there anyway to minimize it? Or is it even normal not a bug? Thanks.
I've had this happen a few times in the past, especially when on a flaky internet connection. Here's what I would try:
Force close Android Studio and re-launch.
Enabled Gradle Offline Work (assuming you have cached versions of your dependencies) by going to File->Settings->Build,Execution,Deployment->Build Tools->Gradle and then check "Offline Work"
Generate your .apk
If you still are having problems building after that, I would try File->Invalidate Caches and Restart. Do you also have this issue when generating .apks with with ProGuard disabled?

Can't add both Google Play Services and Appcompat-v7 dependencies

I am trying to clean up and update the libraries on a project. As part of this I moved from using the classic library folder dependency to one through gradle, for Google Play Services. I started getting an dexDebug error when compiling debug (see Android Studio - UNEXPECTED TOP-LEVEL EXCEPTION: ). From what I understand this error shows up if you have a double dependency somehow.
Below is the dependencies part of my gradle file. If I comment out appcompat-v7 completely, everything works fine. Does play-services already depend on appcompatv7 and automatically bringing it in or what's going on?
dependencies {
compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.maps.android:android-maps-utils:0.3'
//compile files('libs/commons-codec-1.8-sources.jar')
compile files('libs/engine.io-client-0.2.3.jar')
compile files('libs/ffmpeg.jar')
compile files('libs/Java-WebSocket-1.3.0.jar')
compile files('libs/socket.io-client-0.1.3.jar')
//compile files('libs/javacpp.jar')
compile files('libs/javacv.jar')
compile files('libs/json-simple-1.1.1.jar')
compile files('libs/opencv.jar')
//compile files('libs/twitter4j-async-4.0.2.jar')
compile files('libs/twitter4j-core-4.0.2.jar')
//compile files('libs/twitter4j-media-support-4.0.2.jar')
//compile files('libs/twitter4j-stream-4.0.2.jar')
}
It turns out there was an exact duplicate to this question:
After update of AS to 1.0, getting "method ID not in [0, 0xffff]: 65536" error in project
I fixed it by adding (this alone will fix the original problem):
defaultConfig {
...
multiDexEnabled true
}
and by cutting down on the massive Google Play Services, and using only subsets of it (this alone will also fix the original problem):
dependencies {
//compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.google.android.gms:play-services-maps:7.0.0'
compile 'com.google.android.gms:play-services-location:7.0.0'
compile 'com.google.android.gms:play-services-gcm:7.0.0'
compile 'com.google.android.gms:play-services-plus:7.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.maps.android:android-maps-utils:0.3+'
compile files('libs/engine.io-client-0.2.3.jar')
compile files('libs/ffmpeg.jar')
compile files('libs/Java-WebSocket-1.3.0.jar')
compile files('libs/socket.io-client-0.1.3.jar')
compile files('libs/javacv.jar')
compile files('libs/json-simple-1.1.1.jar')
compile files('libs/opencv.jar')
compile files('libs/twitter4j-core-4.0.2.jar')
}

How Android Studio import the other project

I am a beginner in android development,when i develop my app with Android Studio,i can use "compile" in build.gradle file to import the other project from internet like below:
dependencies {
compile 'com.android.support:support-v4:21.0.2'
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.android.support:recyclerview-v7:21.0.2'
compile 'com.android.support:cardview-v7:21.0.2'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.phrase:phrase:1.0.3'
compile 'com.jakewharton.timber:timber:2.5.0'
compile 'com.andreabaccega:android-form-edittext:1.1.0#aar'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.crashlytics.android:crashlytics:1.1.13'
compile 'com.github.bumptech.glide:glide:3.4.0'
compile 'io.reactivex:rxjava:1.0.0'
compile 'io.reactivex:rxandroid:0.23.0'
compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.mcxiaoke.viewpagerindicator:library:2.4.1'
}
That's very useful, but where does those project come from? Can i import my project use "compile com.xxxxxxxx.xxxx:0.00.0" like above from internet? Maybe my question is too easy for you. But i really want to know why?
Imported libraries come from the repositories that you mention in your gradle file, under the repositories part.
If you want to use your project in another one like that, you need to publish it on a repository first.

Categories

Resources