plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

fix(package_info_plus): fix PackageInfoPlugin.kt on latest Android 34

Open ChristianEdwardPadilla opened this issue 1 year ago • 4 comments

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.md nor the plugin version in pubspec.yaml files.
  • [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.

ChristianEdwardPadilla avatar May 31 '24 18:05 ChristianEdwardPadilla

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.

vbuberen avatar Jun 15 '24 20:06 vbuberen

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

miquelbeltran avatar Jun 19 '24 09:06 miquelbeltran

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.

vbuberen avatar Jun 19 '24 11:06 vbuberen

Apologies, the initial description was wrong. The new signatures are in API level 35: https://developer.android.com/about/versions/15

ChristianEdwardPadilla avatar Jun 27 '24 16:06 ChristianEdwardPadilla

Installed Android 15 (API 35) and validated the changes - everything is Ok. Updated the title and description to a correct version.

vbuberen avatar Jul 09 '24 10:07 vbuberen

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.

vbuberen avatar Jul 09 '24 11:07 vbuberen