Add support for AndroidX
Describe the bug
Task :@react-native-mapbox-gl_maps:compileDebugJavaWithJavac FAILED /home/sublime/Desktop/mahendra/react projects/passengerapp/node_modules/@react-native-mapbox-gl/maps/android/rctmgl/src/main/java/com/mapbox/rctmgl/events/LocationEvent.java:4: error: package android.support.annotation does not exist import android.support.annotation.NonNull;
Execution failed for task ':@react-native-mapbox-gl_maps:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
I'm getting this error on react-native run-android command run. I have migrated my project android to androidx.
Screenshots


Versions (please complete the following information):
- Platfrom: Android
- Device: moto
- SDK Version 28
- React Native Version 0.59
@mfazekas we'll need to handle AndroidX as it is coming with RN60. We're still in rc stage, so what do you think about adding this as a breaking change and then move forward with an official release at 7.0.0 with AndroidX support?
Alternatively we could release 7.0.0 and then increment to 8.0.0 for AndroidX.
Here is google's recommendation about migration. This is for flutter, but it still applies to us.
@kristfal I'm not sure the exact changes required for AndroidX. Not sure if it means, but likely it'll mean that mapbox will be RN60+ only.
I'd vote to try to release 7.0 ASAP, and then do the AndroidX in 8.0.
@mfazekas @kristfal I want to use mapbox in 0.59 can you guys assist me what can do to use mapbox in 0.59 version
we're working with androidx rctmgl edit, it's rather quick process, basically only changing few imports in rctmgl like
import android.support.annotation.NonNull => import androidx.annotation.NonNull
import android.support.annotation.Nullable => import androidx.annotation.Nullable
import android.support.v4.content.res.ResourcesCompat => import androidx.core.content.res.ResourcesCompat
https://developer.android.com/jetpack/androidx/migrate provides a good mapping list. other then that, things seem to work fine sofar, can make a PR if it helps
i'd vote - if possible - support androidx via jetifier npm at first. See https://github.com/mikehardy/jetifier#to-jetify--convert-node_modules-dependencies-to-androidx
As i understand this is pretty much a one way street. Once we upgrade to androidx users will be forced to upgrade to androidx project, and they might have androidx problematic dependencies.
Yes, that would be a good approach. Suggest we do the following:
- Release 7.0.0 make sure we support jetifier and document this properly in the readme
- (Potentially) migrate the example app to AndroidX and use it as a poc/example/test for the jetifier
- In a few weeks/months increment to 8.0.0 and switch to AndroidX in the main lib
Thoughts?
@kristfal i agree
As of today, using react-native init now uses RN v.0.60 and android no longer builds with this library. I think it should be in the readme that v0.60 is not supported yet.
Yes, that would be a good approach. Suggest we do the following:
- Release 7.0.0 make sure we support jetifier and document this properly in the readme
- (Potentially) migrate the example app to AndroidX and use it as a poc/example/test for the jetifier
- In a few weeks/months increment to 8.0.0 and switch to AndroidX in the main lib
Thoughts?
Just checking if this suggested solution is in v 7.0.0-rc3 ?
Thanks
@ako977 yes please try https://www.npmjs.com/package/jetifier with react native mapbox and report any issue so we can fix them.
@mfazekas @kristfal
Since I was unable to make this framework work when upgrading my RN project to 0.60.0, I tried creating a test project with RN 0.60.0 and v7.0.0-rc3.
Here is what I did:
react-native init androidxtest --template typescript
yarn add @react-native-mapbox-gl/maps
-
iOS ran fine without further config, Android didn't.
-
Then I followed the Android installation guide
Got this warning when starting Metro Bundler: Loading dependency graph...warn The following packages use deprecated "rnpm" config that will stop working from next release:
@react-native-mapbox-gl/maps: https://npmjs.com/package/@react-native-mapbox-gl/maps
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
- And this error when running Android: error.txt
Extract from file:
Required by:
project :@react-native-mapbox-gl_maps
> Cannot find a version of 'androidx.vectordrawable:vectordrawable' that satisfies the version constraints:
Dependency path 'androidxtest:@react-native-mapbox-gl_maps:unspecified' --> 'com.android.support:support-vector-drawable:28.0.0' because of the following reason: ENABLE_JETIFIER is enabled
Constraint path 'androidxtest:@react-native-mapbox-gl_maps:unspecified' --> 'androidx.vectordrawable:vectordrawable:{strictly 1.0.0}' because of the following reason: debugRuntimeClasspath uses version 1.0.0
Dependency path 'androidxtest:@react-native-mapbox-gl_maps:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.vectordrawable:vectordrawable:1.0.1'
Dependency path 'androidxtest:@react-native-mapbox-gl_maps:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.vectordrawable:vectordrawable-animated:1.0.0' --> 'androidx.vectordrawable:vectordrawable:1.0.0'
> Could not resolve com.android.support:appcompat-v7:28.0.0.
Required by:
project :@react-native-mapbox-gl_maps
> Cannot find a version of 'androidx.appcompat:appcompat' that satisfies the version constraints:
Dependency path 'androidxtest:@react-native-mapbox-gl_maps:unspecified' --> 'com.android.support:appcompat-v7:28.0.0' because of the following reason: ENABLE_JETIFIER is enabled
Constraint path 'androidxtest:@react-native-mapbox-gl_maps:unspecified' --> 'androidx.appcompat:appcompat:{strictly 1.0.0}' because of the following reason: debugRuntimeClasspath uses version 1.0.0
Dependency path 'androidxtest:@react-native-mapbox-gl_maps:unspecified' --> 'com.facebook.react:react-native:0.60.0' --> 'androidx.appcompat:appcompat:1.0.2'
Dependency path 'androidxtest:@react-native-mapbox-gl_maps:unspecified' --> 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v7:0.9.0' --> 'androidx.appcompat:appcompat:1.0.0'
Dependency path 'androidxtest:@react-native-mapbox-gl_maps:unspecified' --> 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v7:0.2.0' --> 'androidx.appcompat:appcompat:1.0.0'
- Then I tried installing and running
jetifierto try and fix theandroidximport issue:
yarn add -D jetifier
npx jetify
And ran Android again, but the error is the same.
So it seems that there is no support for RN 0.60.0 at the moment even with jetifier
@anfriis Did you run jetifier like they said here (Step 3, npx jetify) ?
@Darkilen Yes, apparently I forgot to add it here. Just updated my post
Is there any solution to this? Even as a workaround?
Okay I made a PR that should make things work, but like I say over there, I'm not very experienced with Java/Gradle so I'm not sure if it's the correct solution. For me, the following changes to my package.json file make things work as expected:
"scripts": {
"postinstall": "jetify"
},
"dependencies": {
"@react-native-mapbox-gl/maps": "jshearer/maps",
"jetifier": "^1.6.2"
}
Then just run yarn.
@jshearer any news on this issue?
Since React native must be updated to version 0.60 before August, I hope this will be solved.
@ako977 yes please try https://www.npmjs.com/package/jetifier with react native mapbox and report any issue so we can fix them.
@mfazekas Just following up that postinstall jetify worked for 7.0.0-rc3
@sublimedatasystem @ako977 @mfazekas Hello guys, I have tried the methods using jetifier and adjusted the package.json but still receiving the 'Execution failed for task ':@react-native-mapbox-gl_maps:compileDebugJavaWithJavac'.' issue. Can you list out the steps used to fix this issue or has it not been resolved? Thanks in advance.
@DavidKHahn Try using @jshearer branch. It works for me, we need to wait for merge and release for now ;)
@dsznajder thanks for the quick response. I'll give it a try! :)