facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.16k stars 24.21k forks source link

Android RN>=0.59 Native object for X is of wrong smart pointer type! Possibly NDK help needed! #26092

Closed chugunomi closed 4 years ago

chugunomi commented 5 years ago

Recently I started developing wrapper for native YandexMapKit module for iOS and Android. After updating RN from 0.57 to 0.59, and 0.60 (I didn't tested 0.58 yet, but most likely it causes crashes too) I started to get exceptions on android when YandexMapKit View is starts to draw.

React Native version: 0.59.10, 0.60.4, 0.60.5 (also tried 0.59.0 and 0.60.0)

Steps To Reproduce

  1. Add implementation 'com.yandex.android:mapkit:3.4.0' to your build.gradle dependencies
  2. Create com.yandex.mapkit.mapview.MapView somewhere, even MainAcivity THAT EXTENDS AppCompatActivity (or ReactActivity of course) cause crash:
    
    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 = "72c56920-584b-41c2-ad19-0b1b807847ce"; // you can use this key for now, I delete this key in couple of months
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));
}

}

Crash from bridge-module (same as from MainActivity)

E/unknown:ReactNative: Exception in native call 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 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.simbirsoft.RNYandexMap.YandexMapManager.createViewInstance(YandexMapManager.java:33)
    at com.simbirsoft.RNYandexMap.YandexMapManager.createViewInstance(YandexMapManager.java:17)
    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$DispatchUIFrameCallback.dispatchPendingNonBatchedOperations(UIViewOperationQueue.java:1036)
    at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1007)
    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:759)
    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
    at android.view.Choreographer.doFrame(Choreographer.java:543)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    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)

Describe what you expected to happen:
YandexMapKit.MapView renders as on 0.57 and not causing crash

Snack, code example, screenshot, or link to a repository:
You could also try to install module from repo:

yarn add https://github.com/MikeChugunov/react-native-yandex-map

And use it in some view:
```js
import YandexMap from 'react-native-yandex-map';
export default class App extends React.Component {
    render() {
        return <Fragment>
            <YandexMap style={{flex: 1, width: '100%'}}/>
        </Fragment>;
    }
}

iOS version should render yandex map view, but android throws error screen.

I suppose that crash caused by some NDK library conflicts, and since 0.59 is required to have arm64 builds for Play Store I really looking for help.

Just to clarify: this library works without any problem in native apps

lex-github commented 5 years ago

Have exact same runtime error Any news on this, friend @MikeChugunov?

chugunomi commented 5 years ago

@lex-github yup. I opened issue on mapkit-demo-android and found that only mapkit 3.0.0 working nice on 0.59 and 0.60 rn versions.

https://github.com/yandex/mapkit-android-demo/issues/116#issuecomment-522602885

Anyway the issue still remains for mapkit 3.1.0 and higher, waiting for response from yandex and facebook.

lex-github commented 5 years ago

Thanks for heads up, will use 3.0.0 until resolved!

chugunomi commented 4 years ago

@lex-github the problem with 3.0.0 is that they don't iclude 64-bit shared-libraries. So on real devices with arm64-v8a/x86_64 you'll be facing crash with

FATAL EXCEPTION: main
    Process: com.mapproject, PID: 1580
    java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.mapproject/app_lib/libgnustl_shared.so" is 32-bit instead of 64-bit
stale[bot] commented 4 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.