java.lang.NoClassDefFoundError and ClassNotFoundException after add android Facebook SDK to the project
Asked Answered
G

3

7

I just added android Facebook SDK to my project to use Facebook ads to promote my app and the app crashes on starting, I got this exception

here's the log

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: www.pro_cs_is.com, PID: 20307
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/appevents/InternalAppEventsLogger;
        at com.facebook.marketing.internal.MarketingLogger.<init>(MarketingLogger.java:47)
        at com.facebook.marketing.internal.MarketingInitProvider.setupCodeless(MarketingInitProvider.java:68)
        at com.facebook.marketing.internal.MarketingInitProvider.onCreate(MarketingInitProvider.java:49)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1927)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1902)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6528)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6021)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5927)
        at android.app.ActivityThread.access$1200(ActivityThread.java:200)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6806)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.appevents.InternalAppEventsLogger" on path: DexPathList[[zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/base.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_dependencies_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_resources_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_slice_0_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_slice_1_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_slice_2_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_slice_3_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_slice_4_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_slice_5_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_slice_6_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_slice_7_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_slice_8_apk.apk", zip file "/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/lib/arm64, /system/lib64, /vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.facebook.marketing.internal.MarketingLogger.<init>(MarketingLogger.java:47) 
        at com.facebook.marketing.internal.MarketingInitProvider.setupCodeless(MarketingInitProvider.java:68) 
        at com.facebook.marketing.internal.MarketingInitProvider.onCreate(MarketingInitProvider.java:49) 
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1927) 
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1902) 
        at android.app.ActivityThread.installProvider(ActivityThread.java:6528) 
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6021) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5927) 
        at android.app.ActivityThread.access$1200(ActivityThread.java:200) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:201) 
        at android.app.ActivityThread.main(ActivityThread.java:6806) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
        Suppressed: java.io.IOException: No original dex files found for dex location /data/app/www.pro_cs_is.com-ewD1U225Ajh1l9uikBkdWg==/split_lib_resources_apk.apk
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:354)
        at dalvik.system.DexFile.<init>(DexFile.java:101)
        at dalvik.system.DexFile.<init>(DexFile.java:75)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
        at dalvik.system.DexPathList.<init>(DexPathList.java:164)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
E/AndroidRuntime:     at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:729)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:812)
        at android.app.LoadedApk.getResources(LoadedApk.java:1034)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2357)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5817)
                ... 8 more

build.gradle(Module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "test.com.app"
        minSdkVersion 15
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            useProguard true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        checkReleaseBuilds false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    packagingOptions {
        exclude 'META-INF/proguard/androidx-annotations.pro'
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.1.0-alpha05'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.5.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0-alpha03'
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha4', {
        exclude group: 'com.google.code.findbugs'
    })
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    implementation 'org.jsoup:jsoup:1.11.3'
    implementation 'com.google.apis:google-api-services-blogger:v3-rev57-1.23.0'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'org.apache.commons:commons-lang3:3.8.1'
    implementation 'com.github.ybq:Android-SpinKit:1.2.0'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.8@aar') {
        transitive = true
    }

    implementation 'androidx.multidex:multidex:2.0.1'
    configurations {
        all*.exclude group: 'com.google.guava', module: 'listenablefuture'
    }
    implementation 'com.android.support:customtabs:28.3.0'
    implementation 'org.jetbrains:annotations:15.0'
    implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
    implementation 'com.github.seventhmoon:ipapi-retrofit:1.44'
    implementation 'com.google.firebase:firebase-ads:17.2.0'
    implementation 'com.google.android.ads.consent:consent-library:1.0.7'
    implementation 'com.facebook.android:facebook-android-sdk:4.42.0'
    implementation 'com.facebook.android:facebook-core:4.42.0'
    implementation 'com.facebook.android:facebook-marketing:4.42.0'

}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'

meta data in AndroidManifest file

 <meta-data android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id"/>

I tried to add the old/previous version of facebook SDK but this also didn't work

implementation 'com.facebook.android:facebook-android-sdk:[4,5

proguard Facebook rules

# Facebook
-keep class com.facebook.** {*;}
-dontwarn com.facebook.**
Gingergingerbread answered 11/4, 2019 at 15:38 Comment(2)
I would check proguard settings first of all.Disaster
@oss proguard rules for facebook is # Facebook -keep class com.facebook.** {*;} -dontwarn com.facebook.** Gingergingerbread
F
9

Update: Changing SDK version to 4.39.0 is the fix.

Does your app have internet permission?

Also try 4.39.0 as FB SDK version

Don't forget to invalidateCache and restart.

Fission answered 16/4, 2019 at 18:43 Comment(3)
for sure it's have Internet Permission, because I use Retrofit APIGingergingerbread
Thanks, after downgrade to version 4.39.0 the app runs without problemGingergingerbread
I downgraded to 4.41.0 from 4.42.0 to fix it.Kincardine
D
0

Try adding in your build.gradle file,

repositories {
    mavenCentral()
}

You can also go to File -> Invalidate caches and restart -> Invalidate and Restart

Dudeen answered 15/4, 2019 at 19:48 Comment(2)
already added in all projects allprojects { repositories { google() jcenter() mavenCentral() maven { url "https://jitpack.io" } } } Gingergingerbread
Did you try invalidate and restart. Sometimes there could be a problem with caches.Dudeen
U
-1

Try to disable Instant Run. Go to File -> Settings -> Build,Execution, Deployment -> Instant Run -> Uncheck the checkbox for instant run.

Unrelenting answered 11/4, 2019 at 15:45 Comment(1)
clean and rebuild the project from Build menuFrizzell

© 2022 - 2024 — McMap. All rights reserved.