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

Fixed LeakCanary #5784

Merged
merged 6 commits into from
Oct 31, 2023
Merged

Fixed LeakCanary #5784

merged 6 commits into from
Oct 31, 2023

Conversation

grzesiek2010
Copy link
Member

@grzesiek2010 grzesiek2010 commented Oct 18, 2023

Closes #5782

Why is this the best possible solution? Were any other approaches considered?

Nothing to discuss here. I've just fixed LeakCanary so that it works well for us.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

It doesn't require testing.

Do we need any specific form for testing your changes? If so, please attach one.

No.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

No.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew checkAll and confirmed all checks still pass OR confirm CircleCI build passes and run ./gradlew connectedDebugAndroidTest locally.
  • added a comment above any new strings describing it for translators
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="leak_canary_test_class_name" translatable="false">assertk.Assert</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain how this fixes things? Might be worth a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables LeakCanary. It was disabled with this message: LeakCanary is currently disabled: test class org.junit.Test was found in classpath and according to https://square.github.io/leakcanary/changelog/#api-breaking-bettering-changes this is how we need to fix it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment.

Copy link
Member

@seadowg seadowg Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Not sure I get why we're using assertk.Assert as the test class to detect though? We don't use assertk as far as I'm aware.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, LeakCanary will look for the org.junit.Test class in your classpath and if found, will disable itself to avoid running in tests. However, some apps may ship JUnit in their debug classpaths (for example, when using OkHttp's MockWebServer) so we offer a way to customise the class that is used to determine that the app is running in a test environment.

My understanding is that by default it looks for org.junit.Test and in our case it was found and LeakCanary was disabled.
With this line, it will look for assertk.Assert that does not exist so LeakCanary will be enabled.
That's how I understand it but the documentation is poor and I'm not the only one complaining about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this line, it will look for assertk.Assert that does not exist so LeakCanary will be enabled.

Right. But that will mean it also runs during tests right? My interpretation of those docs is that we should set leak_canary_test_class_name to a class that will only be present in tests (which would be the original intention of org.junit.Test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I used androidx.test.ext.junit.runners.AndroidJUnit4 instead.

@seadowg seadowg merged commit f7a861c into getodk:master Oct 31, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LeakCanary doesn't work
2 participants