Before you switch, back up the iPhone to your computer and save every conversation with OpenExtract (free) as PDF, HTML, CSV or text files that open anywhere. Then let your new phone's setup tool bring over what it can, and turn off iMessage so new texts reach you. The archive on your computer is your safety net if the move misses anything.
Google and Samsung both offer setup tools that can copy texts from an iPhone to a new Android phone. What comes across depends on the phone, the app and the iOS version, so it's worth having your own copy that doesn't depend on any of them. This guide is about your messages and the photos in them. For contacts, call history and the rest, see Switching to Android without losing your iPhone data.
Plug the iPhone into your computer and back it up with Finder (Mac) or the Apple Devices app or iTunes (Windows). OpenExtract can also make the backup from its start screen. On Windows that still needs iTunes or the Apple Devices app installed. An encrypted backup holds more, so tick Encrypt local backup (in OpenExtract the box is called Encrypt backup) and write the password down.
In OpenExtract, open the backup. If OpenExtract made it, or you've opened it before, it's in your list. If not, choose to open a backup folder on the start screen. Open Messages, click Select, then Select all, then save them. Choose separate files and HTML for an archive you can read in any browser. Do it again with CSV if you'd like something you can search in a spreadsheet.
The HTML pages from step 2 already show the photos from each thread, and keep them, with any videos and other files, in a folder beside each page. CSV and text files only name them. Now open Photos in OpenExtract and save them all. That gets the camera roll: the photos you took or saved, not every picture someone sent you.
Use the transfer option your Android phone offers during setup. Afterwards, open the conversations that matter most to you and make sure they came across.
Before you take the SIM out, open Settings on the iPhone, go to Messages (under Apps on newer iOS) and turn off iMessage, then do the same in FaceTime. If you no longer have the iPhone, Apple has a web page where you can deregister your phone number from iMessage.
Resetting the iPhone doesn't touch the backup on your computer. Keep it, and the archive, somewhere you back up.
Can I read the archive on my Android phone? Yes. The HTML files open in any web browser, so you can copy them to the phone or a cloud folder and open them there.
Will my old iMessages show up in Google Messages? That depends on your new phone's transfer tool. OpenExtract doesn't move messages onto a phone.
Do I need to keep the iPhone afterwards? No. Once the backup is on your computer, OpenExtract needs only the backup folder, plus its password if you encrypted it.
What if I already switched? If there's still a backup of the iPhone on a computer, you can open it any time.
Does anything get uploaded? No. OpenExtract reads the backup on your own computer and doesn't send it anywhere. It goes online only when you let it: to check for a new version, if you allow it (you can turn that off in Settings); to send a problem report or a thank-you, when you click Send; and on Windows, to install Apple's free Apple Devices app from Microsoft, if you ask it to, for backing up an iPhone. Nothing from inside your backup goes with any of them.
Is it really free? Yes. OpenExtract is open source under the MIT license, with no paid tier, no account and no strings attached. The code is on GitHub.
Free and open source. Your backup stays on your computer.