Fixed
Status Update
Comments
jb...@google.com <jb...@google.com>
cl...@google.com <cl...@google.com> #2
To provide some context , R8
It is a
In the context of navigation + kotlinx serialization
, we will have to look into whether navigation can viably prevent this shrinkage/obfuscation.
In the mean time, we will be adding a lint rule to remind users to use @Keep
.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit 4940c45ab1632128129bfb64b4fd42320b081c92
Author: Clara Fok <clarafok@google.com>
Date: Mon Sep 16 13:04:40 2024
Add navigation-common lint for Keep annotation
We need to make sure that Enums that are used as nav arguments in type-safe routes are annotated with @Keep. The e
ntry point to locating said Enums are rotue declarations that contains Enum arguments.
Since the entry point is essentially the same lint location for linting @Serializable annotation, this lint uses the same detector but expands upon it.
Test: ./gradlew navigation:navigation-common-lint:test
Bug:358687142
Change-Id: I2b46fbc3b5be6251d89e902e315f50f20c46ce19
M navigation/navigation-common-lint/src/main/java/androidx/navigation/common/lint/NavigationCommonIssueRegistry.kt
M navigation/navigation-common-lint/src/main/java/androidx/navigation/common/lint/TypeSafeDestinationMissingAnnotationDetector.kt
A navigation/navigation-common-lint/src/test/java/androidx/navigation/common/lint/MissingKeepAnnotationDetectorTest.kt
https://android-review.googlesource.com/3270115
Branch: androidx-main
commit 4940c45ab1632128129bfb64b4fd42320b081c92
Author: Clara Fok <clarafok@google.com>
Date: Mon Sep 16 13:04:40 2024
Add navigation-common lint for Keep annotation
We need to make sure that Enums that are used as nav arguments in type-safe routes are annotated with @Keep. The e
ntry point to locating said Enums are rotue declarations that contains Enum arguments.
Since the entry point is essentially the same lint location for linting @Serializable annotation, this lint uses the same detector but expands upon it.
Test: ./gradlew navigation:navigation-common-lint:test
Bug:358687142
Change-Id: I2b46fbc3b5be6251d89e902e315f50f20c46ce19
M navigation/navigation-common-lint/src/main/java/androidx/navigation/common/lint/NavigationCommonIssueRegistry.kt
M navigation/navigation-common-lint/src/main/java/androidx/navigation/common/lint/TypeSafeDestinationMissingAnnotationDetector.kt
A navigation/navigation-common-lint/src/test/java/androidx/navigation/common/lint/MissingKeepAnnotationDetectorTest.kt
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
commit 33f3eee080a07079f9ce7b34d58ee210869fe180
Author: Clara Fok <clarafok@google.com>
Date: Wed Sep 18 23:32:56 2024
Add navigation-compose lint for type safe annotations
The lint checks if routes that are used to create NavDestinations are annotated with kotlinx @Serializable, and checks that enum arg types are annotated with @Keep.
Test: ./gradlew navigation:navigation-compose-lint:test
Bug: 362725816
Bug: 358687142
Change-Id: I954023cd0cb4a5ee7d08647cf9a8139b0c8ae9d9
M navigation/navigation-compose-lint/src/main/java/androidx/navigation/compose/lint/NavigationComposeIssueRegistry.kt
A navigation/navigation-compose-lint/src/main/java/androidx/navigation/compose/lint/TypeSafeDestinationMissingAnnotationDetector.kt
A navigation/navigation-compose-lint/src/test/java/androidx/navigation/compose/lint/MissingKeepAnnotationDetectorTest.kt
A navigation/navigation-compose-lint/src/test/java/androidx/navigation/compose/lint/MissingSerializableAnnotationDetectorTest.kt
M navigation/navigation-compose-lint/src/test/java/androidx/navigation/compose/lint/Stubs.kt
https://android-review.googlesource.com/3271440
Branch: androidx-main
commit 33f3eee080a07079f9ce7b34d58ee210869fe180
Author: Clara Fok <clarafok@google.com>
Date: Wed Sep 18 23:32:56 2024
Add navigation-compose lint for type safe annotations
The lint checks if routes that are used to create NavDestinations are annotated with kotlinx @Serializable, and checks that enum arg types are annotated with @Keep.
Test: ./gradlew navigation:navigation-compose-lint:test
Bug: 362725816
Bug: 358687142
Change-Id: I954023cd0cb4a5ee7d08647cf9a8139b0c8ae9d9
M navigation/navigation-compose-lint/src/main/java/androidx/navigation/compose/lint/NavigationComposeIssueRegistry.kt
A navigation/navigation-compose-lint/src/main/java/androidx/navigation/compose/lint/TypeSafeDestinationMissingAnnotationDetector.kt
A navigation/navigation-compose-lint/src/test/java/androidx/navigation/compose/lint/MissingKeepAnnotationDetectorTest.kt
A navigation/navigation-compose-lint/src/test/java/androidx/navigation/compose/lint/MissingSerializableAnnotationDetectorTest.kt
M navigation/navigation-compose-lint/src/test/java/androidx/navigation/compose/lint/Stubs.kt
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-main
commit 50b1c751929ecb0bfafa59afc1a6101b39668e9b
Author: Clara Fok <clarafok@google.com>
Date: Wed Sep 18 20:55:45 2024
Add navigation-runtime lint for type safe annotations
The lint checks if routes that are used to create NavDestinations are annotated with kotlinx @Serializable, and checks that enum arg types are annotated with @Keep.
Test: ./gradlew navigation:navigation-runtime-lint:test
Bug: 362725816
Bug: 358687142
Change-Id: Ie601a15449b1561154bd3ae5d990e006a371c7c6
M navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/NavigationRuntimeIssueRegistry.kt
A navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/TypeSafeDestinationMissingAnnotationDetector.kt
A navigation/navigation-runtime-lint/src/test/java/androidx/navigation/runtime/lint/MissingKeepAnnotationDetectorTest.kt
A navigation/navigation-runtime-lint/src/test/java/androidx/navigation/runtime/lint/MissingSerializableAnnotationDetectorTest.kt
A navigation/navigation-runtime-lint/src/test/java/androidx/navigation/runtime/lint/Stubs.kt
https://android-review.googlesource.com/3271439
Branch: androidx-main
commit 50b1c751929ecb0bfafa59afc1a6101b39668e9b
Author: Clara Fok <clarafok@google.com>
Date: Wed Sep 18 20:55:45 2024
Add navigation-runtime lint for type safe annotations
The lint checks if routes that are used to create NavDestinations are annotated with kotlinx @Serializable, and checks that enum arg types are annotated with @Keep.
Test: ./gradlew navigation:navigation-runtime-lint:test
Bug: 362725816
Bug: 358687142
Change-Id: Ie601a15449b1561154bd3ae5d990e006a371c7c6
M navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/NavigationRuntimeIssueRegistry.kt
A navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/TypeSafeDestinationMissingAnnotationDetector.kt
A navigation/navigation-runtime-lint/src/test/java/androidx/navigation/runtime/lint/MissingKeepAnnotationDetectorTest.kt
A navigation/navigation-runtime-lint/src/test/java/androidx/navigation/runtime/lint/MissingSerializableAnnotationDetectorTest.kt
A navigation/navigation-runtime-lint/src/test/java/androidx/navigation/runtime/lint/Stubs.kt
cl...@google.com <cl...@google.com>
ap...@google.com <ap...@google.com> #6
Project: platform/frameworks/support
Branch: androidx-main
commit 8b4f5f4e8219232187ac103252715c7213215625
Author: Clara Fok <clarafok@google.com>
Date: Tue Sep 24 04:42:33 2024
Add annotation lint for NavDeepLink builders
Lint for @Serializable and @Keep with for navDeepLink builders
Test: ./gradlew navigation:navigation-common-lint:test
Bug: 362725816
Bug: 358687142
Change-Id: I4a259b5544e4e4655c4bdee812d64f3b2a1947bd
M navigation/navigation-common-lint/src/main/java/androidx/navigation/common/lint/TypeSafeDestinationMissingAnnotationDetector.kt
M navigation/navigation-common-lint/src/test/java/androidx/navigation/common/lint/MissingKeepAnnotationDetectorTest.kt
M navigation/navigation-common-lint/src/test/java/androidx/navigation/common/lint/MissingSerializableAnnotationDetectorTest.kt
M navigation/navigation-lint-common/src/main/java/androidx/navigation/lint/common/BaseTypeSafeDestinationMissingAnnotationDetector.kt
M navigation/navigation-lint-common/src/main/java/androidx/navigation/lint/common/TestStub.kt
https://android-review.googlesource.com/3278871
Branch: androidx-main
commit 8b4f5f4e8219232187ac103252715c7213215625
Author: Clara Fok <clarafok@google.com>
Date: Tue Sep 24 04:42:33 2024
Add annotation lint for NavDeepLink builders
Lint for @Serializable and @Keep with for navDeepLink builders
Test: ./gradlew navigation:navigation-common-lint:test
Bug: 362725816
Bug: 358687142
Change-Id: I4a259b5544e4e4655c4bdee812d64f3b2a1947bd
M navigation/navigation-common-lint/src/main/java/androidx/navigation/common/lint/TypeSafeDestinationMissingAnnotationDetector.kt
M navigation/navigation-common-lint/src/test/java/androidx/navigation/common/lint/MissingKeepAnnotationDetectorTest.kt
M navigation/navigation-common-lint/src/test/java/androidx/navigation/common/lint/MissingSerializableAnnotationDetectorTest.kt
M navigation/navigation-lint-common/src/main/java/androidx/navigation/lint/common/BaseTypeSafeDestinationMissingAnnotationDetector.kt
M navigation/navigation-lint-common/src/main/java/androidx/navigation/lint/common/TestStub.kt
jb...@google.com <jb...@google.com> #7
This has been fixed internally and will be available in the Navigation 2.8.3
release.
Description
Component used: Navigation
Version used: Latest snapshot
Devices/Android versions reproduced on: Any
This bug report is to track the discussion that has started over at https://issuetracker.google.com/issues/358137294#comment6
The problem is that in minified builds, even though navigation now has support for enum classes, kotlinx.serialization at that point knows the name of the class before it was obfuscated by r8, and the navigation library is trying to find it by using the obfuscated name. That's my understanding of the issue.
The real effect this has when using the type-safe apis is that one is simply not able to have enums inside their serializable type-safe destinations.
The one workaround which works is to annotate the enum class with
@androidx.annotation.Keep
, however this is not mentioned anywhere, there is no compile-time warning for it, nor any lint which could help.I am reporting this here with the hopes that there can be some improvement in this area. Optimally this should "just work", even in minified builds, but if that turns out to be infeasible, perhaps some lint could help us out. And if that is infeasible too, perhaps a special error message at compile time could inform the user that they should use this annotation, or whatever other solution may be considered best.
There is a repro project herehttps://github.com/StylianosGakis/navigation-predictive-back-breaking-shared-element/tree/b401ce64c0d2b48585d92f96f626b970fb01bb4a which as seen here https://issuetracker.google.com/issues/358137294#comment9 shows this crash happening.