maps icon indicating copy to clipboard operation
maps copied to clipboard

Add support for AndroidX

Open sublimedatasystem opened this issue 7 years ago • 29 comments

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 image

image

Versions (please complete the following information):

  • Platfrom: Android
  • Device: moto
  • SDK Version 28
  • React Native Version 0.59

sublimedatasystem avatar Jun 24 '19 13:06 sublimedatasystem

@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 avatar Jun 25 '19 12:06 kristfal

@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 avatar Jun 25 '19 14:06 mfazekas

@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

sublimedatasystem avatar Jun 26 '19 04:06 sublimedatasystem

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

wirrareka avatar Jun 26 '19 10:06 wirrareka

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.

mfazekas avatar Jun 26 '19 11:06 mfazekas

Yes, that would be a good approach. Suggest we do the following:

  1. Release 7.0.0 make sure we support jetifier and document this properly in the readme
  2. (Potentially) migrate the example app to AndroidX and use it as a poc/example/test for the jetifier
  3. In a few weeks/months increment to 8.0.0 and switch to AndroidX in the main lib

Thoughts?

kristfal avatar Jun 26 '19 17:06 kristfal

@kristfal i agree

mfazekas avatar Jun 26 '19 19:06 mfazekas

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.

d3vhound avatar Jul 03 '19 20:07 d3vhound

Yes, that would be a good approach. Suggest we do the following:

  1. Release 7.0.0 make sure we support jetifier and document this properly in the readme
  2. (Potentially) migrate the example app to AndroidX and use it as a poc/example/test for the jetifier
  3. 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 avatar Jul 09 '19 15:07 ako977

@ako977 yes please try https://www.npmjs.com/package/jetifier with react native mapbox and report any issue so we can fix them.

mfazekas avatar Jul 09 '19 16:07 mfazekas

@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

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 jetifier to try and fix the androidx import 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 avatar Jul 10 '19 12:07 anfriis

@anfriis Did you run jetifier like they said here (Step 3, npx jetify) ?

Darkilen avatar Jul 10 '19 13:07 Darkilen

@Darkilen Yes, apparently I forgot to add it here. Just updated my post

anfriis avatar Jul 10 '19 13:07 anfriis

Is there any solution to this? Even as a workaround?

jshearer avatar Jul 12 '19 00:07 jshearer

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 avatar Jul 12 '19 01:07 jshearer

@jshearer any news on this issue?

Since React native must be updated to version 0.60 before August, I hope this will be solved.

Friis1978 avatar Jul 14 '19 17:07 Friis1978

@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

ako977 avatar Jul 15 '19 01:07 ako977

@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 avatar Jul 15 '19 18:07 DavidKHahn

@DavidKHahn Try using @jshearer branch. It works for me, we need to wait for merge and release for now ;)

ice-chillios avatar Jul 15 '19 18:07 ice-chillios

@dsznajder thanks for the quick response. I'll give it a try! :)

DavidKHahn avatar Jul 15 '19 18:07 DavidKHahn