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

compileSdkVersion 33; androidx.activity/appcompat upgrades; transitives #944

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

steve-the-edwards
Copy link
Contributor

@steve-the-edwards steve-the-edwards commented Feb 22, 2023

With upgrading of Compose, we revealed a tricky bug in renderAsState caught by the SampleLauncherTest while scrolling a LazyColumn to bring a Composable into view whose state was driven by renderAsState. The fix was to launch a coroutine to transfer the state from Workflow into Compose state via an UNDISPATCHED launched coroutine rather than an onEach on the flow.

@@ -2,14 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

How come?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

New requirement to request this permission if your app posts any notifications. Good point that I didn't really look into why this was being linted and if there was a way of specifying that we don't post notifications. I kind of thought that, hey, might as well just include it. Too messy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is a branch new permission that only applies to API 33+ installs. On those you need to request the permission at runtime. There will be follow-on work for this. Alternative would be to leave it out and disable the Android Lint setting for this? I think this is likely the least intrusive way forward?

What will catch us is when we start running on API 33 devices. I will create an issue to track that.

Copy link
Contributor

@rjrjr rjrjr Feb 27, 2023

Choose a reason for hiding this comment

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

If the lint setting is as stupid as "always request this permission," then I'd be inclined to disable it. In samples I think we should work pretty hard only to include things we're certain we're actually using.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks for code that uses Notifications, but this can be in classes from dependent libraries - classes which aren't necessarily used. This is only a warning, but since we have warning=error it fails the build.

I'm going to take these out and take a lint warnings baseline, then use that going forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out I don't think we need POST_NOTIFICATIONS once i finished updating some transitive dependency libraries (this isn't in the lint baseline). Obviously one of the libraries had to update for Android 13 as well.

@@ -29,7 +31,15 @@ internal data class ViewStateFrame(
companion object CREATOR : Creator<ViewStateFrame> {
override fun createFromParcel(parcel: Parcel): ViewStateFrame {
val key = parcel.readString()!!
val viewState = parcel.readSparseArray<Parcelable>(ViewStateFrame::class.java.classLoader)!!
val viewState = if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm kind of amazed they didn't give us compat wrappers to do all this version checking

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make our own? We already have a module of Androidx support methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could consider it for sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did not do this as I think this type of branching is pretty standard practice and I'm ok with it as it makes it clear what can happen down the road rather than hiding that behind some syntactic sugar.

@steve-the-edwards steve-the-edwards force-pushed the sedwards/compile-sdk-33 branch 5 times, most recently from e5b2ffa to 55f5d80 Compare February 24, 2023 15:29
@steve-the-edwards steve-the-edwards marked this pull request as ready for review February 24, 2023 15:35
Comment on lines 13 to 17
androidx-compose-compiler = "1.3.2"
androidx-compose-foundation = "1.3.1"
androidx-compose-material = "1.3.1"
androidx-compose-runtime = "1.3.3"
androidx-compose-ui = "1.3.3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

holy fragmentation

Copy link

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@steve-the-edwards steve-the-edwards force-pushed the sedwards/compile-sdk-33 branch 2 times, most recently from 10e1725 to 787fa0e Compare February 28, 2023 17:16
Fix RenderAsState which was exposed by test as state was not set initially always.
Comment on lines +15 to +19
configure<BaseAppModuleExtension> {
lint {
baseline = file("lint-baseline.xml")
}
}
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 this to baseline android lint warnings at this snapshot.

Comment on lines +209 to +212
workflowScope.launch(
start = UNDISPATCHED,
context = Dispatchers.Unconfined
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved from shuttling these renderings and snapshot into compose state in an onEach started by a launchIn on Dispatchers.Unconfined to launching for the collection with an CoroutineStart.UNDISPATCHED coroutine and this fixes the timing issue we saw come up in the Compose sample test while scrolling the LazyColumn.

cc @rjrjr and @RBusarow .

I discussed this with @zach-klippenstein . He thinks there may still be some Compose bug here but this is making the behavior more reliable for us for now and while it makes this PR messy I'm inclined to merge it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems fine to me 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This could be a big win. The problem your describing sounds very similar to one that has been plaguing a lot of our Compose tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, but we don't use renderAsState :(

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.

4 participants