Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide warning about using "allowBackup" with Hilt #2798

Open
pablobaxter opened this issue Aug 4, 2021 · 5 comments
Open

Provide warning about using "allowBackup" with Hilt #2798

pablobaxter opened this issue Aug 4, 2021 · 5 comments

Comments

@pablobaxter
Copy link

Currently, there's a known issue with android:allowBackup=true and having a subclassed Application in that if a service or receiver is triggered while the app is backing app and attempts to inject a context, it could potentially crash. A side effect is that a crash while the app is backing up will leave it in the "restricted" mode that disabled the subclassed Application, and the next app start (either user initiated or via intent) will cause injection to fail once again.

Google bug ticket describing this: https://issuetracker.google.com/issues/160946170

Given that Hilt requires we subclass Application, there should also be a warning about using backup on the app as well.

@bcorso
Copy link

bcorso commented Aug 4, 2021

@pablobaxter do you have a recommendation for where you would want this information to be located, e.g. javadoc of some class/annotation vs somewhere in the dagger.dev/hilt documentation?

@pablobaxter
Copy link
Author

A few places, for example:

Basically, anywhere where it states that the Application context must be overridden, a warning about allowBackup should be placed as well. For reference as to why I'm making this suggestion, refer to this github issue: #748

@Chang-Eric
Copy link
Member

We discussed this and I think maybe a known issues or FAQ section on the site will be good for longstanding issues like this.

@pablobaxter
Copy link
Author

Both of those options are great places for this known issue, but a concern I have is that these crashes and issues are not always obvious as to what is the root cause. I spent some months to narrow an issue down to it being because of me overriding the Application class along with usage of allowBackup (which defaults to true). During my debugging, the issue kept pointing me back to either Dagger, Firebase, or some other areas which made the problem non-obvious.

Having some sort of note about overriding Application and using allowBackup upfront could have potentially cut down on my investigation and saved me much heartache. In all honesty, this note should be in the Application documentation as well, but that's a different issue altogether.

@aberaud
Copy link

aberaud commented Apr 17, 2024

We just found this issue after years of trying to understand Play Console reports that our app was crashing with
Caused by java.lang.IllegalStateException: Hilt service must be attached to an @HiltAndroidApp Application. Found: class android.app.Application.

Not being able to use allowBackup with Hilt is a major limitation that should be documented, especially since allowBackup is true by default. Ideally the build should fail in that scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants