Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

"import android.support.v4.widget.*" will orphan classes such as DrawerLayout #23

Closed
spbond opened this issue Jun 29, 2019 · 6 comments
Closed

Comments

@spbond
Copy link

spbond commented Jun 29, 2019

I wanted to alert you to an area where your library may be able to be improved. I used your library on a react-native package, and was receiving a build error about not being able to resolve DrawerLayout. After investigating, I discovered that the library prefix was changed from android.support.v4.widget to androidx.drawerLayout.widget. The import statement imported android.support.v4.widget.* which got translated to androidx.core.widget. I noticed that there were several other widgets that also had their prefix changed to something other than core. If it is possible to check the file for the use of these outliers and add the correct imports, then it could prevent other users from facing the same issue.

@mikehardy
Copy link
Owner

Hmm - that’s very interesting. Thanks for taking the time to report it.

I wonder if they originally went to androidx.core then moved somewhere else? We are using the standard mapping file from google (you can verify the checksum even…) so theoretically it should be sufficient but theory and practice are different.

I’ll check into this, but for independent verification if you could check the ancestry on the androidx.core.widget and where they should have gone and if that has changed over time, it would be useful.

We already do a “custom” mapping for renderscript libraries, so it’s definitely possible for us to alter the standard mappings where necessary

Also, if you have a module you could specify for testing, we can include it in https://github.com/mikehardy/rn-androidx-demo/blob/master/make-demo.sh - then we’ll be able to reproduce and also know it is fixed and stays fixed, it’s the test suite for jetifier

@mikehardy
Copy link
Owner

https://github.com/mikehardy/jetifier/blob/master/src/androidx-class-mapping.csv#L1622 ?

I definitely need a reproduction library for this - I don’t see how it would happen, but I’m frequently surprised!

@spbond
Copy link
Author

spbond commented Jul 1, 2019

The library I had problems with is react-native-navigation, SideMenu.java:6.

I am guessing that the problem is in the * in the import statement. Since there is no way to tell from just the import statement which modules are being imported, maybe it is just converting it to andoidx.core.widget as a default? I didn't see any conversions for prefixes with an *, though, so I don't know where that would be coming from. I did run a migration in android studio after your tool, so maybe that did the actual replacement for that line. I didn't think it touched that library, though. Regardless, it would still be desirable for your plugin to handle these situations.

@mikehardy
Copy link
Owner

Interesting - I don’t think we can handle full package imports. I’m guessing AndroidStudio got it for you since it has knowledge at the abstract syntax tree level of which objects are in use. You should open a PR with that repo to replace the * with concrete imports, in the meantime I’ll look into it as a generic issue because I think you’re right - I don’t think we handle that. Good sleuthing

@mikehardy
Copy link
Owner

…also, if you used patch-package to simply replace the * with concrete imports in your installation of react-native-navigation jetifier should work and it would be durable for all installs of your code base, in the meantime

@mikehardy
Copy link
Owner

wix/react-native-navigation#5218 ! They changed it

If you try master, it should work? I'm not sure what react-native-navigation you are on. Either way, this will be an upstream issue, I will close this as we can't migrate these but it's a legitimate problem and I'll put it in the troubleshooting section

Thanks for providing the reproduction

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants