React Native - 在Android上集成brownfield

时间:2017-03-20 17:56:57

标签: android facebook android-asynctask react-native react-native-android

我正在facebook integrating with existing apps之后的棕色地带工作。到目前为止,所有人似乎都在建所以我用MyReactActivity换了一个当前工作的Activity - 只是为了快速看到我的React App连接到应用程序。我成功构建但是当我单击按钮启动MyReactActivity时,应用程序崩溃了。希望有人有另一个建议。

这是我换出的内容(刚刚更改为MyReactActivity) context.startActivity(MyReactActivity.intent(context));

github issues我注意到了一个推荐的修复,但我的代码实际上已经有了,可能是因为我正在使用react v.40:

-keepclassmembers class *  { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }

-keepclassmembers class *  { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }

这是转储:

W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTRenderableViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTGroupShadowNode
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTShapeShadowNode
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTTextShadowNode
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTSurfaceViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTSurfaceViewShadowNode
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.picker.ReactDialogPickerManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.uimanager.LayoutShadowNode
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.drawer.ReactDrawerLayoutManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.picker.ReactDropdownPickerManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.scroll.ReactHorizontalScrollViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.image.ReactImageManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.progressbar.ReactProgressBarViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.progressbar.ProgressBarShadowNode
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactRawTextManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactTextShadowNode
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.scroll.ReactScrollViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.switchview.ReactSwitchManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.switchview.ReactSwitchManager$ReactSwitchShadowNode
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactTextInlineImageViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactTextInlineImageShadowNode
E/EGL_emulation: tid 11759: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x966101c0, error=EGL_BAD_MATCH
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.textinput.ReactTextInputManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.textinput.ReactTextInputShadowNode
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactTextViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.toolbar.ReactToolbarManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.view.ReactViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.viewpager.ReactViewPagerManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactVirtualTextViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.webview.ReactWebViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.recyclerview.RecyclerViewBackedScrollViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.swiperefresh.SwipeRefreshLayoutManager
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
                  Process: com.app.android.ccs.debug, PID: 11684
                  java.lang.RuntimeException: An error occurred while executing doInBackground()
                      at android.os.AsyncTask$3.done(AsyncTask.java:318)
                      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 android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
                      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.IllegalAccessError: Method 'void android.support.v4.net.ConnectivityManagerCompat.<init>()' is inaccessible to class 'com.facebook.react.modules.netinfo.NetInfoModule' (declaration of 'com.facebook.react.modules.netinfo.NetInfoModule' appears in /data/app/com.app.android.ccs.debug-2/base.apk:classes95.dex)
                      at com.facebook.react.modules.netinfo.NetInfoModule.<init>(NetInfoModule.java:55)
                      at com.facebook.react.shell.MainReactPackage.createNativeModules(MainReactPackage.java:67)
                      at com.facebook.react.ReactInstanceManagerImpl.processPackage(ReactInstanceManagerImpl.java:793)
                      at com.facebook.react.ReactInstanceManagerImpl.createReactContext(ReactInstanceManagerImpl.java:730)
                      at com.facebook.react.ReactInstanceManagerImpl.access$600(ReactInstanceManagerImpl.java:91)
                      at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(ReactInstanceManagerImpl.java:184)
                      at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(ReactInstanceManagerImpl.java:169)
                      at android.os.AsyncTask$2.call(AsyncTask.java:304)
                      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
                      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) 
W/unknown:React: Unable to dispatch keyboard events in JS as the react instance has not been attached
D/LogcatOnlyCrashlyticsProxy: ACTIVITY: onPaused: MyReactActivity
D/DialogManager: MyReactActivity was paused, removing dialog.
D/DialogManager: removeDialogIfShowingAndRememberIfItWasShowing
D/OpenGLRenderer: endAllActiveAnimators on 0x955c5f80 (RippleDrawable) with handle 0xa875cfb0
V/MixpanelAPI.EditorCnctn: Websocket connected
V/MixpanelAPI.EditorCnctn: WebSocket closed. Code: 1005, reason: 
                           URI: wss://switchboard.mixpanel.com/connect/f0e4b7c1485987ea09a2661823af4287
V/MixpanelAPI.ViewCrawler: Editor closed- freeing snapshot
D/LogcatOnlyCrashlyticsProxy: ACTIVITY: onStopped: MyReactActivity
D/LogcatOnlyCrashlyticsProxy: ACTIVITY: onDestroy: MyReactActivity
D/LogcatOnlyCrashlyticsProxy: APP_BACKGROUND: APP UI WAS HIDDEN
E/MixpanelAPI.ViewCrawler: Can't write track_message to server
                           com.mixpanel.android.viewcrawler.EditorConnection$EditorConnectionException
                               at com.mixpanel.android.viewcrawler.EditorConnection$WebSocketOutputStream.write(EditorConnection.java:147)
                               at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
                               at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
                               at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:297)
                               at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
                               at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
                               at android.util.JsonWriter.flush(JsonWriter.java:384)
                               at com.mixpanel.android.viewcrawler.ViewCrawler$ViewCrawlerHandler.sendReportTrackToEditor(ViewCrawler.java:669)
                               at com.mixpanel.android.viewcrawler.ViewCrawler$ViewCrawlerHandler.handleMessage(ViewCrawler.java:321)
                               at android.os.Handler.dispatchMessage(Handler.java:102)
                               at android.os.Looper.loop(Looper.java:154)
                               at android.os.HandlerThread.run(HandlerThread.java:61)
E/MixpanelAPI.ViewCrawler: Can't close writer.
                           com.mixpanel.android.viewcrawler.EditorConnection$EditorConnectionException
                               at com.mixpanel.android.viewcrawler.EditorConnection$WebSocketOutputStream.close(EditorConnection.java:159)
                               at java.io.FilterOutputStream.close(FilterOutputStream.java:160)
                               at sun.nio.cs.StreamEncoder.implClose(StreamEncoder.java:320)
                               at sun.nio.cs.StreamEncoder.close(StreamEncoder.java:149)
                               at java.io.OutputStreamWriter.close(OutputStreamWriter.java:233)
                               at android.util.JsonWriter.close(JsonWriter.java:393)
                               at com.mixpanel.android.viewcrawler.ViewCrawler$ViewCrawlerHandler.sendReportTrackToEditor(ViewCrawler.java:674)
                               at com.mixpanel.android.viewcrawler.ViewCrawler$ViewCrawlerHandler.handleMessage(ViewCrawler.java:321)
                               at android.os.Handler.dispatchMessage(Handler.java:102)
                               at android.os.Looper.loop(Looper.java:154)
                               at android.os.HandlerThread.run(HandlerThread.java:61)

这是MyReactActivity:

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.appcompat.BuildConfig;
import android.view.KeyEvent;

import com.facebook.react.LifecycleState;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactRootView;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.shell.MainReactPackage;

public class MyReactActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {

        private ReactRootView mReactRootView;
        private ReactInstanceManager mReactInstanceManager;

        public static Intent intent(Context context) {
            return new Intent(context, MyReactActivity.class);
        }


    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            mReactRootView = new ReactRootView(this);
            mReactInstanceManager = ReactInstanceManager.builder()
                    .setApplication(getApplication())
                    .setBundleAssetName("index.android.bundle")
                    .setJSMainModuleName("index.android")
                    .addPackage(new MainReactPackage())
                    .setUseDeveloperSupport(BuildConfig.DEBUG)
                    .setInitialLifecycleState(LifecycleState.RESUMED)
                    .build();
            mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null);

            setContentView(mReactRootView);
        }

        @Override
        public void invokeDefaultOnBackPressed() {
            super.onBackPressed();
        }

        @Override
        protected void onPause() {
            super.onPause();

            if (mReactInstanceManager != null) {
                mReactInstanceManager.onPause();
            }
        }

        @Override
        protected void onResume() {
            super.onResume();

            if (mReactInstanceManager != null) {
                mReactInstanceManager.onResume(this, this);
            }
        }

        @Override
        public void onBackPressed() {
            if (mReactInstanceManager != null) {
                mReactInstanceManager.onBackPressed();
            } else {
                super.onBackPressed();
            }
        }

        @Override
        public boolean onKeyUp(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) {
                mReactInstanceManager.showDevOptionsDialog();
                return true;
            }
            return super.onKeyUp(keyCode, event);
        }
}

1 个答案:

答案 0 :(得分:1)

对我而言,解决方案是改变:

compile ("com.facebook.react:react-native:+") {
    exclude group:'com.facebook.stetho', module:'stetho'
  }

为:

compile ("com.facebook.react:react-native:0.42.3") {
    exclude group:'com.facebook.stetho', module:'stetho'
  }

这是因为我们内部的maven中心只允许我们将React Native更新为.20,即使使用+。较旧版本的react native与大于23的SDK或Google支持库不兼容,我们使用的是25。