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

fix KotlinConstructorBuilder on Android SDK below 26 #2881

Merged
merged 5 commits into from
Apr 2, 2024

Conversation

damianw
Copy link
Contributor

@damianw damianw commented Mar 26, 2024

Fixes #2876. I also added a sample app that can run on API 24+ per @oldergod's request, and verified that it no longer crashes.

Screenshot_1711467123

Copy link
Member

@oldergod oldergod left a comment

Choose a reason for hiding this comment

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

Thanks for the PR

Could we get rid of all the mipmap folders but one?

Comment on lines +34 to +37
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val someText = checkNotNull(jsonAdapter.fromJson("""{"value": "Hi"}"""))
findViewById<TextView>(R.id.text_view).text = someText.value_
Copy link
Member

@oldergod oldergod Mar 28, 2024

Choose a reason for hiding this comment

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

Since we're fixing a runtime problem, we need this code to run on CI to be useful. We thus need a test that execute this path.

Right now, without your fix, this would not throw either since CI isn't launching the app.

Copy link
Member

Choose a reason for hiding this comment

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

hmmmm does that mean we need androidTests with an emulator...? hmmm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup - I would love to write a test but I am both unfamiliar with the CI setup, and I don't think the current build configuration supports any of the ways I can think of to add a regression test for this, so your input would be helpful on what you think would be best. I don't want to introduce something unmaintainable just for this one test.

Right now I can think of a few ways this might be done, all of which are pretty icky in the context of what exists in the project already:

  • Run unit tests on an older JDK: don't think the project has any support for this
  • Use a mocking framework (e.g. MockK or Mockito): one is not already used in the project
  • Use Robolectric: I don't even know if it would pick this up, but it is not part of this project
  • Run instrumentation tests: Could use Gradle managed devices, or Firebase Test Lab. For the former, would need bare metal machines (which are probably already being used in the form of Mac agents?)

Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

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

I think I would copy/pasta as much as we need from Retrofit
https://github.com/square/retrofit/blob/trunk/.github/workflows/build.yml#L30-L64

If that sounds doable to you, please! otherwise I can tackle that when I have the time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just what I need, thanks! Will do.

By the way, it looks like com.squareup.wire.GrpcClientTest > streamingRequestFailureWithUnexpectedHttpCode might be flaky

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added - fwiw I wasn't able to use assertj because it depends on other JDK APIs that can't be desugared

@@ -108,7 +108,6 @@ internal class KotlinConstructorBuilder<M : Message<M, B>, B : Message.Builder<M
.sortedBy { it.wireField.schemaIndex }

private class ProtoField(
// TODO(Benoit) Delete if unused?
Copy link
Member

Choose a reason for hiding this comment

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

This was waiting for you it seems

@oldergod
Copy link
Member

oldergod commented Apr 2, 2024

Thanks a lot Damian, chef-kiss PR.

@oldergod oldergod merged commit a555eb2 into square:master Apr 2, 2024
11 checks passed
@damianw
Copy link
Contributor Author

damianw commented Apr 2, 2024

Thanks for merging! Are there any plans to release another stable version (4.9.9?) in the near future?

oldergod added a commit that referenced this pull request Apr 2, 2024
fix KotlinConstructorBuilder on Android SDK below 26
@oldergod
Copy link
Member

oldergod commented Apr 2, 2024

4.9.9 has been released. Let me know how it went

@damianw
Copy link
Contributor Author

damianw commented Apr 2, 2024

Amazing, thank you! Will do 🙇

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.

NoSuchMethodError for java.lang.Constructor#getParameterCount
2 participants