fix(package_info_plus): fix PackageInfoPlugin.kt on latest Android 34
Description
This plugin fails to compile with the latest nullability signatures for Android 34.0.0
The compilation error messages are:
PackageInfoPlugin.kt:45:56: error: [UNSAFE_CALL] Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ApplicationInfo?
put("appName", info.applicationInfo.loadLabel(packageManager).toString())
^
PackageInfoPlugin.kt:47:36: error: [TYPE_MISMATCH] Type mismatch: inferred type is String? but String was expected
put("version", info.versionName)
^^^^^^^^^^^^^^^^
PackageInfoPlugin.kt:108:51: error: [SMARTCAST_IMPOSSIBLE] Smart cast to 'Array<(out) Signature!>' is impossible, because 'packageInfo.signatures' is a mutable property that could have been changed by this time
if (signatures.isNullOrEmpty() || packageInfo.signatures.first() == null) {
Checklist
- [x] I read the Contributor Guide and followed the process outlined there for submitting PRs.
- [x] I titled the PR using Conventional Commits.
- [x] I did not modify the
CHANGELOG.mdnor the plugin version inpubspec.yamlfiles. - [x] All existing and new tests are passing.
- [x] The analyzer (
flutter analyze) does not report any problems on my PR.
Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
- [ ] Yes, this is a breaking change (please indicate that with a
!in the title as explained in Conventional Commits). - [x] No, this is not a breaking change.
Could you share how you were able to reproduce the compilation failure? In which setup? Because the plugin switched to compileSDK 34 quite some time ago and there were no issues with compilation.
I assume it is something happening with some different set of Android dependencies than the ones that we have in the example app, because I can't see any of these warnings and can run it successfully.
It is weird indeed that we haven't seen this compilation issues, but checking the documentation, these two methods versionName and applicationInfo can indeed return null, so adding the null checks seems correct to me.
- https://developer.android.com/reference/android/content/pm/PackageInfo#applicationInfo
- https://developer.android.com/reference/android/content/pm/PackageInfo#versionName
It is weird indeed that we haven't seen this compilation issues, but checking the documentation, these two methods versionName and applicationInfo can indeed return null, so adding the null checks seems correct to me.
Yes, I also checked docs when was reviewing the PR a few days ago, but I am curios on how to get these compile issues from the PR description.
Apologies, the initial description was wrong. The new signatures are in API level 35: https://developer.android.com/about/versions/15
Installed Android 15 (API 35) and validated the changes - everything is Ok. Updated the title and description to a correct version.
There is a failing integration test on Android API 34 which is not related to timeouts we usually have and not related to changes in this PR. Will be addressed in another PR.