web-dev-qa-db-ja.com

E / LoadedApk:Android Q(API 29)でのみappComponentFactoryをインスタンス化できません

私はこれについてどこでも検索しましたが、まだ解決策はありません。

GradleにはminSdkVersion 21とtargetSdkVersion 29があります

API 29でのみエラーが発生しました。アプリが読み込まれず、空白の画面が表示されます。 logcatを見ると、次のようなエラーが発生します。

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アプリに次のコードを追加してみました

multiDexKeepFileファイル( 'multidex-config.txt')

multiDexKeepProguardファイル( 'multidex-config.pro')

私のmultidex-config.txt

com/packagename/appname/androidx.class

私のmultidex-config.pro

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

multiDexApplicationを拡張する私のAppクラス

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

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

私の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'
}

これに対する解決策が本当に必要です。助けてください、どうもありがとう!

3

あなたはJava 1.8互換性を追加しようとすることができます

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

そのコードをAndroid { } at app/build.gradle

1

multidexを手動で設定しないようにしてください

アプリケーションクラス

//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'
}
0
wood wood

「build.gradle」の「buildToolsVersion」を更新してから「再構築」を実行すると、問題が解決しました

Android {... ... ... buildToolsVersion "29.0.3" ... ... ...}

0
Sreeji