Application is working fine on all OS, but when i add facebook SDK, it gives me following error message on lollipop devices.
compile 'com.facebook.android:facebook-android-sdk:4.20.0'
Caused by: java.lang.ClassNotFoundException: Didn't find class "retrofit2.Retrofit$Builder" on path: DexPathList[[zip file "/data/app/com.myapp.app-3/base.apk", zip file
java.lang.NoClassDefFoundError: Failed resolution of: Lretrofit2/Retrofit$Builder; Caused by: java.lang.ClassNotFoundException: Didn't find class "retrofit2.Retrofit$Builder" on path: DexPathList[[zip file "/data/app/com.myapp.app-3/base.apk", zip file "/data/app/ com.myapp.app-3/split_lib_dependencies_apk.apk",
This is my gradle file.
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId 'com.myapp.app'
minSdkVersion 21
targetSdkVersion 23
versionCode 122
versionName "1.2.5"
multiDexEnabled true
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86"
}
configurations.all {
resolutionStrategy {
force 'com.squareup.okhttp:okhttp:2.4.0'
force 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
force 'com.squareup.okio:okio:1.11.0'
force 'com.squareup.okhttp3:okhttp:3.6.0'
force 'com.squareup.retrofit2:retrofit:2.2.0'
force 'com.android.support:recyclerview-v7:25.0.0'
force 'com.android.support:support-v4:25.0.0'
force 'com.android.support:cardview-v7:25.0.0'
force 'com.android.support:appcompat-v7:25.0.0'
force 'com.android.support:design:25.0.0'
force 'com.android.support:support-annotations:25.0.0'
force 'com.google.android.gms:play-services-ads:9.0.1'
force 'com.google.android.gms:play-services-location:9.0.1'
force 'com.google.android.gms:play-services-auth-base:9.0.1'
force 'com.google.android.gms:play-services-base:9.0.1'
}
configurations.all {
resolutionStrategy {
failOnVersionConflict()
}
}
Kindly guide me what can be the reason of this crash, and why its only crashing on lollipop devices and working fine on Marshmallow and Nougat.
EDIT
If I don't use facebook sdk, everything seems fine, no crashes. Maybe Facebook sdk cause this problem but I don't know why
Apps on Android can crash because of low storage space, too many apps running simultaneously, a weak internet connection, or not having the proper app updates installed.
The easiest way to fix an app that keeps crashing on your Android smartphone is to simply force stop it and open it again. To do this, go to Settings -> Apps and select the app that keeps crashing. Tap on the app's name and then tap on 'Force stop'. Now try opening the app again and see if it works well.
This usually occurs when your Wi-Fi or cellular data is slow or unstable, causing apps to malfunction. Another reason for Android apps crashing can be a lack of storage space in your device. This can occur when you overload your device's internal memory with heavy apps.
Network Problems The Mobile Data saver of your Android phone may also lead to the problem of apps keep crashing and automatically closing.
You are using too many libraries so your methods have crossed over 64k so you have to enable Multidex for you project
inside your build.gradle
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
and in AndroidManifest.xml
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
see This for more info
You are getting ClassNotFoundException
The ClassNotFoundException is thrown when the Java Virtual Machine (JVM) tries to load a particular class and the specified class cannot be found in the classpath.
At first you should set Multidex .
Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.
You should use Latest Version
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId 'com.myapp.app'
minSdkVersion 21
targetSdkVersion 25 // Good approach using same version of compileSdkVersion
versionCode 122
versionName "1.2.5"
multiDexEnabled true
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86"
}
configurations.all {
resolutionStrategy {
force 'com.squareup.okhttp:okhttp:3.7.0'
force 'com.squareup.okhttp:okhttp-urlconnection:2.7.5'
force 'com.squareup.okio:okio:1.12.0'
force 'com.squareup.okhttp3:okhttp:3.7.0'
force 'com.squareup.retrofit2:retrofit:2.2.0'
force 'com.android.support:recyclerview-v7:25.2.0'
force 'com.android.support:support-v4:25.2.0'
force 'com.android.support:cardview-v7:25.2.0'
force 'com.android.support:appcompat-v7:25.2.0'
force 'com.android.support:design:25.2.0'
force 'com.android.support:support-annotations:25.2.0'
force 'com.google.android.gms:play-services-ads:10.2.1'
force 'com.google.android.gms:play-services-location:10.2.1'
force 'com.google.android.gms:play-services-auth-base:10.2.1'
force 'com.google.android.gms:play-services-base:10.2.1'
}
configurations.all {
resolutionStrategy {
failOnVersionConflict()
}
}
After that Clean-Rebuild-Run .
FYI
You can use below version if 4.20.0 crashing .
compile 'com.facebook.android:facebook-android-sdk:4.16.0'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With