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
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'
In my Case this solved my problem
In Application Class you need to
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
The main issue I can see is that you have exceeded the methods limit by adding a lot of libraries in your project. Android app has a certain limit of methods. To make your code efficient I'll suggest you to remove all unnecessary libraries like why are you using "Retrofit" and "OkHttp" together? You can get all the work done by any one of them.
But still if you want to use all these libraries, then you have to allow your app to "Multidex" usage.
Here is the way to allow "Multidex" usage.
https://developer.android.com/studio/build/multidex.
But I won't suggest to use this. Because this will put load on your app and will require more space in Phone's ram
Choice is yours!
Related
I upgraded the android studio 2.x.x to android studio 3.0.1 after importing the project gradle building is successful. But when installing app showing the error message
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
my app grdle is given below
Why it's showing this error and how to fix it? unable to install the app on the emulator.
Already tried the clean and rebuild option in android studio but it doesn't fix the issue
Try with the following
If your minSdkVersion is set to 21 or higher
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
...
}
if your minSdkVersion is set to 20 or lower,
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
If this does not resolve, try through these posts post 1 , android_dev or post 2
To remove this Dex issue just implement one dependency.
This issue occur when we are using multiple different service from the same server. Suppose we are using ads and Firestore in a project and both have a repository maven. so we need to call different data with on repository we need dex dependency to implement.
The new update Dependency:-
implementation 'com.android.support:multidex:1.0.3'
or use testCompile inside compile such as :
implementation 'com.google.android.gms:play-services-ads:15.0.1'
testCompile 'com.google.firebase:firebase-firestore:17.0.1'
and also make multiDexEnabled true;
100 % it will work !
I created my first Android app 2 years ago in Eclipse and now I have some time to improve it. I do not have Eclipse installed anymore, so I decided to import the project into Android Studio.
But now I am running into several problems:
Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version 14 declared in library [com.google.android.gms:play-services:10.2.0]
So in the build.gradle I changed it to 14. Then I got the next error
Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Spinner.Underlined'.
So therefor I changed the compileSdkVersion and the targetSdkVersion to 25 (correct me if it's wrong). And I changed
compile 'com.android.support:support-v4:20.0.0'
into
compile 'com.android.support:support-v4:25.2.0'
Now I could build my project. But when I tried to run my app, after more then 5 minutes(!) I got the next error :
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
So then I added
multiDexEnabled true
and
compile 'com.android.support:multidex:1.0.1'
and
android:name="android.support.multidex.MultiDexApplication"
to the manifest file.
My build.gradle now looks like this
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "<<myApplicationId>>"
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:25.2.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/AppFireworks.jar')
compile files('libs/fcvtgzwtzuliivdcu.jar')
compile 'com.android.support:multidex:1.0.1'
}
But now I got the following pop-up and errors
Instant Run does not support deploying build variants with multidex enabled, to a target with API level 20 or below. To use Instant Run with a multidex enabled build variant, deploy to a target with API level 21 or higher.
Error:UNEXPECTED TOP-LEVEL ERROR:
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
What have I done wrong? Do I have to change the minSdkVersion to 21? I want to be able to run my app on Android 4.x. I could when I was developing in Eclipse. So far switching from Eclipse to Andriod Studio is going from bad to worse. :-(
you are compiling using compile 'com.google.android.gms:play-services:+'
play service is itself is a large library. You should not use + which implies all available version to compile
Rather use a specific version of play services or break down the library and use specific services like location,maps etc.
Also u can use dexOptions to increase ur memory usage during compilation
try changing your gradle file to:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "<<myApplicationId>>"
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:25.2.0'
compile 'com.google.android.gms:play-services-maps:9.0.1'
compile 'com.google.android.gms:play-services-plus:9.0.1'
compile 'com.google.android.gms:play-services-location:9.0.1'
compile 'com.google.android.gms:play-services-games:9.0.1'
compile 'com.google.android.gms:play-services-gcm:9.0.1'
compile files('libs/AppFireworks.jar')
compile files('libs/fcvtgzwtzuliivdcu.jar')
compile 'com.android.support:multidex:1.0.1'
}
I have this error whenever i try to create an APK for the app.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/text/TextUtilsCompat.class
The app run in the android emulator , but when i try to build an apk i get this error.
i dont know what to change
here is the gradle code
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.companyname.gamename"
minSdkVersion 11
targetSdkVersion 23
multiDexEnabled true
ndk {
moduleName "player_shared"
}
}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/support-v4-19.0.1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
}
I tryed to clean rebuild an run the prject but i still have the same problem,
I've read that it's depencdencies problem. but can't figure wich one to remove.
First, never use a plus dependency.
services:+'
Also don't compile all the Play Services, only setup ones you really need.
https://developers.google.com/android/guides/setup#split
Secondly, stop using jar files and go find the correct libraries using Maven Central (or the supporting documentation for those libraries) and use the other way to compile through Gradle.
Your jar files have overlapping classes and therefore you have errors
While you're at it...
Dagger 1 is being deprecated for Dagger 2
NineoldAndroids has stopped being maintained, so best to find some other way to use the code you need it for
Your support libraries need to match the compileSdk version
I am developing Android library. When My Client(Application developer) applied my Jar file, it is shown error message.
Build is normal working, But When I run(playButton) App in Android Studio, it is occurred.
The error message shown like below :
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't read [/Users/VSSCP_KYOSEON/Documents/Work/Android/A/B/app/build/intermediates/transforms/jarMerging/debug/jars/1/1f/combined.jar] (Can't process class [com/a/b/VSFunctionActivity.class] (Unknown verification type [88] in stack map frame))
This is my Application Gradle Code :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '24.0.1'
defaultConfig {
applicationId "com.a.b"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
dexOptions {
javaMaxHeapSize "4g" //specify the heap size for the dex process
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile project(':ChartLib')
compile 'com.google.android.gms:play-services-fitness:8.4.0'
compile 'com.android.support:multidex:1.0.1'
compile files('libs/vs_sat_sdk.jar')
}
My Jar file is vs_sat_sdk.jar. It is applied to proguard.
I already applied Android Multidex guide. https://developer.android.com/tools/building/multidex.html But I failed to execute.
I have normal operation situation.
1. I apply proguard in My jar file. and When minSdkVersion is over 21, it is normal operation. But When minSdkVersion is under 21, it is shown failed.
2. If My jar file doesn't applied proguard, regardless of minSdkVersion, it is normal operation.
please let me know about your solution.
Regards.
Maybe the jar file has been processed by a tool that does not correctly update the StackMapFrame attribute.
Actually, StackMapFrame attributes are not needed for Android development, so you could instruct ProGuard to not create it and it might solve your issue. Add the following to your configuration when applying ProGuard to your library:
-dontpreverify
I have this error :
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzrf.class
I want to add google play services to my project so i put this line in build.gradle file :
compile 'com.google.android.gms:play-services:7.8.0'
So I had to enable multidex and I followed android doc, adding this in build.gradle :
compile 'com.android.support:multidex:1.0.1'
and
multiDexEnabled true
I add this in android manifest :
<application
...
android:name="android.support.multidex.MultiDexApplication">
But I have the error I wrote above. I've found a lot of questions relative to this problem (app:packageAllDebugClassesForMultiDex) but not with that (duplicate entry: com/google/android/gms/internal/zzrf.class).
I tried some solutions like remove some google libraries but I don't know what refers to internal/zzrf.class.
Here is my gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "fr.djey.testgoogleplus"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
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.1'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.android.support:multidex:1.0.1'
}
I faced same problem. In my case I used home made Android library used by My Android app. Which means 1 project with 2 separate modules, while the app module depends on the library module.
Both have support of multidex. The root cause was inconsistency between google play services version. In the app module I used 7.8.+ and in the library I used 8.1.+. So I just updated both to same 8.1.+ and that fixed for me. So my answer is to check all the libs you depend on and may 1 of them using google play services version below yours.
Delete all files under build folder of that project. In my case, it is the jar file of the whole google play conflict with the jar file of only ads service.
As I said in the comment : I created another project and just did the same things : putting google play services and multidex, the problem didn't appear anymore.