Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Is profilo compatible with react-native? #42

Closed
popahqiu opened this issue Mar 5, 2019 · 7 comments
Closed

Is profilo compatible with react-native? #42

popahqiu opened this issue Mar 5, 2019 · 7 comments

Comments

@popahqiu
Copy link

popahqiu commented Mar 5, 2019

Hello. Hope this finds you well.

Recently I've come accoss a problem that bothers me a lot.
My app already has react-native in it. So when I tried to put profilo into it, I met the following error while starting the app up.

I/AEE_AED: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/AEE_AED: Build fingerprint: 'Meizu/meizu_MX6/MX6:7.1.1/NMF26O/1547836199:user/release-keys'
I/AEE_AED: Revision: '0'
I/AEE_AED: ABI: 'arm'
I/AEE_AED: pid: 5213, tid: 5336, name: MainActivity_Jo >>> com.qiyi.video <<<
I/AEE_AED: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xdeadb00c
I/AEE_AED: Abort message: 'Assert (/code/rn-upgrade/android/react-native-0.55/ReactAndroid/src/main/jni/first-party/fb/jni/Environment.cpp:42): g_vm'
I/AEE_AED: r0 0000008c r1 00000000 r2 00000000 r3 deadb00c
I/AEE_AED: r4 e49f9004 r5 00000000 r6 00000001 r7 c4e38158
I/AEE_AED: r8 c4e3817c r9 edc09008 sl c4e381a0 fp c4e38318
I/AEE_AED: ip c4e3704c sp c4e38118 lr e49ec6d9 pc e49ec6dc cpsr 600f0030
I/AEE_AED: backtrace:
I/AEE_AED: #00 pc 000086dc /data/app/com.qiyi.video-2/lib/arm/libfb.so (_ZN8facebook14assertInternalEPKcz+71)
I/AEE_AED: #1 pc 000090af /data/app/com.qiyi.video-2/lib/arm/libfb.so
I/AEE_AED: #2 pc 00009259 /data/app/com.qiyi.video-2/lib/arm/libfb.so (_ZN8facebook3jni11Environment7currentEv+32)
I/AEE_AED: #3 pc 00014a11 /data/app/com.qiyi.video-2/lib/arm/libreactnativejni.so (_ZN8facebook3jni6JClass15registerNativesESt16initializer_listINS0_12NativeMethodEE+22)
I/AEE_AED: #4 pc 000260a1 /data/app/com.qiyi.video-2/lib/arm/libreactnativejni.so
I/AEE_AED: #5 pc 0000d43b /data/app/com.qiyi.video-2/lib/arm/libfb.so (_ZN8facebook3jni10initializeEP7_JavaVMOSt8functionIFvvEE+390)
I/AEE_AED: #6 pc 00025ae1 /data/app/com.qiyi.video-2/lib/arm/libreactnativejni.so (JNI_OnLoad+48)
I/AEE_AED: #7 pc 0023d4c9 /system/lib/libart.so (ZN3art9JavaVMExt17LoadNativeLibraryEP7_JNIEnvRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEP8_jobjectP8_jstringPS9+1844)
I/AEE_AED: #8 pc 00003233 /system/lib/libopenjdkjvm.so (JVM_NativeLoad+178)
I/AEE_AED: #9 pc 731675c5 /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x2f63000)

It seems to be related to some conflicts on libfb and libfbjni between the two projects: rn and profilo.
As I looked into them, I found that the code path and structure are totally different.
For example, there are
profilo/deps/fb
profilo/deps/fbjni/cxx/fbjni
profilo/deps/fbjni/cxx/lyra
profilo/deps/fbjni/java
&
react-native/ReactAndroid/src/main/jni/first-party/fb/include
react-native/ReactAndroid/src/main/jni/first-party/fb/jni
react-native/ReactAndroid/src/main/jni/first-party/fb/jni/android
react-native/ReactAndroid/src/main/jni/first-party/fb/jni/java
react-native/ReactAndroid/src/main/jni/first-party/fb/lyra

The files in those folders are very similar (same names but slightly different content).
I guess that might be the cause to the crash.

Would you please give some advice on how to resolve it?
Or, it will be perfect if you have plan to support it. XD

Thanks for your time.

@BurntBrunch
Copy link
Contributor

I guess that might be the cause to the crash.

It's possible though the two copies of fbjni should be able to coexist, they're in entirely different libraries.

Can you do me a favor and list the libraries in your APK before you include profilo? I suspect that our libfb is overwriting react-native's or vice versa. The fix should be trivial but I'd like a listing of the conflicting library names first.

@popahqiu
Copy link
Author

popahqiu commented Mar 8, 2019

Can you do me a favor and list the libraries in your APK before you include profilo?

Sure, there are about 49 of them (sorry for the long list) :
libc++_shared.so
libcardjsc.so
libCube.so
libcupid.so
libfb.so
libffmpeg-armv7-neon.so
libfolly_json.so
libframefilter.so
libgifimage.so
libglog.so
libglog_init.so
libgnustl_shared.so
libgpufilter.so
libicu_common.so
libimagepipeline.so
libjsc.so
liblivenet6.so
liblocSDK6a.so
libmarsxlog.so
libmcto_media_player.so
libmctocurl.so
libMMANDKSignature.so
libmmkv.so
libmp.so
libnativeDaemonAPI21.so
libnativeprocess.so
libndkbitmap.so
libpl_droidsonroids_gif.so
libpluginpatch.so
libpp_gif.so
libppqvideoeditor_neon43.so
libprivatedata.so
libprotect.so
libqtpclient.so
libqyapm_agent.so
libqyboxalign.so
libqylog.so
libreactnativejni.so
librtmp.so
libstatic-webp.so
libswtranscode.so
libwhitebox.so
libxcrash.so
libxcrash_dumper.so
libxhook.so
libxlog.so
libyhook.so
libyoga.so

I suspect that our libfb is overwriting react-native's or vice versa.

Yes, I used pickFirst 'lib/armeabi/libfb.so' in build.gradle file.
And I think react-native's libfb is overwritting profilo's. You might see it from the abort message, it was asserting in react-native:
I/AEE_AED: Abort message: 'Assert (/code/rn-upgrade/android/react-native-0.55/ReactAndroid/src/main/jni/first-party/fb/jni/Environment.cpp:42): g_vm'

@popahqiu
Copy link
Author

popahqiu commented Mar 8, 2019

Actually there are several types of conflicts I ran into while trying including profilo.

  1. "More than one file was found with OS independent path"
         lib/armeabi/libgnustl_shared.so
         **lib/armeabi/libfb.so**
         javax/annotation/CheckReturnValue.java
         javax/annotation/concurrent/Immutable.java

Solution: pickFirst in build.gradle

  1. "Program type already present: ..." - java package conflicts
        com.facebook.jni
	com.facebook.proguard
	com.facebook.soloader
	javax.annotation

Solution: remove these java files from classes.jar in profilo.aar

  1. java.lang.NoSuchMethodError in com.facebook.soloader
    Cause: different versions of soloader used in rn and profilo
    Solution: use same soloader

  2. java.lang.UnsatisfiedLinkError in libprofilo_systemcounters.so
    Cause: some symbols missing. Again, different versions of NDK used.
    Solution: Use same NDK to compile both.

Most of them seems irrelevant to our current topic, except for
lib/armeabi/libfb.so
I think we may focus on that.

Just post this one for record, in case someone needs it.

@popahqiu
Copy link
Author

@BurntBrunch Sir, is there anything more I could provide?
I'm still stuck with this one :(
Looking forward to your advice.

@BurntBrunch
Copy link
Contributor

Sorry about that, I was ooo.

libfb.so is definitely what's causing this crash and it's pretty easy to fix. I'll have a commit up soon.

As for the java conflicts... we need to figure out a better story, I'll raise this with the RN team.

facebook-github-bot pushed a commit that referenced this issue Mar 19, 2019
Summary:
This diff fixes some obscurities in the BUCK setup and ensures that all native libraries under our control are prefixed with `profilo_`.

This addresses issue #42.

Reviewed By: aandreyeu

Differential Revision: D14508127

fbshipit-source-id: efb35342802504e770eda5e97f57ce4490f2b90d
@BurntBrunch
Copy link
Contributor

BurntBrunch commented Mar 19, 2019

@popahqiu the native library conflict should be resolved now, can you please check if anything else breaks your app?

@popahqiu
Copy link
Author

No more crash now.
Really save the day.
Thank you so much. 👍

facebook-github-bot pushed a commit that referenced this issue Feb 18, 2021
Summary:
Planning to upgrade the native build steps a little, but need to be up-to-date on build dependencies first.

Pull Request resolved: facebookincubator/fbjni#42

Reviewed By: fabiomassimo

Differential Revision: D26512246

Pulled By: passy

fbshipit-source-id: 1fb059018b6b4ab0deb3a7f23ab2d6b70a7eac46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants