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

[Android Auto] Make interfaces backwards compatible in java #1670

Merged
merged 2 commits into from
Sep 20, 2022

Conversation

kmadsen
Copy link
Contributor

@kmadsen kmadsen commented Sep 14, 2022

Summary of changes

We would like to release a stable api for this AA extension library. In order to create a stable api we also prefer solutions that are flexible for handling future changes.

Making the gesture handler capable of adding the onClick function in the future without breaking SEMVER #1604

We don't have a solution at the moment, that allows downstream to add the onClick without an extension upgrade. It would be nice to have an implementation that allowed for extension, but the Jetpack car library is difficult in this regard. The library only allows for a single SurfaceCallback, if it allowed for multiple this would be easy. Here is a ticket where we asked Google to add this flexibility https://issuetracker.google.com/u/0/issues/200592099. There may be another solution here, but I'm only imaging something with reflection.

The other solution, is for Mapbox to release a beta channel. The AA beta channel could support for the AA beta apis.

For now, this pull request simply makes it so there is better java backwards compatibility in the mapbox extension.

User impact (optional)

Pull request checklist:

  • Briefly describe the changes in this PR.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality. If tests were not written, please explain why.
  • Optimize code for java consumption (@JvmOverloads, @file:JvmName, etc).
  • Add example if relevant.
  • Document any changes to public APIs.
  • Run make update-api to update generated api files, if there's public API changes, otherwise the verify-api-* CI steps might fail.
  • Update CHANGELOG.md or use the label 'skip changelog', otherwise check changelog CI step will fail.
  • If this PR is a v10.[version] release branch fix / enhancement, merge it to main firstly and then port to v10.[version] release branch.

Fixes: < Link to related issues that will be fixed by this pull request, if they exist >

PRs must be submitted under the terms of our Contributor License Agreement CLA.

@kmadsen kmadsen force-pushed the km-make-gesture-handler-backwards-compatible branch 2 times, most recently from e443f68 to b1f9cf1 Compare September 14, 2022 18:14
@kmadsen kmadsen marked this pull request as ready for review September 14, 2022 18:14
@kmadsen kmadsen requested review from a team as code owners September 14, 2022 18:14
@kmadsen kmadsen force-pushed the km-make-gesture-handler-backwards-compatible branch 4 times, most recently from a6bf196 to e2e3771 Compare September 15, 2022 20:02
@kmadsen kmadsen changed the title Make MapboxCarMapGestureHandler backwards compatible [Android Auto] Make interfaces backwards compatible in java Sep 15, 2022
@@ -32,6 +32,10 @@ android {
}
}

kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-Xjvm-default=all"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Am testing this on a bunch of interfaces to see if we catch any issues on the navigation side

mapbox/mapbox-navigation-android#6335 (comment)
^ Here are some details that show that adding the compiler flag may force some projects to add the compiler option. That seems like an issue with the compiler flag 🤔

Copy link
Contributor Author

@kmadsen kmadsen Sep 15, 2022

Choose a reason for hiding this comment

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

For this reason I'm preferring the java interface approach..

Copy link
Contributor

Choose a reason for hiding this comment

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

And by java interface approach you mean jvm-default=all instead of older annotation option?

Btw https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-m3-generating-default-methods-in-interfaces/ found a blog post summarizing the differences

Copy link
Contributor Author

@kmadsen kmadsen Sep 16, 2022

Choose a reason for hiding this comment

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

I mean, jvm-default=all works well if you are building an app but it has as different behavior when building an sdk.

specifically, when I added -Xjvm-default=all to the nav-sdk it broke a downstream build because it is not using -Xjvm-default=all that is using kotlin. So a new SDK like android-auto could require downstream to add the flag, but this unpredictability is too concerning IMO.

What I mean, is define the interface with MyInterface.java so that the sdk is not depending on a "kotlin to java" converter. It is instead relying on "kotlin's java interpreter" which is a bit more reliable.

Copy link
Contributor Author

@kmadsen kmadsen Sep 16, 2022

Choose a reason for hiding this comment

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

Notice how this pull request requires the addition of the compiler flat in both build.gradle files

android-auto-app/build.gradle.kts
extension-androidauto/build.gradle.kts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yunikkk this pull request is updated with the approach I'm thinking we need.

I've moved the jvm-default flag approach over here #1674

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM, I'm fine with the approach.

BTW could you elaborate the issue you've faced adding with the -Xjvm-default=all flag? Were you able to fix using snapshot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I've updated this branch to use the jvm-default issue https://github.com/mapbox/mapbox-maps-android/pull/1674/files#r975672871

That way anyone can pull that branch and reproduce the issue

Copy link
Contributor Author

@kmadsen kmadsen Sep 20, 2022

Choose a reason for hiding this comment

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

#1670 (comment)

This comment describes the issue well. The -Xjvm-default compiler flag may do what we want in the future. But right now, it does not generate default interfaces in an SDK. The app developer has to include the flag in their app to make the app compile when it uses an sdk that is relying on the flag.

One big issue for us to not add it, is kotlin will fail to compile if the app does not include it - totally unexpected behavior in my opinion because I would only expect java to fail to compile.

Copy link
Contributor

Choose a reason for hiding this comment

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

But right now, it does not generate default interfaces in an SDK.

Unexpected indeed, thanks for the investigation

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.

5 participants