qiuxiang / react-native-amap3d

react-native 高德地图组件,使用最新 3D SDK,支持 Android + iOS
https://qiuxiang.github.io/react-native-amap3d/api/
MIT License
1.27k stars 327 forks source link

How to compatible with react-native-amap-geolocation ? #778

Closed magic3584 closed 1 year ago

magic3584 commented 1 year ago

I could not found the best compatible versions, I have tested below conditions on iOS, the react native version is 0.68.2:

  1. package name version
    react-native-amap3d 3.1.3
    react-native-amap-geolocation 1.2.0

The AMap3DMap will be removed when pod install:

Removing AMap3DMap

There is no build error in rn but then comes the error when running on iOS: requireNativeComponent:"AMapView" was not found in the UIManager

  1. package name version
    react-native-amap3d 3.1.1
    react-native-amap-geolocation 1.2.0

Dependency confict when pod install:

[!] CocoaPods could not find compatible versions for pod "AMapFoundation":
  In Podfile:
    react-native-amap-geolocation (from `../node_modules/react-native-amap-geolocation`) was resolved to 1.2.0, which depends on
      AMapLocation (~> 2.9.0) was resolved to 2.9.0, which depends on
        AMapFoundation (>= 1.7.0)

    react-native-amap3d (from `../node_modules/react-native-amap3d/lib/ios`) was resolved to 3.1.1, which depends on
      AMap3DMap (~> 9.2.1) was resolved to 9.2.1, which depends on
        AMapFoundation (~> 1.6.9)
  1. package name version
    react-native-amap3d 3.1.1
    react-native-amap-geolocation 1.1.0

Crashed when running:

image
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'
*** First throw call stack:
(0x1a3235d78 0x1bbe88704 0x1a33405d0 0x1a334b6bc 0x1a31f2984 0x1a3211628 0x1014e5e48 0x101603264 0x105160c6c 0x1051627bc 0x105172c68 0x1051727a4 0x1a31ee2f0 0x1a31a81f4 0x1a31bb6b8 0x1bf23d374 0x1a5b23acc 0x1a58a5970 0x100a09618 0x104c11ce4)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/usr/lib/libMTLCapture.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'
qiuxiang commented 1 year ago

我周末把这两个的高德 sdk 都升级下应该就可以了

magic3584 commented 1 year ago

Thanks buddy 大佬辛苦

EntityGJ commented 1 year ago

Thanks author! I had the same problem.

magic3584 commented 1 year ago

Waiting to be released online... I have noticed that the version of react native has been updated too, I'm wonder whether it is still available with 0.68.2 If it's not available, could u please tell me how to update the dependencies?

qiuxiang commented 1 year ago

android 版在 RN 最新版测试通过了,但 ios 还没有测,我直接发到 npm 吧,晚点我再测 ios

magic3584 commented 1 year ago

Both packages were updated! I'm starting test on iOS right away!

qiuxiang commented 1 year ago

稍等,react-native-amap3d 还没发布成功

magic3584 commented 1 year ago

Yeah, found it🤣

qiuxiang commented 1 year ago

好了

jefn76 commented 1 year ago

刚用这个库,就赶上了最新版本,nice!!

magic3584 commented 1 year ago

Tested with react native 0.68.2 on iOS:

package name version
react-native-amap3d 3.2.0
react-native-amap-geolocation 1.2.1
Installing AMapFoundation (1.8.0)
Installing AMapLocation (2.9.0)

The AMap3DMap is still not be installed. Could u please where should I fork and how to update the dependencies? I'm going to fix it and make a PR.

jefn76 commented 1 year ago

新版本安卓跑失败了,上个版本是成功的。

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

2: Task failed with an exception.

BUILD FAILED in 24s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

2: Task failed with an exception.

qiuxiang commented 1 year ago

ios 确实已经是最新版了:https://github.com/qiuxiang/react-native-amap3d/blob/4e679950f00471a3942b34eb2d7adaadc92a0b87/react-native-amap3d.podspec#L19

qiuxiang commented 1 year ago

@magic3584 把你的错误提示再发完整点

magic3584 commented 1 year ago
使用下面版本的时候,android 是正常使用的,但是 iOS 是运行时崩溃,参照本 issue 第三种情况。 package name version
react-native-amap3d 3.1.1
react-native-amap-geolocation 1.1.0

当 pod install 的时候,完成的依赖安装如下

Installing AMap3DMap (9.2.1)
Installing AMapFoundation (1.6.9)
Installing AMapLocation (2.6.9)
Installing react-native-amap-geolocation (1.1.0)
Installing react-native-amap3d (3.1.1)

大佬刚更新过后的两个包版本如下

package name version
react-native-amap3d 3.2.0
react-native-amap-geolocation 1.2.1

此时 pod install, 完成的依赖安装如下

Installing AMapFoundation (1.8.0)
Installing AMapLocation (2.9.0)
Installing react-native-amap-geolocation (1.2.1)

与前次相比,缺少了 AMap3DMapreact-native-amap3d,相当于本仓库的包没有被安装。

magic3584 commented 1 year ago

ios 确实已经是最新版了:

https://github.com/qiuxiang/react-native-amap3d/blob/4e679950f00471a3942b34eb2d7adaadc92a0b87/react-native-amap3d.podspec#L19

https://github.com/CocoaPods/Specs/blob/master/Specs/5/f/c/AMap3DMap/9.6.0/AMap3DMap.podspec.json iOS 最新版本是 9.6.0, "~> 9.5.0"这种写法并不能匹配成功。 不过我感觉也不是这个问题,大佬也可以更新下试试

qiuxiang commented 1 year ago

发布了个新版本,再试试

qiuxiang commented 1 year ago

@jefn76 试试在 android/app/build.gradle 的 dependencies {} 里加入这段:

implementation(project(':react-native-amap-geolocation')) {
    exclude group: 'com.amap.api', module: 'location'
}
magic3584 commented 1 year ago
测试版本如下 package name version
react-native-amap3d 3.2.1
react-native-amap-geolocation 1.2.1

有新崩溃

WX20230213-203914@2x

另外大佬,iOS 如果更新最新版本依赖,需要修改以下文件内 https://github.com/qiuxiang/react-native-amap3d/blob/main/lib/ios/react-native-amap3d.podspec

s.dependency 'AMap3DMap', "~> 9.5.0"

to

s.dependency 'AMap3DMap', "~> 9.6.0"

magic3584 commented 1 year ago

升级 AMap3DMap 到 9.6.0 后,还是同一个方法崩溃。我需要学一下 rn 怎么封装原生组件。

qiuxiang commented 1 year ago

我等下用 xcode 看下

magic3584 commented 1 year ago
image

也许可能是我们的问题?明天我得看下代码是怎么写的,打印的也没有 MapView

qiuxiang commented 1 year ago

我试了 example 是没有问题的

qiuxiang commented 1 year ago

明天再试试新建的项目

jefn76 commented 1 year ago

@jefn76 试试在 android/app/build.gradle 的 dependencies {} 里加入这段:

implementation(project(':react-native-amap-geolocation')) {
    exclude group: 'com.amap.api', module: 'location'
}

谢谢大佬,跑成功了!

magic3584 commented 1 year ago

我试了 example 是没有问题的

大佬请问 example 怎么跑起来?没找到 iOS 的 project

qiuxiang commented 1 year ago

在外面 react-native init example,然后把 example/ios 复制到 这个项目里来,然后在这个项目正常的 pos install,react-native run-ios

jefn76 commented 1 year ago

报错了,首先是react-native run-ios的时候,报了警告:Package react-native-amap3d contains invalid configuration: "dependency.platforms.ios.project" is not allowed. Please verify it's properly linked using "react-native config" command and contact the package maintainers about this. 然后调用AMapSdk.init()后,app报错: ERROR TypeError: Cannot read property 'initSDK' of null

This error is located at: in App in RCTView (created by View) in View (created by AppContainer) in RCTView (created by View) in View (created by AppContainer) in AppContainer in AwesomeProject(RootComponent), js engine: hermes

打开Pods文件夹,发现并没有link到:

SCR-20230214-dkv
qiuxiang commented 1 year ago

我还是先改回之前的结构。@jefn76 发了新版本,再试试

jefn76 commented 1 year ago

我还是先改回之前的结构。@jefn76 发了新版本,再试试

成功了,完美!

magic3584 commented 1 year ago

在外面 react-native init example,然后把 example/ios 复制到 这个项目里来,然后在这个项目正常的 pos install,react-native run-ios

不行啊, nom run iOS 报错如下 image

EntityGJ commented 1 year ago

还是之前同样的问题

image

下载的依赖关系

image

package.json里面的版本

image
qiuxiang commented 1 year ago

在外面 react-native init example,然后把 example/ios 复制到 这个项目里来,然后在这个项目正常的 pos install,react-native run-ios

不行啊 image

这已经和 ios 项目没关系了,这是 js bundle 错误

qiuxiang commented 1 year ago

不对,是原生的错,你先试试提示的操作,重新 pod install,yarn start --reset-cache

magic3584 commented 1 year ago

不对,是原生的错,你先试试提示的操作,重新 pod install,yarn start --reset-cache

可以了,我的错,如下修改就可以了。 image

接下来用最新版本的库去看我们项目的代码了,所以可能还是我们的代码有问题,但是相同代码 android 可以跑 emmm 我再研究研究,辛苦大佬~

qiuxiang commented 1 year ago

RN 项目和原生耦合太深了,为了排除原生项目配置的问题,我干脆把 example 的原生项目都移除了,构建的时候再 react-native init 一个新的。我只能保证在新项目里能跑起来,其他项目跑不起来大概就是配置问题。

build action 可以作为参考: https://github.com/qiuxiang/react-native-amap3d/blob/f50289bfd0fbb066b46dbfb9563452696a3b2f02/.github/workflows/build.yml#L8-L19

magic3584 commented 1 year ago

但是大佬,本 issue 的问题仍然存在,依赖如下时,仍然无法导入地图的库

image

Installing AMapFoundation (1.8.0) Installing AMapLocation (2.9.0) Installing react-native-amap-geolocation (1.2.1)

magic3584 commented 1 year ago

请教这个 action 如何执行?

qiuxiang commented 1 year ago

这个 action 只测了 android

qiuxiang commented 1 year ago

准备写下 ios 的 action,可以 fork 下来,自己改,提交了就会运行

magic3584 commented 1 year ago

大佬这两个库的兼容问题还会去查吗?这俩库一般都搭配使用的吧

qiuxiang commented 1 year ago

我只能晚上回去再看,公司没有 mac

qiuxiang commented 1 year ago

现在写下 ios 的 action,估计也能看出一些问题

qiuxiang commented 1 year ago

@magic3584 看起来是没有问题的

https://github.com/qiuxiang/react-native-amap3d/actions/runs/4170573648/jobs/7219670017

image

而且上面 @jefn76 也反馈没问题了

magic3584 commented 1 year ago
针对两个版本的 react native 0.68.20.71.2,分别创建新项目使用相同版本的两个库 package name version
react-native-amap3d 3.2.3
react-native-amap-geolocation 1.2.1

测试结果如下:

  1. 0.68.2

Installing AMapFoundation (1.8.0) Installing AMapLocation (2.9.0) Installing react-native-amap-geolocation (1.2.1)

仍然缺少地图库

  1. 0.71.2

Installing AMap3DMap (9.6.0) Installing AMapFoundation (1.8.0) Installing AMapLocation (2.9.0) Installing react-native-amap-geolocation (1.2.1) Installing react-native-amap3d (3.2.3)

可以正常安装两个库。

不确定是否是本仓库以前的包所依赖的 RN 版本导致的。 还需要再进一步去验证

qiuxiang commented 1 year ago

看起来是 RN 升级过后查找原生依赖的策略发生了一些变化,这种事也发生过,现在主要受 react-native.config.js 影响,还有一些隐含的策略,为此我看过,调试过 RN 这部分的源码。但现在过去了这么久,以至于我都忘了为什么要写两个 podspec 才能让 RN 查找到依赖。

https://github.com/qiuxiang/react-native-amap3d/blob/main/react-native-amap3d.podspec https://github.com/qiuxiang/react-native-amap3d/blob/main/lib/ios/react-native-amap3d.podspec

qiuxiang commented 1 year ago

react-native-amap-geolocation 这个项目没有问题是因为 xcodeproj 的存在,这就是其中隐含的查找策略

https://github.com/qiuxiang/react-native-amap-geolocation/tree/main/lib/ios/AMapGeolocation.xcodeproj

我现在懒得深究这个问题了,就只保证能兼容最新的 RN

magic3584 commented 1 year ago

好的大佬,感谢您及时跟进解决,我再研究研究。如果您以后再看到相关文档解释,烦请再在这里贴一下