chenxiaolong / BCR

A Basic Call Recorder for rooted Android devices
GNU General Public License v3.0
1.76k stars 113 forks source link

Prepare for SDK 34 #376

Closed PatrykMis closed 1 year ago

PatrykMis commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.

PatrykMis commented 1 year ago

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 commented 1 year ago

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

Agreed and merged. Thanks!