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

查看:160
本文介绍了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

我的毕业/应用

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 之后,componentfactory 导入问题已通过 androidx 库导入解决,尽管 facebook sdk 存在另一个问题版本 4.36.0 中的依赖项已通过将版本降级到 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天全站免登陆