-
Notifications
You must be signed in to change notification settings - Fork 131
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
Conversation
e443f68
to
b1f9cf1
Compare
...ndroidauto/src/main/java/com/mapbox/maps/extension/androidauto/MapboxCarMapGestureHandler.kt
Outdated
Show resolved
Hide resolved
a6bf196
to
e2e3771
Compare
android-auto-app/build.gradle.kts
Outdated
@@ -32,6 +32,10 @@ android { | |||
} | |||
} | |||
|
|||
kotlinOptions { | |||
freeCompilerArgs = freeCompilerArgs + "-Xjvm-default=all" |
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.
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 🤔
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.
For this reason I'm preferring the java interface
approach..
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.
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
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.
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.
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.
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
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.
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, 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?
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.
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
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.
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.
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.
But right now, it does not generate default interfaces in an SDK.
Unexpected indeed, thanks for the investigation
e2e3771
to
a308c2b
Compare
a308c2b
to
651733f
Compare
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 #1604We 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 singleSurfaceCallback
, 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:
@JvmOverloads
,@file:JvmName
, etc).make update-api
to update generated api files, if there's public API changes, otherwise theverify-api-*
CI steps might fail.check changelog
CI step will fail.v10.[version]
release branch fix / enhancement, merge it tomain
firstly and then port tov10.[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.