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

deprecation: compileSdk 33 issues #12364

Closed
13 of 14 tasks
david-allison opened this issue Sep 10, 2022 · 54 comments · Fixed by #15734
Closed
13 of 14 tasks

deprecation: compileSdk 33 issues #12364

david-allison opened this issue Sep 10, 2022 · 54 comments · Fixed by #15734
Labels
Deprecation Warnings on deprecated API usage Good First Issue! Help Wanted Requesting Pull Requests from volunteers
Milestone

Comments

@david-allison
Copy link
Member

david-allison commented Sep 10, 2022

Hi there! Thanks for picking up a deprecation task - we think these are good first issues because:

1- typically you can just search the codebase for a relevant string and find where the work is quickly
2- typically there is documentation upstream in the Google Android Developer docs that explain how the old API worked, why it is deprecated, and then there is documentation for the new API
3- the functionality is already working, switching to a new implementation has a clear standard to meet, it should be obvious the change was good (because the feature was working, and should just still be working

These are the collection of interfaces deprecated as we switched compileSdkVersion from 32 to 33:

  • Activity.onBackPressed
  • Intent.getParcelableExtra
  • Bundle.getSerializable
  • Intent.getSerializable
  • Parcel.readSparseArray
  • Parcel.readSerializable
  • Parcel.readList
  • Bundle.getParcelableArrayList
  • Bundle.get (array access: `b["key"]``)
  • Bundle.getParcelable
  • PackageManager.resolveActivity
  • PackageManager.getPackageInfo
  • PackageManager.queryIntentActivities
  • PackageManager.resolveService

The task is to:

  • pick one no one else has commented on here, write a comment here that you are working on that one
  • search for the second part of the string (for example "onBackPressed")
  • verify that it has a @Suppress("deprecation") near it signaling that you found the spot!
  • Add a Timber.d in the area to make sure you can exercise the feature on the emulator before changing it (you should see your log message)
  • read the docs on the deprecated API and the new API, and convert the code to the new API
  • make sure ./gradlew jacocoTestReport ktlintCheck passes on your work locally, and that the feature still works
  • open a PR with your changes

Ask if you have any questions!

Originally posted by @david-allison in #12359 (comment)

@david-allison david-allison added the Deprecation Warnings on deprecated API usage label Sep 10, 2022
@mikehardy mikehardy added Help Wanted Requesting Pull Requests from volunteers Good First Issue! labels Sep 10, 2022
@priyanshuborole
Copy link

priyanshuborole commented Sep 11, 2022

@david-allison I would like to work on Activity.onBackPressed deprecation.
Edit - If anyone wants to work on this you can. I am not working on it currently

@mikehardy
Copy link
Member

@priyanshuborole great - unless someone has said they are working on something - no need to ask permission, just state (with authority! go for it!) that you are working on such and such. Good luck, and thanks

@criticalAY
Copy link
Contributor

@david-allison I was working on Intent.getParcelableExtra but when I am trying to update the method it gives an error and not recognizing the API level 33 intent removing the @Supress also throws an error while building up the application.

@david-allison
Copy link
Member Author

david-allison commented Sep 14, 2022

@criticalAY
Copy link
Contributor

read the docs on the deprecated API and the new API, and convert the code to the new API

Look up the method: getParcelableExtra: https://developer.android.com/reference/android/content/Intent#getParcelableExtra(java.lang.String)

https://developer.android.com/reference/android/content/Intent#getParcelableExtra(java.lang.String,%20java.lang.Class%3CT%3E) is recommended instead.

I found https://stackoverflow.com/questions/73019160/android-getparcelableextra-deprecated/73311814#73311814 which explains the usability of getPracelableExtra in API >=33

@svitlana-shumilova
Copy link

@david-allison Working on Parcel.readSparseArray

@sumanbmondal
Copy link

Hey, I was working on Bundle.getParcelable.
The method in API level 33 is
public T getParcelable (String key, Class<T> clazz)

I'm not sure which class should be mentioned here
mPreviousImageUri = savedInstanceState.getParcelable("mPreviousImageUri")
Is it Uri::class.java ?

Also if I add a class, it says Call requires API level 33, should I surround it with if (Build.VERSION.SDK_INT >= 33) ?

@david-allison
Copy link
Member Author

david-allison commented Sep 15, 2022

It's a Uri:

See our compat infrastructure for how to handle this. There's already a thread on Discord where I've walked someone through this

@criticalAY criticalAY mentioned this issue Sep 15, 2022
5 tasks
@david-allison
Copy link
Member Author

#12410 adds this infra, and should be a good starting point

@criticalAY
Copy link
Contributor

criticalAY commented Sep 16, 2022

@david-allison I would like to work on Activity.onBackPressed deprecation.

Hey! are you still working on it?

@priyanshuborole
Copy link

priyanshuborole commented Sep 16, 2022

@david-allison I would like to work on Activity.onBackPressed deprecation.

Hey! are you still working on it?

Yes I am working on it, give me 1-2 days if not possible I will update you

@criticalAY
Copy link
Contributor

Hey, I was working on Bundle.getParcelable. The method in API level 33 is public T getParcelable (String key, Class<T> clazz)

I'm not sure which class should be mentioned here mPreviousImageUri = savedInstanceState.getParcelable("mPreviousImageUri") Is it Uri::class.java ?

Also if I add a class, it says Call requires API level 33, should I surround it with if (Build.VERSION.SDK_INT >= 33) ?

Hey! Are you working on it? coz if not then I would like to overtake it.

@svitlana-shumilova
Copy link

I'm working on Parcel.readSparseArray and there is only one place it occurs, which is com/ichi2/anki/FieldEditLine.kt:249
But it looks like it's never used in the project and I can't find a way to test it. What am I supposed to do?

@n1snt
Copy link
Contributor

n1snt commented Sep 18, 2022

Is anyone working on PackageManager depreciated interfaces?
If not I would love to work on it.

@criticalAY
Copy link
Contributor

Is anyone working on PackageManager depreciated interfaces? If not I would love to work on it.

I don't think anyone is

@sumanbmondal
Copy link

Hey! Are you working on it? coz if not then I would like to overtake it.

I'm not able to figure out a few things. So sure go ahead. I'll just watch and learn 😂

@criticalAY
Copy link
Contributor

Hey! Are you working on it? coz if not then I would like to overtake it.

I'm not able to figure out a few things. So sure go ahead. I'll just watch and learn 😂

Sure, Thanks!

@priyanshuborole
Copy link

Hey, I was working on Bundle.getParcelable. The method in API level 33 is public T getParcelable (String key, Class<T> clazz)
I'm not sure which class should be mentioned here mPreviousImageUri = savedInstanceState.getParcelable("mPreviousImageUri") Is it Uri::class.java ?
Also if I add a class, it says Call requires API level 33, should I surround it with if (Build.VERSION.SDK_INT >= 33) ?

Hey! Are you working on it? coz if not then I would like to overtake it.

yes, you can start working on it.

@criticalAY
Copy link
Contributor

criticalAY commented Sep 19, 2022

Could you please review the last PR so that I can move on to the other one? Like whenever you are good to go. Thanks!

@mikehardy
Copy link
Member

@criticalAY if you examine the volume of work in flight at any time (https://github.com/ankidroid/Anki-Android/pulse) you'll see you have to have some patience, especially since we are essentially all volunteers. Sometimes things are very very fast, sometimes they sit, it is not predictable. However, if you feel you have that PR under control, you can take on another one - that's fine. I would only caution against having too many PRs in flight at once, but that would be like 5-6 - at that point it is usually a sign that things are not really being answered satisfactorily for some reason or they would be getting merged. In this case I think we're close, go ahead on something new if you like, while reviewers catch up. Cheers!

@criticalAY
Copy link
Contributor

Yes, I do understand but if I make another PR that would make a conflict I guess. One thing that I am learning from open source contributions is how to be patient and I would love to wait as I am enjoying working with you all <3

@mikehardy
Copy link
Member

I believe the various SDK33 deprecations will not conflict with each other, each of them should be in different chunks of text which git should ideally be able to handle just fine on merge. Even if not, handling conflicts via git rebase / fixing conflicts / force push to your branch is one of the most powerful things you can learn as a modern software developer (where "modern" is defined as "we are all using git now"). Once you've got git rebase-merge/de-conflict/force-push down, there is almost nothing out of reach with regards to managing a source code repository and that's a powerful professional skill. So don't fear conflicts, in my opinion

@criticalAY criticalAY mentioned this issue Sep 20, 2022
5 tasks
@criticalAY
Copy link
Contributor

criticalAY commented Sep 21, 2022

API 33 serializable bundle deprecation update #12463 for Bundle.getSerializable

@sakxshi

This comment was marked as resolved.

@david-allison

This comment was marked as resolved.

@sakxshi

This comment was marked as resolved.

@david-allison
Copy link
Member Author

Additional info on onBackPressed from #13323

OnBackPressed Override Function is deprecated in Android 13 Android 13 has a new feature called Predictive Back Gesture which shows users that they are about to navigate back to the launcher from the application with back action.

Here is the warning that android studio will give on using onBackPressed on Android API level 33+

image

Here is how you can replace onBackPressed in the code -


onBackPressedDispatcher.addCallback(this /* lifecycle owner */, object : OnBackPressedCallback(true) {
    override fun handleOnBackPressed() {
        // Back is pressed... Finishing the activity
        finish()
    }
})

// ====================================================
/* Or for lambda simplicity: */
// ====================================================
onBackPressedDispatcher.addCallback(this /* lifecycle owner */) {
    // Back is pressed... Finishing the activity
    finish()
}```

@niryline
Copy link

Hey! I'm new here but would like to contribute. Can I try to work on onBackPressed() ?

@mikehardy
Copy link
Member

@niryline that sounds great! Good luck

@MudssirAhmed
Copy link

Hey @mikehardy, I migrated the deprecated code, But I'm getting some errors when I'm going to push the code and make a PR.
Can you help me to figure it out?

Here is the error code
`PS D:\Development\Open-Source\Anki-Android> git add .
PS D:\Development\Open-Source\Anki-Android> git commit -m "Deprication OnBackPressed handled"
Running ktlint over these files:
AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt
AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateBrowserAppearanceEditor.kt
AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt
AnkiDroid/src/main/java/com/ichi2/anki/CardTemplatePreviewer.kt
AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
AnkiDroid/src/main/java/com/ichi2/anki/Info.kt
AnkiDroid/src/main/java/com/ichi2/anki/ModelBrowser.kt
AnkiDroid/src/main/java/com/ichi2/anki/ModelFieldEditor.kt
AnkiDroid/src/main/java/com/ichi2/anki/NavigationDrawerActivity.kt
AnkiDroid/src/main/java/com/ichi2/anki/StudyOptionsActivity.kt
AnkiDroid/src/main/java/com/ichi2/anki/preferences/Preferences.kt
AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt

FAILURE: Build failed with an exception.

  • What went wrong:
    Unable to start the daemon process.
    This problem might be caused by incorrect configuration of the daemon.
    For example, an unrecognized jvm option is used.
    Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/8.0.2/userguide/gradle_daemon.html
    Process command line: C:\Program Files (x86)\Java\jre1.8.0_361\bin\java.exe -Xmx2560M -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -cp C:\Users\mudss.gradle\wrapper\dists\gradle-8.0.2-bin\25jlreiuz6u3xu2phlpa2vv4m\gradle-8.0.2\lib\gradle-launcher-8.0.2.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.0.2
    Please read the following process output to find out more:

Error occurred during initialization of VM
Could not reserve enough space for 2621440KB object heap

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

@mikehardy
Copy link
Member

@MudssirAhmed we use JDK11 normally for development. I would make sure that's the JDK in use. Looks like you attempted to use 8.

@MudssirAhmed
Copy link

MudssirAhmed commented Apr 9, 2023

@mikehardy thanks for the comment, I created a PR for onBackPress depreciation handle. PR
Kindly review this PR.

@niryline
Copy link

Oh @MudssirAhmed I was working on this... I guess I was too slow.

KendallPark pushed a commit to KendallPark/Anki-Android that referenced this issue May 30, 2023
Deprecated in API 33

https://developer.android.com/reference/android/content/pm/PackageManager#getPackageInfo(java.lang.String,%20int)

`PackageManagerCompat` was created because:

* PackageInfoFlags is introduced in API 33 and is the API replacement
  * Unusable before API 33
* parameters: `flags: Integer` is replaced with `flags: PackageInfoFlags`
* `PackageInfoFlags` is given `PackageInfoFlagsBits` which handles
  invalid values
  * PackageInfoFlagsBits depends on constants which are not defined in API 21

Closes ankidroid#12548 (superseded)
Related ankidroid#12364
@github-actions
Copy link
Contributor

github-actions bot commented Jul 9, 2023

Hello 👋, this issue has been opened for more than 3 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Jul 9, 2023
@BrayanDSO BrayanDSO added Keep Open avoids the stale bot and removed Stale labels Jul 9, 2023
@dae
Copy link
Contributor

dae commented Sep 1, 2023

@david-allison there's a pending PR for the last remaining issue - should we ask them to update it?

@mikehardy
Copy link
Member

onBackPressed is the only remaining one, and we're going to track it in #14558

@david-allison david-allison removed the Keep Open avoids the stale bot label Nov 3, 2023
@github-actions github-actions bot added this to the 2.18 release milestone Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecation Warnings on deprecated API usage Good First Issue! Help Wanted Requesting Pull Requests from volunteers
Projects
None yet
Development

Successfully merging a pull request may close this issue.