Android Hilt Throw IllegalStateException甚至在subtest.xml中说明了自定义应用程序

发布于 2025-01-28 07:56:38 字数 2687 浏览 3 评论 0 原文

我有一些真实的设备,还使用Android Studio的仿真器进行了测试,但没有发现任何类似的崩溃。

我的问题是我发布了该应用程序并收到了来自真实用户的崩溃报告。

Google Play游戏机崩溃报告

类型 java.lang.runtimeException
...
引起的是:java.lang.illegalstateException:
在Dagger.hilt.android.internal.managers.activityComponentManager.CreateComponent(activyComponentManager.java:76)
在Dagger.hilt.android.internal.managers.activityComponentManager.generatedComponent(activyComponentManager.java:66)
在myApp.hilt_firstentrypage.generatedComponent(hilt_firstentrypage.java:45)
上 在myApp.hilt_firstentrypage.Ink(hilt_firstentrypage.java:67)
上 在MyApp.hilt_firstentrypage $ 1.Oncontextavailable(Hilt_firstentrypage.java:38)
at androidx.activity.contextaware.contextawarehelper.dispatchoncontextavailable(contextawarehelper.java:99)
at androidx.activity.componentive.oncreate(componentActivity.java:322)
at androidx.fragment.App.FragmentActivity.oncreate(fragmentActivity.java:249)
在myApp.firstentrypage.oncreate(firstpage.java:68)
在Android.App.Activity.performcreate(activity.java:8207)
...

ActivityComponentManager.java:76

Hilt Activity must be attached to an @HiltAndroidApp Application. Did you forget to specify your Application's class name in your  
 manifest's <application />'s android:name attribute?

我确实检查了其他堆栈溢出问题,我已经将自定义应用程序添加到清单中并在测试设备中成功运行。

我的应用程序只有一个模块,只有一个应用程序,还有几个 contentProvider broadcastreceiver appwidgetProvider workmanager JobIntentservice ,不确定它们是否会影响正常的申请初始化以导致崩溃。

对于第一个分类活动,我没有注入任何东西。就像Hello World示例一样,这是非常简单的活动页面。因此,不可能有任何组件冲突。此外, pendingIntent 可以从 broadcastreceiver 和通知来打开第一篇文章活动。

以前的版本不适用于刀柄,此版本是第一次将刀柄带给真实用户。

androidmanifest.xml

<application
    android:name=".MyApplication"

myApplication.java

@HiltAndroidApp
public final class MyApplication extends MultiDexApplication implements Configuration.Provider

firstentrypage.java

@AndroidEntryPoint
public final class FirstEntryPage extends FragmentActivity implements OnClickListener, DialogInterface.OnClickListener

build.gradle

dependencies {
   classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.1'
}

apply plugin: 'dagger.hilt.android.plugin'  

dependencies {
   implementation 'androidx.hilt:hilt-work:1.0.0'
   implementation 'com.google.dagger:hilt-android:2.38.1'
   kapt 'androidx.hilt:hilt-compiler:1.0.0'
   kapt 'com.google.dagger:hilt-compiler:2.38.1'
}

I have a few real devices and also tested with Android studio's emulator and did not find any similar crash.

My problem is that I published the app and received crash reports from real users.

Google Play Console Crash Report

Type
java.lang.RuntimeException
...
Caused by: java.lang.IllegalStateException:
at dagger.hilt.android.internal.managers.ActivityComponentManager.createComponent (ActivityComponentManager.java:76)
at dagger.hilt.android.internal.managers.ActivityComponentManager.generatedComponent (ActivityComponentManager.java:66)
at MyApp.Hilt_FirstEntryPage.generatedComponent (Hilt_FirstEntryPage.java:45)
at MyApp.Hilt_FirstEntryPage.inject (Hilt_FirstEntryPage.java:67)
at MyApp.Hilt_FirstEntryPage$1.onContextAvailable (Hilt_FirstEntryPage.java:38)
at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable (ContextAwareHelper.java:99)
at androidx.activity.ComponentActivity.onCreate (ComponentActivity.java:322)
at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:249)
at MyApp.FirstEntryPage.onCreate (FirstPage.java:68)
at android.app.Activity.performCreate (Activity.java:8207)
...

ActivityComponentManager.java:76

Hilt Activity must be attached to an @HiltAndroidApp Application. Did you forget to specify your Application's class name in your  
 manifest's <application />'s android:name attribute?

I did check other stack overflow questions, I already did add my custom application into Manifest and run successfully in my testing devices.

My app has only one module and only one application, and also some several ContentProvider, BroadcastReceiver, AppWidgetProvider, WorkManager, JobIntentService, not sure they could affect the normal initialization of application to lead the crash.

For the FirstEntryPage activity, I did not inject any things. It is very simple activity page just like Hello World example. Therefore there could not be any component conflict. In addition, FirstEntryPage activity can be opened by PendingIntent from BroadcastReceiver and also notification.

The previous version did not apply hilt, and this version is the first time to bring hilt to real users.

AndroidManifest.xml

<application
    android:name=".MyApplication"

MyApplication.java

@HiltAndroidApp
public final class MyApplication extends MultiDexApplication implements Configuration.Provider

FirstEntryPage.java

@AndroidEntryPoint
public final class FirstEntryPage extends FragmentActivity implements OnClickListener, DialogInterface.OnClickListener

build.gradle

dependencies {
   classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.1'
}

apply plugin: 'dagger.hilt.android.plugin'  

dependencies {
   implementation 'androidx.hilt:hilt-work:1.0.0'
   implementation 'com.google.dagger:hilt-android:2.38.1'
   kapt 'androidx.hilt:hilt-compiler:1.0.0'
   kapt 'com.google.dagger:hilt-compiler:2.38.1'
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天旳寂寞 2025-02-04 07:56:38

在互联网中搜索答案之后,我在匕首github 。我也自己测试过,在相关代码更改后,我的Google Play控制台中不再有此类崩溃报告。

这是简短的答案:
使用刀具时,您不能使用 Android自动备份 android:allodbackup =“ true” 没有 android:backipagent ),否则您的应用将崩溃。

如果您的应用需要备份,则必须使用HILT,则必须使用键/值备份(Android备份服务)而不是 Android自动备份

也就是说,在您的androidManifest.xml

  • android中添加这些(以及您实现Mybackuepagent):wallybackup =“ true”
  • :backepagent =“ mybackupagent”
  • android :fullbackuponly =“ false”

如果您的应用不需要备份,则使用HILT,只需设置 android:wallybackup =“ false” in androidManifest.xml

After searching answer in the Internet, I found the answer in the dagger Github https://github.com/google/dagger/issues/2798. I also tested by myself and there is no more such crash report in my Google Play Console after related code changes.

Here is the short answer:
When using hilt, you cannot use Android Auto Backup (android:allowBackup="true" without android:backupAgent), otherwise your app will crash.

If your app needs backup, with hilt, you must use Key/Value Backup (Android Backup Service) instead of Android Auto Backup.

That is, add these (and with your implementation of MyBackupAgent) in your AndroidManifest.xml

  • android:allowBackup="true"
  • android:backupAgent="MyBackupAgent"
  • android:fullBackupOnly="false"

If you app does not need backup, with hilt, just set android:allowBackup="false" in your AndroidManifest.xml

↘紸啶 2025-02-04 07:56:38

您还需要在 firstEntryPage fragment活动的父活动中声明 @androidentrypoint

You also need to declare @AndroidEntryPoint in your parent activity of your FirstEntryPage Fragment Activity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文