iPhone X won’t charge if the ear speaker is connected

I got an iPhone X, but it wasn’t charging. I installed a new battery, a new dock connector and a new screen (as the previous one had a crack). It still wasn’t charging, but after some more troubleshooting I figured out that if I disconnect the ear speaker, it will start charging fine. I can’t find any information on this kind of defect anywhere, and I don’t know what to do other than maybe get a new ear speaker. Does anyone have some insight on this?

Edit: I started messing around with it, and was able to find an inellegant solution. After cutting off the ambient light sensor and the little circuits that led up to it, I was able to get it to charge with no problems. The rest of the ear speaker parts work. Replacing the ear speaker would probably solve the problem and give me a working ambient light sensor, but I’m good with this.

crwdns2934089:0crwdne2934089:0 crwdns2934093:0crwdne2934093:0

crwdns2934109:0crwdne2934109:0

crwdns2889612:0crwdne2889612:0 0

crwdns2947414:01crwdne2947414:0:

I was able to fix my problem, however inellegantly. I updated my question to include the fix.

crwdns2934271:0crwdnd2934271:0crwdne2934271:0

crwdns2934285:0crwdne2934285:0