React-Native Android未定义不是对象(评估' root ._')

时间:2018-04-08 10:43:48

标签: android react-native redux react-redux

我在运行我的应用时出现问题,特别是在Android上。当我运行react-native run-android并启动应用程序时(有或没有事先运行react-native start)我得到以下错误:Undefined不是一个对象(评估' root ._')。然后我无法启动调试器,因为这会在连接到远程调试器错误时给我一个超时。

Error shown

Debugger error

我的应用程序加载过程如下: index.js:

import { AppRegistry } from 'react-native'
import setup from './src/setup'

AppRegistry.registerComponent('appname', setup)

setup.js:

import React, { Component } from 'react'
import { View } from 'react-native'
import { Provider } from 'react-redux'
import { AsyncStorage } from 'react-native'
import { persistStore } from 'redux-persist';
import configureStore from './store/configureStore'

import Spinner from './components/common/Spinner'
import App from './App'

import styles from './styles/setup'

export class Root extends Component {

  constructor() {
    super()
    this.state = {
      loaded: false,
      // store: configureStore(this.onStoreLoaded.bind(this))
    }
  }

  onStoreLoaded() {
    this.setState({
      loaded: true,
    })
  }

  render() {
    return (

    <View style={styles.wrapper}>
      <Spinner/>
    </View>
  )
  }
}

export default function setup() {
  return Root
}

我现在注释了商店加载,因为自添加redux以来这似乎已经变得明显,但是配置存储看起来如下:

import {applyMiddleware, createStore, compose} from 'redux'
import {persistStore, autoRehydrate} from 'redux-persist';
import { AsyncStorage } from 'react-native'
import thunk from 'redux-thunk'

import reducers from '../reducers'

const middlewares = [
  thunk
]

const store = createStore(
  reducers,
  undefined,
  compose(
    applyMiddleware(...middlewares),
    autoRehydrate()
  )
)

export default function(callback) {
  persistStore(store, {
    blacklist: [],
    storage: AsyncStorage
  }, callback)

  return store
}

我使用react-native 0.53.0,redux版本为3.7.2,react-redux 5.0.6。我尝试重新捆绑代码如下:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

我也尝试过:adb reverse tcp:8081 tcp:8081

我还在Android工作室更新了我的构建工具和gradle等,一切都很好。

0 个答案:

没有答案