-
Notifications
You must be signed in to change notification settings - Fork 119
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
Migrate codebase from Dagger to Hilt #505
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful! Finally, an opinionated standard on how to structure DI in Android. Taking a look now; in the meantime, please run gradle checkstyle
, you'll see the following error:
Already have image (with digest): gcr.io/cloud-builders/gsutil
Reports uploaded to https://console.cloud.google.com/storage/browser/artifact_bucket/hilt-migration-0be56337-08b4-4bda-94e5-6667ee4e9522/
[ant:checkstyle] [ERROR] /workspace/gnd/src/main/java/com/google/android/gnd/ui/offlinearea/viewer/OfflineAreaViewerViewModel.java:49: Line is longer than 100 characters (found 119). [LineLength]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':workspace:gnd:checkstyle'.
> Checkstyle rule violations were found. See the report at: file:///workspace/gnd/build/reports/checkstyle/checkstyle.html
Checkstyle files with violations: 1
Checkstyle violations by severity: [error:1]
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 42s
/workspace/gnd/src/test/java/com/google/android/gnd/persistence/local/LocalDataStoreTest.java:26: error: cannot find symbol
import com.google.android.gnd.inject.DaggerTestComponent;
^
symbol: class DaggerTestComponent
location: package com.google.android.gnd.inject
/workspace/gnd/src/test/java/com/google/android/gnd/persistence/local/LocalDataStoreTest.java:204: error: cannot find symbol
DaggerTestComponent.create().inject(this);
^
symbol: variable DaggerTestComponent
location: class LocalDataStoreTest
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':gnd:compileDebugUnitTestJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 49s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migration LGTM! Have you tested all flows end to end to ensure there are no regressions after this change?
Many thanks for the quick review. Is there an exhaustive list of flows somewhere which I can use to manually test? This would be v.useful for writing the UI/integration tests as well. |
Thanks @dturner! I think the build is failing because of unit tests (looking at the above stack-trace). |
Thanks for the massive cleanup. I tried running the app and thinks are working fine except when trying to sync data remotely. The below crash happens after creating a new observation, filling some info and clicking "save" button.
|
@dturner Is there a specific reason for creating separate Secondly, we need to specifically uninstall module (as done in |
@shobhitagarwal1612 great questions.
The original code had a separate testing application and much simplified Dagger dependency graph with a single module which injected the testing dependencies (the only real difference I can see is that the Room database allows queries on the main thread) The strategy for testing in Hilt is different. You start with your production We could have a single "testing" module which satisfies the dependencies of both the above modules. I kept them separate to keep a 1:1 mapping between uninstalled modules and installed test modules so it's clear what's being swapped.
Yes, this is the Hilt way. There are downsides to this approach. Relevant issues/discussions: google/dagger#1896 In this case I think the bigger question is: can we avoid Dagger/Hilt/Robolectric entirely for unit tests? We could avoid these extra dependencies/complexity by changing our codebase to support manual DI. In this case we're testing The architecture samples project has a good example of unit testing a local data store using manual DI. I'd like to investigate this in a followup PR and would love to get your thoughts. |
@gino-m ok to merge? Just need your approval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🥇
Hilt is a new DI framework for Android built on top of Dagger. It provides the same features in a simplified way by removing much of the heavy lifting associated with Dagger.
This PR migrates the Ground codebase from Dagger and dagger.android to Hilt. I followed the migration guide here and had some help from Manuel Vivo.
Here's the summary of work:
GndApplicationComponent
to Hilt'sApplicationComponent
@AndroidEntryPoint
to install activities and fragments into Hilt's corresponding componentsdagger.android
dependenciesGndWorkerFactory
to Jetpack'sHiltWorkerFactory