AndroidX Build Fails in Release Mode regarding appComponentFactory

一笑奈何 提交于 2019-11-27 03:11:31

问题


I'm using Android P and compiling against AndroidX. Works great in debug/beta, but when I make a release I get a cryptic crash during runtime:

2018-06-24 00:21:26.080 11971-11971/? E/LoadedApk: Unable to instantiate appComponentFactory java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/app.itsyour.elegantstocks-EuVZWdDgzplhm0Hpa90VwA==/base.apk"],nativeLibraryDirectories=[/data/app/app.itsyour.elegantstocks-EuVZWdDgzplhm0Hpa90VwA==/lib/x86, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:126) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at android.app.LoadedApk.createAppFactory(LoadedApk.java:226) at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:731) at android.app.LoadedApk.getClassLoader(LoadedApk.java:772) at android.app.LoadedApk.getResources(LoadedApk.java:994) at android.app.ContextImpl.createAppContext(ContextImpl.java:2345) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5736) at android.app.ActivityThread.access$1000(ActivityThread.java:197) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1634) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6642) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 2018-06-24 00:21:26.145 1667-1854/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property 2018-06-24 00:21:26.233 1667-1703/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property 2018-06-24 00:21:29.627 1796-1913/? E/TaskPersister: File error accessing recents directory (directory doesn't exist?). 2018-06-24 00:21:30.087 11971-11971/? E/AndroidRuntime: FATAL EXCEPTION: main Process: app.itsyour.elegantstocks, PID: 11971 java.lang.IllegalArgumentException: Parameter specified as non-null is null: method c.d.b.h.b, parameter $receiver at app.itsyour.elegantstocks.a.b.a(Unknown Source:2) at app.itsyour.elegantstocks.feature.navigator.b.a$a.a(Unknown Source:24) at app.itsyour.elegantstocks.feature.navigator.b.a.a(Unknown Source:13) at app.itsyour.elegantstocks.feature.navigator.b.a.a(Unknown Source:2) at androidx.recyclerview.widget.RecyclerView$a.a(Unknown Source:0) at androidx.recyclerview.widget.RecyclerView$a.b(Unknown Source:29) at androidx.recyclerview.widget.RecyclerView$p.a(Unknown Source:39) at androidx.recyclerview.widget.RecyclerView$p.a(Unknown Source:510) at androidx.recyclerview.widget.RecyclerView$p.a(Unknown Source:5) at androidx.recyclerview.widget.RecyclerView$p.c(Unknown Source:1) at androidx.recyclerview.widget.LinearLayoutManager$c.a(Unknown Source:11) at androidx.recyclerview.widget.LinearLayoutManager.a(Unknown Source:0) at androidx.recyclerview.widget.LinearLayoutManager.a(Unknown Source:44) at androidx.recyclerview.widget.LinearLayoutManager.c(Unknown Source:371) at androidx.recyclerview.widget.RecyclerView.O(Unknown Source:42) at androidx.recyclerview.widget.RecyclerView.q(Unknown Source:41) at androidx.recyclerview.widget.RecyclerView.onLayout(Unknown Source:5) at android.view.View.layout(View.java:20670) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20670) at android.view.ViewGroup.layout(ViewGroup.java:6194) at androidx.constraintlayout.widget.ConstraintLayout.onLayout(Unknown Source:66) at android.view.View.layout(View.java:20670) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20670) at android.view.ViewGroup.layout(ViewGroup.java:6194) at androidx.swiperefreshlayout.widget.SwipeRefreshLayout.onLayout(Unknown Source:60) at android.view.View.layout(View.java:20670) at android.view.ViewGroup.layout(ViewGroup.java:6194) at androidx.coordinatorlayout.widget.CoordinatorLayout.d(Unknown Source:143) at androidx.coordinatorlayout.widget.CoordinatorLayout.a(Unknown Source:32) at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(Unknown Source:48) at android.view.View.layout(View.java:20670) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20670) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) at android.widget.LinearLayout.onLayout(LinearLayout.java:1565) at android.view.View.layout(View.java:20670) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20670) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) at android.widget.LinearLayout.onLayout(LinearLayout.java:1565) at android.view.View.layout(View.java:20670) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:753) at android.view.View.layout(View.java:20670) 2018-06-24 00:21:30.087 11971-11971/? E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2767) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2294) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1447) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7130) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:935) at android.view.Choreographer.doCallbacks(Choreographer.java:747) at android.view.Choreographer.doFrame(Choreographer.java:682) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:921) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6642) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 2018-06-24 00:21:30.137 1796-1880/? E/InputDispatcher: channel '5896582 app.itsyour.elegantstocks/app.itsyour.elegantstocks.feature.navigator.NavigatorActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 2018-06-24 00:21:30.253 5198-9377/? E/EntrySyncManager: Cannot determine account name: drop request 2018-06-24 00:21:30.253 5198-9377/? E/NowController: Failed to access data from EntryProvider. ExecutionException. java.util.concurrent.ExecutionException: com.google.android.apps.gsa.sidekick.main.h.n: Could not complete scheduled request to refresh entries. ClientErrorCode: 3 at com.google.common.util.concurrent.d.eA(SourceFile:85) at com.google.common.util.concurrent.d.get(SourceFile:23) at com.google.common.util.concurrent.l.get(SourceFile:2) at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.caI(SourceFile:47) at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.caH(SourceFile:176) at com.google.android.apps.gsa.staticplugins.nowstream.b.a.bh.run(Unknown Source:2) at com.google.android.apps.gsa.shared.util.concurrent.at.run(SourceFile:4) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at com.google.android.apps.gsa.shared.util.concurrent.b.g.run(Unknown Source:4) at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4) at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764) at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(SourceFile:6) Caused by: com.google.android.apps.gsa.sidekick.main.h.n: Could not complete scheduled request to refresh entries. ClientErrorCode: 3 at com.google.android.apps.gsa.staticplugins.nowstream.b.a.aq.az(Unknown Source:4) at com.google.common.util.concurrent.q.ap(SourceFile:7) at com.google.common.util.concurrent.p.run(SourceFile:32) at com.google.common.util.concurrent.bt.execute(SourceFile:3) at com.google.common.util.concurrent.d.b(SourceFile:275) at com.google.common.util.concurrent.d.addListener(SourceFile:135) at com.google.common.util.concurrent.p.b(SourceFile:3) at com.google.android.apps.gsa.shared.util.concurrent.h.a(SourceFile:16) at com.google.android.apps.gsa.shared.util.concurrent.h.a(SourceFile:13) at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.caI(SourceFile:45) at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.caH(SourceFile:176)  at com.google.android.apps.gsa.staticplugins.nowstream.b.a.bh.run(Unknown Source:2)  at com.google.android.apps.gsa.shared.util.concurrent.at.run(SourceFile:4)  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)  at java.util.concurrent.FutureTask.run(FutureTask.java:266)  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)  at java.util.concurrent.FutureTask.run(FutureTask.java:266)  at com.google.android.apps.gsa.shared.util.concurrent.b.g.run(Unknown Source:4)  at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)  at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:764)  at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(SourceFile:6)

My gradle files. Project gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

ext {
    androidXVersion = '1.0.0-alpha3'
    supportLibraryVersion = '28.0.0-alpha1'
}

buildscript {
    ext.kotlin_version = '1.2.50'
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-beta01'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects 

{
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
     }
}

 task clean(type: Delete) {
     delete rootProject.buildDir
 }

App gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

def versionMajor = 1
def versionMinor = 0
def versionPatch = project.hasProperty('buildNumber') ? project.getProperties().get('buildNumber').toInteger() : 0

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "app.itsyour.elegantstocks"
        minSdkVersion 25
        targetSdkVersion 28

        // Version
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
        versionCode versionMajor * 1000000 * versionMinor * 10000 + versionPatch
        resValue "string", "build_number", "Version ${versionName}"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        kapt {
            arguments {
                arg("room.schemaLocation", "$projectDir/schemas".toString())
            }
        }
    }

    buildTypes {
        release {
            resValue "string", "app_name", "Elegant Stocks"
            signingConfig signingConfigs.release
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-release.pro'
        }
        staging {
            resValue "string", "app_name", "Elegant Stocks"
            signingConfig signingConfigs.staging
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-staging.pro'
        }
        beta {
            signingConfig signingConfigs.beta
            debuggable true
            minifyEnabled false
            applicationIdSuffix ".beta"
            versionNameSuffix "-BETA"
            resValue "string", "app_name", "Elegant Stocks Beta"
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-beta.pro'
        }
        debug {
            debuggable true
            minifyEnabled false
            resValue "string", "app_name", "Elegant Stocks Debug"
            applicationIdSuffix ".debug"
            versionNameSuffix = "-DEBUG"
        }
    }

    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
            all {
                testLogging {
                    events "passed", "failed", "skipped"
                }
            }
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "androidx.appcompat:appcompat:$androidXVersion"
    implementation "androidx.fragment:fragment-ktx:$androidXVersion"
    implementation "com.google.android.material:material:$androidXVersion"
    implementation "androidx.recyclerview:recyclerview:$androidXVersion"
    implementation "androidx.core:core-ktx:$androidXVersion"
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'

    // Dagger 2
    implementation 'com.google.dagger:dagger:2.16'
    implementation 'com.google.dagger:dagger-android:2.16'
    implementation 'com.google.dagger:dagger-android-support:2.16'
    kapt 'com.google.dagger:dagger-compiler:2.16'
    kapt 'com.google.dagger:dagger-android-processor:2.16'

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'

    // Stetho
    implementation 'com.facebook.stetho:stetho:1.5.0'
    implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'

    // Rx
    implementation 'io.reactivex.rxjava2:rxjava:2.1.13'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
    implementation 'com.jakewharton.rxbinding2:rxbinding-kotlin:2.1.1'
    implementation 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7-kotlin:2.1.1'
    implementation 'com.jakewharton.rx2:replaying-share:2.0.1'

    // Room
    implementation "androidx.room:room-runtime:2.0.0-alpha1"
    implementation "androidx.room:room-rxjava2:2.0.0-alpha1"
    kapt "androidx.room:room-compiler:2.0.0-alpha1"

    // Logging
    implementation 'com.jakewharton.timber:timber:4.7.0'

    // Time
    implementation 'com.jakewharton.threetenabp:threetenabp:1.1.0'

    // UI
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
    implementation 'net.opacapp:multiline-collapsingtoolbar:27.1.1'
    implementation 'com.balysv:material-ripple:1.0.2'

    // Testing
    androidTestImplementation "com.android.support.test:runner:1.0.2"
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
    testImplementation 'junit:junit:4.12'
    testImplementation "org.jetbrains.kotlin:kotlin-test-junit:${kotlin_version}"
    testImplementation "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
    testImplementation "org.mockito:mockito-core:2.18.3"
    testImplementation "org.robolectric:robolectric:3.8"
    testImplementation "org.robolectric:shadows-multidex:3.8"
}

Proguard:

# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn org.codehaus.mojo.animal_sniffer.**
-dontwarn javax.annotation.**
-dontwarn org.conscrypt.**

回答1:


Add -keep class androidx.core.app.CoreComponentFactory { *; } to your proguard config so that this class won't be proguarded out



来源:https://stackoverflow.com/questions/51006967/androidx-build-fails-in-release-mode-regarding-appcomponentfactory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!