E/LoadedApk:仅在Android Q(API 29)上无法实例化appComponentFactory [英] E/LoadedApk: Unable to instantiate appComponentFactory only on Android Q (API 29)

查看:2108
本文介绍了E/LoadedApk:仅在Android Q(API 29)上无法实例化appComponentFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处都在搜索此内容,但仍然没有解决办法.

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

gradle具有minSdkVersion 21和targetSdkVersion 29

The gradle has minSdkVersion 21 and targetSdkVersion 29

我仅在API 29中遇到错误,然后该应用程序未加载并显示空白屏幕.当我看到logcat时,出现这样的错误:

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)

我认为从multidex来看,然后我尝试将以下代码添加到gradle应用

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

multiDexKeepFile文件('multidex-config.txt')

multiDexKeepFile file('multidex-config.txt')

multiDexKeepProguard文件('multidex-config.pro')

multiDexKeepProguard file('multidex-config.pro')

我的multidex-config.txt

my multidex-config.txt

com/packagename/appname/androidx.class

我的multidex-config.pro

my multidex-config.pro

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

我的App类扩展了MultiDexApplication

my App class extending MultiDexApplication

public class App extends MultiDexApplication {

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

我的清单

<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">

我的gradle.properties

my gradle.properties

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

我的gradle/应用

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!

推荐答案

错误指向使用androidx CoreComponentFactory类(使用AndroidX),但您使用的是旧软件包com.android.support:multidex

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

因此将androidx依赖项用作:

implementation 'androidx.multidex:multidex:2.0.1'

代替

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

,并确保在应用程序类中将androidx导入用作

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);
    }
}

另外:在应用程序加载期间,无论您是否在清单中使用CoreComponentFactory实例,Android Q都在内部使用它,这导致了问题.

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.

此外,将multiDexEnabled true添加为defaultConfig{multiDexEnabled true }

更新:RCA之后,androidx lib导入解决了componentfactory导入问题,尽管版本4.36.0中的facebook sdk依赖项存在另一个问题,已通过以下方式解决将版本降级为4.35.0(或使用最新版本集成),并发布

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.

这篇关于E/LoadedApk:仅在Android Q(API 29)上无法实例化appComponentFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆