Skip to content

Kotlin Android Extensions & Butterknife are deprecated #4664

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

Closed
psh opened this issue Oct 6, 2021 · 44 comments · Fixed by #5063, #5065, #5067, #5089 or #5090
Closed

Kotlin Android Extensions & Butterknife are deprecated #4664

psh opened this issue Oct 6, 2021 · 44 comments · Fixed by #5063, #5065, #5067, #5089 or #5090

Comments

@psh
Copy link
Collaborator

psh commented Oct 6, 2021

Summary:

Looking at "The future of Kotlin Android Extensions" from 23 November 2020, (see: https://android-developers.googleblog.com/2020/11/the-future-of-kotlin-android-extensions.html)

The deprecation period starts with Kotlin 1.4.20, released today. android-kotlin-extensions will be removed in a future Kotlin release during or after September 2021. Long term, we will continue to maintain the kotlin-parcelize plugin, and you can continue to file issues on Parcelize in the Android Studio issue tracker.

According to Google (https://developer.android.com/topic/libraries/view-binding/migration)

Kotlin Android Extensions is deprecated, which means that using Kotlin synthetics for view binding is no longer supported. If your app uses Kotlin synthetics for view binding, use this guide to migrate to Jetpack view binding.

In addition, the author of Butternife has stated (https://github.com/JakeWharton/butterknife)

Attention: This tool is now deprecated. Please switch to view binding. Existing versions will continue to work, obviously, but only critical bug fixes for integration with AGP will be considered. Feature development and general bug fixes have stopped.

Would you like to work on the issue?

It looks like a pretty big migration, with a large number of files that will be touched. A search for import butterknife.BindView shows 40 files, and import kotlinx.android.synthetic a further 16 files; probably too big for a single person and something to do in stages. I would be happy to be part of the process.

@misaochan
Copy link
Member

Welcome back, @psh ! :)

Thanks for bringing this to our attention. It felt like only yesterday that we were making the switch TO Butterknife. :(

I will ping @madhurgupta10 and @ashishkumar468 for input on this, however it makes sense to me that we should start the migration. We definitely want to do it in stages, with modular PRs if possible. Will let you know when it's OK to start.

@madhurgupta10
Copy link
Collaborator

Using Jetpack ViewBinding and DataBinding seems like a good thing to do, IMO. There might be some code that still uses old findViewById methods, we need to take care of that too.

And yes, this should definitely be done in multiple PRs otherwise would be very difficult to test and merge.

This could also be a beginner-friendly task :)

@misaochan
Copy link
Member

Sounds good, thanks @madhurgupta10 . Let's do it. :) We can probably split this up by package - 1 PR for files in 1 package?

@madhurgupta10
Copy link
Collaborator

@misaochan Yes sure, even more than one PR per package would be okay IMO.

I will create a PR with the necessary dependencies and an example so it is easier for first-time contributors to follow up :)

@ThomasLatham
Copy link

ThomasLatham commented Dec 22, 2021

Hi, I'd really like to help out with this migration as my first open-source contribution. Is there a package to which I should start applying the changes outlined in @madhurgupta10's example?

I've followed the quick start guide for developers (in addition to reading the Contributing Guidelines, Developer workflow and Code Style), and Gradle has built the application successfully. Android Studio is still telling me there are errors, however, and I want to clear those up before I try writing any code, even seemingly straight-forward code like in the example provided by @madhurgupta10.

I read at the bottom of the quick start guide that I should open a new issue for trouble with setup, but I don't feel like I have enough experience to determine whether the problems I'm facing deserve their own issue. This probably isn't the right place to say all this either, but I've been stuck for a few days, and I just really want to be able to contribute.

Anyway, would somebody please be willing to help me out?

EDIT: Figured some stuff out.

@madhurgupta10
Copy link
Collaborator

@ThomasLatham Feel free to open a new issue if you need help, one or more team members will be happy to help you out :)

@ThomasLatham
Copy link

Thank you @madhurgupta10! I'll see what I can figure out on my own, but I won't hesitate to open a new issue if I get stuck

@psh
Copy link
Collaborator Author

psh commented Feb 19, 2022

https://android-developers.googleblog.com/2022/02/discontinuing-kotlin-synthetics-for-views.html?m=1

Google says -

In November 2020, we announced that this plugin has been deprecated in favor of better solutions, and we recommended removing the plugin from your projects. We know many developers still depend on this plugin’s features, and we’ve extended the support timeframe so you have more time to complete your migrations.

We are now setting a deadline for these migrations: the plugin will be removed in Kotlin 1.8, which is expected to be released by the end of 2022. At that time, you won’t be able to update your project to newer Kotlin versions if it still depends on the Kotlin Android Extensions plugin. This means that now is the time to perform the necessary migrations in your projects.

Looking at the code, there are only a few classes using synthetics left. I'll prioritize getting those done.

@bosankus
Copy link
Contributor

bosankus commented Oct 3, 2022

Hi All @psh @misaochan @madhurgupta10 @ThomasLatham @prtksxna ,
When I search import butterknife.BindView globally in Android Studio, I see multiple classes where its still being used. And out of which, I want to start working for the mentioned change at WelcomeActivity.

I have raised a PR for the same. Am I allowed to do it ?

@bosankus
Copy link
Contributor

Hi @nicolas-raoul , Can you review the above PRs kindly?

@glitched-sudhanshu
Copy link

Hi @madhurgupta10 is this issue is solved.
What I understood from all this discussion was, it needs multiple people.
So can I work into it?

@nicolas-raoul
Copy link
Member

@bosankus Sorry for the delay, I have started reviewing but not finished yet.

@glitched-sudhanshu If you find other classes that need the same, please list them here and you can start working on them 🙂

@bosankus
Copy link
Contributor

Hi @nicolas-raoul , there are other areas to cover too which am yet to push code in future for closing this ticket. Are you sure this issue can be closed now ?

@neeldoshii
Copy link
Contributor

neeldoshii commented Mar 3, 2024

Hi @nicolas-raoul , following are covered in the Above PRs (Each PR addresses 1 Package, except the last PR) :

app/src/main/java/fr/free/nrw/commons/category/CategoryDetailsActivity.java app/src/main/java/fr/free/nrw/commons/settings/SettingsActivity.java

app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java app/src/main/java/fr/free/nrw/commons/contributions/ContributionViewHolder.java

app/src/main/java/fr/free/nrw/commons/explore/ExploreListRootFragment.java app/src/main/java/fr/free/nrw/commons/explore/ExploreFragment.java app/src/main/java/fr/free/nrw/commons/explore/depictions/WikidataItemDetailsActivity.java app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java app/src/main/java/fr/free/nrw/commons/explore/ExploreMapRootFragment.java app/src/main/java/fr/free/nrw/commons/explore/recentsearches/RecentSearchesFragment.java app/src/main/java/fr/free/nrw/commons/explore/SearchActivity.java

app/src/main/java/fr/free/nrw/commons/bookmarks/pictures/BookmarkPicturesFragment.java app/src/main/java/fr/free/nrw/commons/bookmarks/BookmarkFragment.java app/src/main/java/fr/free/nrw/commons/bookmarks/BookmarkListRootFragment.java app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationsFragment.java app/src/main/java/fr/free/nrw/commons/bookmarks/items/BookmarkItemsFragment.java

app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardFragment.java app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.java

app/src/main/java/fr/free/nrw/commons/upload/license/MediaLicenseFragment.java app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java app/src/main/java/fr/free/nrw/commons/upload/UploadMediaDetailAdapter.java app/src/main/java/fr/free/nrw/commons/upload/ThumbnailsAdapter.java app/src/main/java/fr/free/nrw/commons/upload/SimilarImageDialogFragment.java app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.java app/src/main/java/fr/free/nrw/commons/upload/categories/UploadCategoriesFragment.java app/src/main/java/fr/free/nrw/commons/upload/depicts/DepictsFragment.java

Hi, sorry for not checking it. I was also working towards it, thats why I like getting assigned first to avoid collission between two contributors. Nevermind, I will close the PR will do the code review on your's PR as I have hands on at the code already.

@shashankiitbhu
Copy link
Contributor

Hi @nicolas-raoul , following are covered in the Above PRs (Each PR addresses 1 Package, except the last PR) :
app/src/main/java/fr/free/nrw/commons/category/CategoryDetailsActivity.java app/src/main/java/fr/free/nrw/commons/settings/SettingsActivity.java
app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java app/src/main/java/fr/free/nrw/commons/contributions/ContributionViewHolder.java
app/src/main/java/fr/free/nrw/commons/explore/ExploreListRootFragment.java app/src/main/java/fr/free/nrw/commons/explore/ExploreFragment.java app/src/main/java/fr/free/nrw/commons/explore/depictions/WikidataItemDetailsActivity.java app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java app/src/main/java/fr/free/nrw/commons/explore/ExploreMapRootFragment.java app/src/main/java/fr/free/nrw/commons/explore/recentsearches/RecentSearchesFragment.java app/src/main/java/fr/free/nrw/commons/explore/SearchActivity.java
app/src/main/java/fr/free/nrw/commons/bookmarks/pictures/BookmarkPicturesFragment.java app/src/main/java/fr/free/nrw/commons/bookmarks/BookmarkFragment.java app/src/main/java/fr/free/nrw/commons/bookmarks/BookmarkListRootFragment.java app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationsFragment.java app/src/main/java/fr/free/nrw/commons/bookmarks/items/BookmarkItemsFragment.java
app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardFragment.java app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.java
app/src/main/java/fr/free/nrw/commons/upload/license/MediaLicenseFragment.java app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java app/src/main/java/fr/free/nrw/commons/upload/UploadMediaDetailAdapter.java app/src/main/java/fr/free/nrw/commons/upload/ThumbnailsAdapter.java app/src/main/java/fr/free/nrw/commons/upload/SimilarImageDialogFragment.java app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.java app/src/main/java/fr/free/nrw/commons/upload/categories/UploadCategoriesFragment.java app/src/main/java/fr/free/nrw/commons/upload/depicts/DepictsFragment.java

Hi, sorry for not checking it. I was also working towards it, thats why I like getting assigned first. Nevermind, I will close the PR will do the code review on your's PR as I have hands on at the code already.

No issues, also this issue is of such nature that it can't be assigned to one person (as discussed by mentors above) and Ideal way is to contribute 1 PR per package at our pace. Our goal here is to complete this task as a team, thanks and good luck

@kanahia1
Copy link
Contributor

kanahia1 commented Mar 4, 2024

Hey @shashankiitbhu, Can I also work on it together ;)

@shashankiitbhu
Copy link
Contributor

shashankiitbhu commented Mar 4, 2024

@kanahia1 Sure, I am already working on the media package (almost done with it) so you can start on others that are left like campaigns

Also Review Package in Progress (Made some changes last time in that too so I would like to finish Review Package as well)

@shashankiitbhu
Copy link
Contributor

@kanahia1 These are still left and you can work on them if you want :

app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java
app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java
app/src/main/java/fr/free/nrw/commons/campaigns/CampaignView.java

I hope nothing is missed here 🥲

@neeldoshii
Copy link
Contributor

app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java
app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java
app/src/main/java/fr/free/nrw/commons/campaigns/CampaignView.java

Taking it up

@kanahia1
Copy link
Contributor

kanahia1 commented Mar 5, 2024

Hey @neeldoshii, are you working on them ?

@shashankiitbhu
Copy link
Contributor

@kanahia1 @neeldoshii Also If you get stuck somewhere (specially if your tests are failing) then take a look at one of my PRs (above PR for Review Package is something you can take reference from), it will save you a lot of time and trouble and do let me know if you need help somewhere

@neeldoshii
Copy link
Contributor

Hey @neeldoshii, are you working on them ?

yes.

psh pushed a commit that referenced this issue Mar 17, 2024
* Moved Main Activity and Settings Activity to ViewBinding
* Moving only SettingsActivity for now
* Removed values-yue-hant directory
* Removing previously done changes to main.xml
@psh psh closed this as completed in #5601 Mar 21, 2024
@neeldoshii
Copy link
Contributor

Hey @psh, I don't think this issue is completed. There are few packages left for this to complete this issue.
#5606 #5604

@psh psh reopened this Mar 21, 2024
@psh
Copy link
Collaborator Author

psh commented Mar 21, 2024

Thanks for the heads-up - I missed the "Fixes ____" in the PR comment.

With these long running issues, if you want to tag that it's part of the effort, it would be better to say "Relates to ____" and Github wont auto-close the associated issue!

@shashankiitbhu
Copy link
Contributor

@nicolas-raoul as this task is completed (only some OPEN PRs need to be merged) , shouldn't this be removed from the Phabricator Proposal Page?

@psh
Copy link
Collaborator Author

psh commented Mar 26, 2024

Great work on this migration effort! I did a search in the code and it turned up a couple of cleanup steps still left to do.

Looks like there is still a little migration to go (binding of views, and click listeners)

  • UploadActivity (@OnClick was missed in previous conversion)
  • NearbyParentFragment (lots of @BindView and @OnClick)

Cleanup unused butterknife imports in

  • MediaLicenseFragment
  • BookmarkLocationsFragment
  • UserDetailAdapter

Once those are done, we should be able to remove BUTTERKNIFE_VERSION from gradle properties, and butterknife itself from build.gradle (both kapt and implementation dependency)

@shashankiitbhu
Copy link
Contributor

@psh NearbyParentFragment is migrated completely in #5655

@shashankiitbhu
Copy link
Contributor

Cleanup unused butterknife imports in

  • MediaLicenseFragment
  • BookmarkLocationsFragment
  • UserDetailAdapter

Once those are done, we should be able to remove BUTTERKNIFE_VERSION from gradle properties, and butterknife itself from build.gradle (both kapt and implementation dependency)

On it , will be sharing a PR soon

@shashankiitbhu
Copy link
Contributor

@psh My PR above removes butterknife and completes migration.

@shashankiitbhu
Copy link
Contributor

@neeldoshii your PR removed unused Imports from BookmarkLocationsFragment and MediaLicenceFragment, well no worries, My PR is focused on removing other Butterknife elements, you should have confirmed first but no issues.

@shashankiitbhu
Copy link
Contributor

@psh I think #5655 have to merged first to complete this migration , can you help in reviewing that ?

@nicolas-raoul
Copy link
Member

Sorry for the delay, I merged #5655 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment