gpt4 book ai didi

android - RuntimeException :ClassNotFoundException android. arch.lifecycle.ProcessLifecycleOwnerInitializer

转载 作者:行者123 更新时间:2023-12-03 13:25:12 33 4
gpt4 key购买 nike

我仅在 Android SDK < 5.0 上收到此错误。所以 4.0、4.2、4.3 等。任何运行 Android 5.0+ 的设备都能完美运行。有任何想法吗?启动时崩溃。

按照本指南进行设置-> https://developer.android.com/topic/libraries/architecture/adding-components.html

应用程序.java

public void onCreate() {
super.onCreate();

ProcessLifecycleOwner.get().getLifecycle().addObserver(new AppLifecycleListener(this));
registerActivityLifecycleCallbacks(this);
}

AppLifecycleListener.java
public class AppLifecycleListener implements LifecycleObserver {
private App app;

public AppLifecycleListener(App app)
{
this.app = app;
}

@OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onMoveToForeground() {
if (app.getCurrentActivity() instanceof BaseActivity)
{
BaseActivity baseActivity = (BaseActivity) app.getCurrentActivity();
baseActivity.runIsAPIVersionCheck();
baseActivity.fetchObjectsWithHUD(false);
}
}

@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void onMoveToBackground() {}

}

Gradle
compileSdkVersion 26

dexOptions {
javaMaxHeapSize "4g"
}

defaultConfig {
applicationId "app"
minSdkVersion 16
targetSdkVersion 26
versionCode 71
versionName "4.9.9"
multiDexEnabled true
resConfigs "en"

javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}

compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'android.arch.lifecycle:extensions:1.1.0'
compile 'android.arch.lifecycle:compiler:1.1.0'

02-28 20:54:03.151 2558-2558/? E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to get provider android.arch.lifecycle.ProcessLifecycleOwnerInitializer: java.lang.ClassNotFoundException: android.arch.lifecycle.ProcessLifecycleOwnerInitializer at android.app.ActivityThread.installProvider(ActivityThread.java:4563) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4190) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4132) at android.app.ActivityThread.access$1300(ActivityThread.java:130) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: android.arch.lifecycle.ProcessLifecycleOwnerInitializer at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) at java.lang.ClassLoader.loadClass(ClassLoader.java:501) at java.lang.ClassLoader.loadClass(ClassLoader.java:461) at android.app.ActivityThread.installProvider(ActivityThread.java:4548) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4190)  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4132)  at android.app.ActivityThread.access$1300(ActivityThread.java:130)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loop(Looper.java:137)  at android.app.ActivityThread.main(ActivityThread.java:4745)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:511)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)  at dalvik.system.NativeStart.main(Native Method) 

最佳答案

这最终成为一个多索引问题。我按照这里的文档-> https://developer.android.com/studio/build/multidex.html#mdex-gradle现在效果很好!

Gradle :

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

应用程序.java:
public class App extends Application implements Application.ActivityLifecycleCallbacks {

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

关于android - RuntimeException :ClassNotFoundException android. arch.lifecycle.ProcessLifecycleOwnerInitializer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49038667/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com