【问题标题】:React Native Android: screenPhysicalPixels.width is undefinedReact Native Android:screenPhysicalPixels.width 未定义
【发布时间】:2016-02-24 17:59:59
【问题描述】:

我最近升级到 RN 0.20,当我尝试加载我的应用程序时,现在抛出了以下异常:

undefined is not an object (evaluating 'screenPhyisicalPixels.width')
<unknown>
index.android.bundle?platform=android& def=true:32950
requireImpl
index.android.bundle?platform=android& def=true:76
_require
index.android.bundle?platform=android& def=true:36

这显然会导致以下文件出现 JS 错误:

node_modules/react-native/Libraries/Utilities/Dimensions.js at line 30

关于信息,我在我的应用中使用 Dimensions API。

对此有什么建议吗?

【问题讨论】:

    标签: android reactjs react-native


    【解决方案1】:

    您需要将android/app/build.gradle中的字符串更新为

    dependencies {
        compile "com.facebook.react:react-native:0.20.+"
    }
    

    然后运行

    npm start
    react-native run-android
    

    【讨论】:

      【解决方案2】:

      在将我的项目从 0.19 升级到 0.20 时,我遇到了类似的问题。

      它为我做了什么,运行react-native upgrade

      之后,您可能需要使用npm install 重新安装您的模块。

      编辑:当然之后通过react-native run-android 重建您的应用程序。

      【讨论】:

        【解决方案3】:

        最好的办法是删除 node_modules 文件夹。之后在根目录运行

        watchman watch-del-all
        

        下一步是运行

        npm install 
        

        然后手动启动打包程序

        react-native start --reset-cache
        

        这对我有帮助。祝你好运!

        【讨论】:

          【解决方案4】:

          我不清楚哪个命令到底做了什么,但我在以下步骤后修复了它,这要归功于@mr-brown 和@matija-grcic 答案的组合:

          1. package.json 中设置"react-native": "^0.20.0",
          2. 删除node_modules
          3. 运行react-native upgrade(更新android/app/build.gradle等)
          4. 在我的手机上卸载应用程序
          5. react-native run-android

          【讨论】:

            猜你喜欢
            • 2021-09-15
            • 2016-09-26
            • 2022-01-21
            • 2021-11-30
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-09-23
            相关资源
            最近更新 更多