15

I have searched everywhere about this and still have no solution.

The gradle has minSdkVersion 21 and targetSdkVersion 29

I got error only in API 29, then the app doesn't load and show up blank screen. When i see logcat it gives an error like this :

E/LoadedApk: Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/com.packagename.appname-BxS7Zs-h0IWwJAVhbjx7aQ==/lib/x86, /data/app/com.packagename.appname-BxS7Zs-h0IWwJAVhbjx7aQ==/base.apk!/lib/x86, /system/lib, /system/product/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.LoadedApk.createAppFactory(LoadedApk.java:256)
    at android.app.LoadedApk.updateApplicationInfo(LoadedApk.java:370)
    at android.app.ActivityThread.handleDispatchPackageBroadcast(ActivityThread.java:5951)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1941)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at com.android.server.SystemServer.run(SystemServer.java:541)
    at com.android.server.SystemServer.main(SystemServer.java:349)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:908)

I think it seems like from multidex, then i have tried adding following code to gradle app

multiDexKeepFile file('multidex-config.txt')

multiDexKeepProguard file('multidex-config.pro')

my multidex-config.txt

com/packagename/appname/androidx.class

my multidex-config.pro

-keep class androidx.core.app.CoreComponentFactory { *; }

my App class extending MultiDexApplication

public class App extends MultiDexApplication {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

my Manifest

<application
    android:name=".App"
    android:allowBackup="true"
    android:icon="@mipmap/ic_logo"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_logo"
    android:supportsRtl="true"
    android:theme="@style/main"
    android:usesCleartextTraffic="true"
    tools:ignore="GoogleAppIndexingWarning">

my gradle.properties

android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

my gradle/app

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

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.packagename.appname"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 7
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        debug {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            multiDexKeepFile file('multidex-config.txt')
            multiDexKeepProguard file('multidex-config.pro')
            minifyEnabled true
        }
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            multiDexKeepFile file('multidex-config.txt')
            multiDexKeepProguard file('multidex-config.pro')
            minifyEnabled true
        }
    }
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.libraries.places:places:2.2.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'

    implementation 'com.android.support:multidex:2.0.1'

    implementation 'com.github.vipulasri:timelineview:1.1.0'
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    implementation 'com.yanzhenjie.zbar:camera:1.0.0'
    implementation 'androidx.percentlayout:percentlayout:1.0.0'

    implementation 'com.amitshekhar.android:android-networking:1.0.2'

    implementation 'com.google.firebase:firebase-core:17.2.2'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

    implementation 'com.github.kenglxn.QRGen:android:2.5.0'

    implementation 'com.facebook.android:facebook-android-sdk:4.36.0'

    implementation 'com.jsibbold:zoomage:1.2.0'

    implementation 'androidx.arch.core:core-common:2.1.0'
    implementation 'androidx.arch.core:core-runtime:2.1.0'
}

I really need a solution for this. Help me please, thank you so much!

Community
  • 1
  • 1
Erwin Kurniawan A
  • 958
  • 2
  • 9
  • 17
  • See a solution here: https://stackoverflow.com/questions/57438312/java-lang-classnotfoundexception-didnt-find-class-com-my-app-name-androidx or https://stackoverflow.com/questions/57700486/didnt-find-class-androidx-core-app-corecomponentfactory. – CoolMind Jun 17 '20 at 10:42

9 Answers9

10

The error is pointing to the use of androidx CoreComponentFactory class(using AndroidX) but you are using old package com.android.support:multidex

so use androidx dependency as:

implementation 'androidx.multidex:multidex:2.0.1'

instead of

implementation 'com.android.support:multidex:2.0.1'

and make sure to use androidx imports in the application class as

import android.content.Context;
import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;

public class YourApp extends MultiDexApplication {

    @Override
    protected void attachBaseContext(Context base) {
        MultiDex.install(this);
        super.attachBaseContext(base);
    }
}

Additionally: During the app Load-up, android Q uses the CoreComponentFactory instance internally whether you are using it in manifest or not, which is causing the issue.

Also, add multiDexEnabled true as defaultConfig{multiDexEnabled true }


Update: After the RCA, the componentfactory import issue was resolved with the androidx lib imports though there was another issue with the facebook sdk dependency in version 4.36.0 which was resolved by downgrading the version to 4.35.0(or use latest version integration) and also posted here.

Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
2

I'm not sure why this error occurred. But I faced a similar situation, and the solution in my case was to delete two lines in the manifest.

<application
...
tools:replace="android:appComponentFactory"
android:appComponentFactory="androidx"
>

I don't know if it's the smartest solution, but it worked for me.

1

you can try to add Java 1.8 compatibility

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = "1.8"
}

add that code into your android { } at app/build.gradle

1

thanks to Pavneet_Singh answer:

i had both lines

implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.android.support:multidex:1.0.3'

i removed additional line:

implementation 'com.android.support:multidex:1.0.3'

and this error was gone.

sifr_dot_in
  • 3,153
  • 2
  • 33
  • 42
1

First of all I think that you have a double call to MultiDex.install(this) because subclassing the MultiDexApplication class calls this for you and then you are also explicitly calling it. So this may have been part of the issue I guess.

However, I had a similar problem and none of the above answers fixed it.

Our app has been around for some time (before API 21 / Android 5), and had an explicit implementation of Multidex.

class MyApplication : SomeOtherApplication() {

    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }
}

Removing the mutliDex implementation and gradle dependency,

dependencies {
  implementation "androidx.multidex:multidex:2.0.1"
}

then rebuilding the app immeditately resolved the problem.

The documentation states that as of minSdkVersion 21 multiDex is enabled by default and therefore the subclassing of the MultiDexApplication class like in the question or our implementation is no longer required.

So it would also appear like you could remove your multiDex related implementation and perhaps overcome the problem too.

For the record, although it doesn't appear to be relevant here, it is also possible to remove some of the other gradle configurations relating to multiDex as they are enabled by default. See this answer

Chris
  • 4,662
  • 2
  • 19
  • 27
0

Updating the "buildToolsVersion" in "build.gradle" and then doing a "Rebuild" solved my issue

android { ... ... ... buildToolsVersion "29.0.3" ... ... ... }

Sreeji
  • 101
  • 4
0

try to not configure multidex manually

Application class

//Remove unused imports
public class App extends Application { //change MultiDexApplication 
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        //MultiDex.install(this); //comment this
    }
}

gradle:app

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

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.packagename.appname"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 7
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        debug {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            //multiDexKeepFile file('multidex-config.txt') //comment this
            //multiDexKeepProguard file('multidex-config.pro') //comment this
            minifyEnabled true
        }
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            //multiDexKeepFile file('multidex-config.txt') //comment this
            //multiDexKeepProguard file('multidex-config.pro') //comment this
            minifyEnabled true
        }
    }
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.libraries.places:places:2.2.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'

    //implementation 'com.android.support:multidex:2.0.1' //comment this

    implementation 'com.github.vipulasri:timelineview:1.1.0'
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    implementation 'com.yanzhenjie.zbar:camera:1.0.0'
    implementation 'androidx.percentlayout:percentlayout:1.0.0'

    implementation 'com.amitshekhar.android:android-networking:1.0.2'

    implementation 'com.google.firebase:firebase-core:17.2.2'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

    implementation 'com.github.kenglxn.QRGen:android:2.5.0'

    implementation 'com.facebook.android:facebook-android-sdk:4.36.0'

    implementation 'com.jsibbold:zoomage:1.2.0'

    implementation 'androidx.arch.core:core-common:2.1.0'
    implementation 'androidx.arch.core:core-runtime:2.1.0'
}
wood wood
  • 101
  • 7
  • 1
    Hi, thanks for the answer. I have tried to commenting multidex dependencies, multiDexKeepFile and Proguard, then changing my App class extending Application and still no luck the app still doesn't load and blank.. – Erwin Kurniawan A Mar 03 '20 at 11:38
  • is there any difference with the log? – wood wood Mar 03 '20 at 11:45
  • Its still the same – Erwin Kurniawan A Mar 03 '20 at 11:54
  • have you clean project and/or invalidate caches/restart and/or rebuild project? – wood wood Mar 03 '20 at 11:56
  • it is possible that your app execute MultiDex.install() or any other code through reflection or JNI before MultiDex.install() is complete. so it can caused ClassNotFoundException. if with changes that i suggested still not work even not make the logs any difference, you should check all your dependecies. good luck – wood wood Mar 03 '20 at 12:07
0

This error can be caused due to using both androidx and legacy android support libraries

Just open project structure and go to Dependencies and select All Modules and check is there any library which contains android.support

Just replace that with androidx version for that library

In the latest versions of android studio, just REMOVE these lines if it is there inside the manifest file

<application
...
tools:replace="android:appComponentFactory"  // REMOVE THIS
android:appComponentFactory="androidx"       // REMOVE THIS
>

If still it doesn't helps try this

https://stackoverflow.com/a/74523286/6236959

-1

The situation I encountered is that my application uses a system signature, and this problem is also encountered in Android Q. No matter how I change it, I can’t change it. Just change the signature later.