我正在一个使用djinni使用跨平台本机C ++的React Native项目中。

我已经looked at this question,但这似乎是一个不同的问题。

项目构建成功,但几乎立即运行失败。

adb logcat显示以下异常:


  找不到com.djinnius.HelloWorld $ CppProxy的实现com.djinnius.HelloWorld.create(com.rushingvise.reactcpp.ReactBridge)(尝试了Java_com_djinnius_HelloWorld_create和Java_com_djinnius_HelloWorld_create__Lcom_rushingvise_act_reactcpp_Re)


我试图了解上面消息中的tried含义。这是因为apk中缺少相应的本机代码吗?还是另一个原因?

完整的logcat如下:

04-19 19:44:51.042 2354-2700/com.djinnius E/art: No implementation found for com.djinnius.HelloWorld$CppProxy com.djinnius.HelloWorld.create(com.rushingvise.reactcpp.ReactBridge) (tried Java_com_djinnius_HelloWorld_create and Java_com_djinnius_HelloWorld_create__Lcom_rushingvise_reactcpp_ReactBridge_2)
04-19 19:44:51.045 2354-2354/com.djinnius W/unknown:React: Caught exception after cancelling react context init
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object com.facebook.react.ReactInstanceManager$Result.get()' on a null object reference
        at com.facebook.react.ReactInstanceManager$ReactContextInitAsyncTask.onCancelled(ReactInstanceManager.java:247)
        at com.facebook.react.ReactInstanceManager$ReactContextInitAsyncTask.onCancelled(ReactInstanceManager.java:197)
        at android.os.AsyncTask.finish(AsyncTask.java:665)
        at android.os.AsyncTask.-wrap1(AsyncTask.java)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:203)
        at android.app.ActivityThread.main(ActivityThread.java:6339)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
04-19 19:44:51.053 2354-2700/com.djinnius E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
    Process: com.djinnius, PID: 2354
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:325)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:761)
     Caused by: java.lang.UnsatisfiedLinkError: No implementation found for com.djinnius.HelloWorld$CppProxy com.djinnius.HelloWorld.create(com.rushingvise.reactcpp.ReactBridge) (tried Java_com_djinnius_HelloWorld_create and Java_com_djinnius_HelloWorld_create__Lcom_rushingvise_reactcpp_ReactBridge_2)
        at com.djinnius.HelloWorld.create(Native Method)
        at com.djinnius.HelloWorld.<init>(HelloWorld.java:27)
        at com.djinnius.HelloWorldPackage.createNativeModules(HelloWorldPackage.java:18)
        at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:88)
        at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:950)
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:891)
        at com.facebook.react.ReactInstanceManager.access$600(ReactInstanceManager.java:104)
        at com.facebook.react.ReactInstanceManager$ReactContextInitAsyncTask.doInBackground(ReactInstanceManager.java:218)
        at com.facebook.react.ReactInstanceManager$ReactContextInitAsyncTask.doInBackground(ReactInstanceManager.java:197)
        at android.os.AsyncTask$2.call(AsyncTask.java:305)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
        at java.lang.Thread.run(Thread.java:761) 


任何帮助表示赞赏。

最佳答案

找到了问题。
实际上,在扩展ReactPackage的Java类中确实缺少System.LoadLibrary()调用。
现在可以使用此类的初始值设定项

public class HelloWorldPackage implements ReactPackage {
    static {
        System.loadLibrary("native-lib");
    }

07-26 01:04