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

Prepare for SDK 34 #376

Closed
PatrykMis opened this issue Jul 10, 2023 · 4 comments · Fixed by #377
Closed

Prepare for SDK 34 #376

PatrykMis opened this issue Jul 10, 2023 · 4 comments · Fixed by #377
Assignees
Labels
enhancement New feature or request

Comments

@PatrykMis
Copy link
Contributor

PatrykMis commented Jul 10, 2023

Android SDK 34 is already stable. When setting CompileSdkVersion to 34, build failes with errors below.

Changed also AGP to v8.2.0-alpha10 and buildToolsVersion to 34.0.0, although buildToolsVersion does not matter here.

e: file:///C:/BCR/app/src/main/java/com/chiller3/bcr/RecorderTileService.kt:10:1 Class 'RecorderTileService' is not abstract and does not implement abstract member public abstract fun onSharedPreferenceChanged(p0: SharedPreferences!, p1: String?): Unit defined in android.content.SharedPreferences.OnSharedPreferenceChangeListener
e: file:///C:/BCR/app/src/main/java/com/chiller3/bcr/RecorderTileService.kt:47:5 'onSharedPreferenceChanged' overrides nothing
e: file:///C:/BCR/app/src/main/java/com/chiller3/bcr/settings/SettingsFragment.kt:25:1 Class 'SettingsFragment' is not abstract and does not implement abstract member public abstract fun onSharedPreferenceChanged(p0: SharedPreferences!, p1: String?): Unit defined in android.content.SharedPreferences.OnSharedPreferenceChangeListener
e: file:///C:/BCR/app/src/main/java/com/chiller3/bcr/settings/SettingsFragment.kt:202:5 'onSharedPreferenceChanged' overrides nothing

Few other apps compiled successfully, so most probably it isn't SDK issue. Something may have changed but I can't figure out what in this case.

@PatrykMis
Copy link
Contributor Author

PatrykMis commented Jul 10, 2023

According to this: https://developer.android.com/reference/kotlin/android/content/SharedPreferences.OnSharedPreferenceChangeListener

Changing the following line in both RecorderTileService.kt and SettingsFragment.kt partially fixes this.
From

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {

to

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {

But then:

e: file:///C:/BCR/app/src/main/java/com/chiller3/bcr/settings/SettingsFragment.kt:218:37 Type mismatch: inferred type is String? but String was expected

@chenxiaolong
Copy link
Owner

Thanks for starting to look into this!

I haven't tested, but it's probably because Preferences.isFormatKey(key) expects a non-null key. This should be fixable by adding a null check to the top.

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
    when {
        key == null -> return
        // ...

Regarding API 34, I'm thinking of updating in two phases, compileSdk first and then targetSdk. For targetSdk 34, there will need to be more changes due to new background service changes (which I think I know how to handle).

Also, I won't be merging any API 34-related PRs until the source code is released in AOSP. In the past, the early SDK releases have had a proprietary license. I don't know if that's still the case because I couldn't find a license file for 34, but I'd rather play it safe.

@chenxiaolong chenxiaolong self-assigned this Jul 10, 2023
@chenxiaolong chenxiaolong added the enhancement New feature or request label Jul 10, 2023
@PatrykMis
Copy link
Contributor Author

because Preferences.isFormatKey(key) expects a non-null key. This should be fixable by adding a null check to the top.

Exactly. I did that and rebased my PR. I think it can be merged because it makes the code safer and successfully compiles with previous SDKs though.

@chenxiaolong
Copy link
Owner

I think it can be merged because it makes the code safer and successfully compiles with previous SDKs though.

Agreed and merged. Thanks!

@chenxiaolong chenxiaolong reopened this Jul 10, 2023
chenxiaolong added a commit that referenced this issue Jul 10, 2023
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants