【安卓】ReactNative 集成 react-native-baidumap-sdk,android Kotlin编译报错
问题描述
RN项目,集成 react-native-baidumap-sdk
报错,(同时在ios 做了集成,没有问题。)
由于从前端转做RN开发,不懂Android
也不懂 Kotlin
,这问题在 google
搜了很久都没找到答案,我现在完全是懵逼状态。。完全不知道从何处下手排查这个问题。
如果还需要其他相关信息 我随时可以提供。
错误如下:
> Configure project :react-native-baidumap-sdkWARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
> Configure project :react-native-webview
:react-native-webview:reactNativeAndroidRoot /project/node_modules/react-native/android
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/Utils.kt: (52, 35): T
ype inference failed. Expected type mismatch: inferred type is List<LatLng?> but List<LatLng> was expected
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapHeatMap.kt: (20, 43): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapHeatMap.kt: (20, 67): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapHeatMap.kt: (21, 38): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (156, 19): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (157, 43): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (157, 60): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (160, 19): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (161, 41): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (164, 19): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (165, 45): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (168, 19): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (169, 43): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (172, 19): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (173, 31): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (173, 47): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
e: /project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapView.kt: (177, 13): Type mismatch: inferred type is Boolean? but Boolean was expected
> Task :react-native-baidumap-sdk:compileDebugKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-baidumap-sdk:compileDebugKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
/project/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/Utils.kt: (52, 35)
/Users/dizhang/Workspace/rn/ReactNativeBaseFramework/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/mapview/BaiduMapHeatMap.kt: (20, 43)
其中两个文件是这样的。其他都差不多。
环境
system:macos 10.14
"react": "16.8.3","react-native": "0.59.5",
"react-native-baidumap-sdk": "^0.6.1-2",
build.gradle
buildscript {ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
kotlin_version = "1.3.10"
}
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
回答
我这里检测发现是 Kotlin
语法的问题,
解决方法:在报错文件的对应参数后加两个感叹号
我这里是3个文件,分别是: BaiduMapHeatMap.kt
BaiduMapView.kt
Utils.kt
比如 BaiduMapHeatMap.kt
文件修改如下:
fun setPoints(points: ReadableArray) { this.points = (0..(points.size() - 1))
.map { points.getMap(it) }
.map {
val intensity = if (it!!.hasKey("intensity")) it!!.getDouble("intensity") else 0.0
WeightedLatLng(it!!.toLatLng(), intensity)
}
}
解决了吗解决了吗解决了吗解决了吗解决了吗
以上是 【安卓】ReactNative 集成 react-native-baidumap-sdk,android Kotlin编译报错 的全部内容, 来源链接: utcz.com/a/98753.html