mapkit-android-demo
mapkit-android-demo copied to clipboard
java.lang.RuntimeException: Native object for N6yandex4maps7runtime4view12PlatformViewE is of wrong smart pointer type!
Ошибка возникает при попытке создании MapView(context)
в проекте с react-native.
Насколько я понимаю возможен конфликт нативных (shared object) библиотек, т.к. я уже пытался создать вьюху карты в MainActivity
который наследуется от AppCompatActivity
следующим образом (ранее работало отлично через native-bridge):
package com.mapproject;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.yandex.mapkit.MapKitFactory;
import com.yandex.mapkit.mapview.MapView;
public class MainActivity extends AppCompatActivity {
private final String MAPKIT_API_KEY = "***";
private MapView mapView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MapKitFactory.setApiKey(MAPKIT_API_KEY);
MapKitFactory.initialize(this);
mapView = new MapView(this);
this.addContentView(mapView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1f));
}
}
Т.е. выкинув практически все что можно от react-native
, но получаю такой результат:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mapproject, PID: 4709
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mapproject/com.mapproject.MainActivity}: java.lang.RuntimeException: Native object for N6yandex4maps7runtime4view12PlatformViewE is of wrong smart pointer type!
Exception stack trace (top 9 entries):
# 0: 1621304 libcom.yandex.runtime.so _ZN6yandex4maps7runtime9backtrace9BacktraceC1Ev
# 1: 1638971 libcom.yandex.runtime.so
# 2: 1638385 libcom.yandex.runtime.so _ZN6yandex4maps7runtime9ExceptionC2ERKNSt6__ndk112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEENS2_8SeverityE
# 3: 1747940 libcom.yandex.mapkit.so
# 4: 6874875 libcom.yandex.mapkit.so
# 5: 6874636 libcom.yandex.mapkit.so
# 6: 6874478 libcom.yandex.mapkit.so
# 7: 6857944 libcom.yandex.mapkit.so Java_com_yandex_mapkit_internal_MapKitBinding_createMapWindow__Lcom_yandex_runtime_view_PlatformGLView_2
# 8: 172268 libdvm.so dvmPlatformInvoke
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Причем ранее YMK, с версией RN 0.57, работал. Проблема начала наблюдаться в 0.59-0.60 (вероятнее всего в 0.58 тоже)
Проблема наблюдается как на arm, так и на x86 платформах.
build.gradle следующий:
apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
* bundleCommand: "ram-bundle",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
entryFile: "src/index.ts",
enableHermes: true, // clean and rebuild if changing
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false)
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.mapproject"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
packagingOptions {
pickFirst '**/armeabi-v7a/libc++_shared.so'
pickFirst '**/x86/libc++_shared.so'
pickFirst '**/arm64-v8a/libc++_shared.so'
pickFirst '**/x86_64/libc++_shared.so'
pickFirst '**/x86/libjsc.so'
pickFirst '**/armeabi-v7a/libjsc.so'
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.yandex.android:mapkit:3.4.0'
if (enableHermes) {
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
Проверял 3.3.0 и 3.4.0 версии mapkit
Изменил версию MapKit на 3.0.0 и проблема исчезла.
В build.gradle
вместо этого:
implementation 'com.yandex.android:mapkit:3.4.0'
вставил это:
implementation ('com.yandex.android:mapkit:3.0.0') {
exclude group: "com.google.android.gms"
}
@RuslanLann а проверяли в проекте с react-native именно? Смена версии mapkit-а ничего не дала, делал clean & rebuild.
Я создал проект в котором это можно повторить https://github.com/MikeChugunov/mapProject который использует модуль из репозитория https://github.com/MikeChugunov/react-native-yandex-map
после клонирования достаточно сделать:
yarn install && yarn start
и запустить проект из подпапки android или выполнить react-native run-android
если установлен cli
@MikeChugunov Да, именно для проекта на React Native я и делаю карту. Нашел настройки для build.gradle в проекте https://github.com/escaton/react-native-yandex-map-kit и вставил вместо тех, что были у Яндекса в документации к MapKit. Все работает и в этом проекте, и в моем.
@RuslanLann версия react-native>=0.59.0? Я отталкивался от этого модуля вообщем-то, и на RN версии 0.57 все было хорошо с китом версии 3.3.0.
Но сейчас с этой библиотекой с react-native 0.59.10/0.60.0/0.60.4-5 такой же вылет:
E/unknown:ReactNative: Exception in native call
java.lang.RuntimeException: Native object for N6yandex4maps7runtime4view12PlatformViewE is of wrong smart pointer type!
Exception stack trace (top 20 entries):
# 0: 1621304 /data/app/com.mapproject-9TsLdisi_valtUj-C1X46w==/lib/x86/libcom.yandex.runtime.so _ZN6yandex4maps7runtime9backtrace9BacktraceC1Ev
# 1: 1638971 /data/app/com.mapproject-9TsLdisi_valtUj-C1X46w==/lib/x86/libcom.yandex.runtime.so
# 2: 1638385 /data/app/com.mapproject-9TsLdisi_valtUj-C1X46w==/lib/x86/libcom.yandex.runtime.so _ZN6yandex4maps7runtime9ExceptionC2ERKNSt6__ndk112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEENS2_8SeverityE
# 3: 1747940 /data/app/com.mapproject-9TsLdisi_valtUj-C1X46w==/lib/x86/libcom.yandex.mapkit.so
# 4: 6874875 /data/app/com.mapproject-9TsLdisi_valtUj-C1X46w==/lib/x86/libcom.yandex.mapkit.so
# 5: 6874636 /data/app/com.mapproject-9TsLdisi_valtUj-C1X46w==/lib/x86/libcom.yandex.mapkit.so
# 6: 6874478 /data/app/com.mapproject-9TsLdisi_valtUj-C1X46w==/lib/x86/libcom.yandex.mapkit.so
# 7: 6857944 /data/app/com.mapproject-9TsLdisi_valtUj-C1X46w==/lib/x86/libcom.yandex.mapkit.so Java_com_yandex_mapkit_internal_MapKitBinding_createMapWindow__Lcom_yandex_runtime_view_PlatformGLView_2
# 8: 6541928 /system/lib/libart.so
# 9: 6517347 /system/lib/libart.so
#10: 1093840 /system/lib/libart.so _ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc
#11: 3237184 /system/lib/libart.so _ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_11ShadowFrameEtPNS_6JValueE
#12: 3209125 /system/lib/libart.so _ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE
#13: 6414304 /system/lib/libart.so MterpInvokeInterface
#14: 6456482 /system/lib/libart.so artMterpAsmInstructionStart
#15: 3050028 /system/lib/libart.so
#16: 3076840 /system/lib/libart.so _ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE
#17: 3209099 /system/lib/libart.so _ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE
#18: 6415405 /system/lib/libart.so MterpInvokeDirect
#19: 6456226 /system/lib/libart.so artMterpAsmInstructionStart
at com.yandex.mapkit.internal.MapKitBinding.createMapWindow(Native Method)
at com.yandex.mapkit.mapview.MapView.init(MapView.java:59)
at com.yandex.mapkit.mapview.MapView.<init>(MapView.java:54)
at com.yandex.mapkit.mapview.MapView.<init>(MapView.java:39)
at com.yandex.RNYandexMapKit.RNYandexMapKitManager.createViewInstance(RNYandexMapKitManager.java:35)
at com.yandex.RNYandexMapKit.RNYandexMapKitManager.createViewInstance(RNYandexMapKitManager.java:18)
at com.facebook.react.uimanager.ViewManager.createViewInstanceWithProps(ViewManager.java:119)
at com.facebook.react.uimanager.ViewManager.createViewWithProps(ViewManager.java:66)
at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:259)
at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:198)
at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:838)
at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:952)
at com.facebook.react.uimanager.UIViewOperationQueue.access$2200(UIViewOperationQueue.java:44)
at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1012)
at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:172)
at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:84)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:909)
at android.view.Choreographer.doC
Самое плохое что вылет наблюдается даже если в самом проекте в MainActivity попытаться создать MapView
. Я знаю что у react-native "под капотом" очень многое поменялось в версии 0.58, и я боюсь что это из-за NDK библиотек которые он использует.
А ниже 0.59 откатываться не вариант - иначе не собрать arm64/x86-64 сборки для Play Store
@MikeChugunov версия React Native 0.60.4.
@RuslanLann огромное спасибо, видимо clean не до конца очистил все, теперь работает!
Тем не менее, проблема с актуальной версией mapkit остается
@MikeChugunov отлично! Очень рад! Да, проблема остается. Очень не хватает Яндекс Карт для React Native
@RuslanLann как минимум есть проблема на реальных устройствах с 64-битными процами на mapkit:3.0.0, там нет .so под 64-битные версии:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mapproject, PID: 26100
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.mapproject/app_lib/libgnustl_shared.so" is 32-bit instead of 64-bit
at java.lang.Runtime.load0(Runtime.java:928)
at java.lang.System.load(System.java:1633)
at com.yandex.runtime.internal.ReLinker.loadLibrary(ReLinker.java:82)
at com.yandex.runtime.Runtime.loadLibrary(Runtime.java:122)
at com.yandex.runtime.Runtime.init(Runtime.java:99)
at com.yandex.mapkit.MapKitFactory.initialize(MapKitFactory.java:18)
at com.simbirsoft.RNYandexMap.YandexMapManager.createViewInstance(YandexMapManager.java:26)
at com.simbirsoft.RNYandexMap.YandexMapManager.createViewInstance(YandexMapManager.java:12)
at com.facebook.react.uimanager.ViewManager.createViewInstanceWithProps(ViewManager.java:119)
at com.facebook.react.uimanager.ViewManager.createViewWithProps(ViewManager.java:66)
at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:259)
at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:198)
at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:838)
at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:952)
at com.facebook.react.uimanager.UIViewOperationQueue.access$2200(UIViewOperationQueue.java:44)
at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1012)
at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:172)
at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:84)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1010)
at android.view.Choreographer.doCallbacks(Choreographer.java:824)
at android.view.Choreographer.doFrame(Choreographer.java:756)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:998)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6693)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
вроде как есть способы использовать 32-битную либу в 64-битном проекте. Ищу варианты, возможно удасться положить как-то libgnustl_shared.so 64-битной версии из новой версии библиотеки
После переезда на RN 0.61 у нас тоже отвалился MapKit 3.4. @MikeChugunov получилось что-нибудь в итоге?
@hssrrw пока пришлось костылять реализацию на вебвью для Android, нужно как-то привлечь Яндекс к этой проблеме
RN 0.61.2 Android (Hermes) откатился до 3.1.0 и всё работает
Немного оживлю ветку - проблема все еще актуальна. В react native в андроид приходится использовать версию 3.2.0
Помимо проблем повышения стабильности в новых версиях так же апи было обновлено. То есть старую версию в полной мере использовать очень неудобно - документация есть только для последней версии (если кто знает киньте ссылку на старую доку)
p.s: дока конечно и так не очень информативная, но например метод getMap().setStyle принимает строку, а какой у нее формат искать надо в доке. Формат от актуальной версии не работает в версии 3.2.0