React Native Release APK仅限Android崩溃

时间:2018-02-07 17:23:41

标签: android react-native react-native-android crash-reports

我的apk-debug工作正常!

Build apk-release工作正常!

当我安装到设备时,应用程序崩溃并从此问题开始:

adb logcat

E AndroidRuntime: Process: br.com.missionbrasil, PID: 10382
E AndroidRuntime: java.lang.RuntimeException: com.facebook.react.devsupport.JSException: Strict mode does not allow function declarations in a lexically nested statement. (index.android.bundle:4)
E AndroidRuntime:   at com.facebook.react.bridge.DefaultNativeModuleCallExceptionHandler.handleException(DefaultNativeModuleCallExceptionHandler.java:24)
E AndroidRuntime:   at com.facebook.react.devsupport.DisabledDevSupportManager.handleException(DisabledDevSupportManager.java:172)
E AndroidRuntime:   ... 7 more
W ActivityManager:   Force finishing activity br.com.missionbrasil/.MainActivity

我改变所有条件=&gt; { vars && (<View></View>) } to { vars ?: }

清洁./gradlew 100次......

的package.json

"dependencies": {
    "@expo/react-native-fade-in-image": "^1.1.1",
    "@expo/react-native-touchable-native-feedback-safe": "^1.1.2",
    "autobind-decorator": "^1.3.4",
    "babel-core": "^6.26.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "react": "16.0.0",
    "react-addons-update": "^15.6.2",
    "react-native": "^0.51.0",
    "react-native-image-crop-picker": "^0.19.1",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0"
  },
  "devDependencies": {
    "babel-jest": "21.2.0",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
    "babel-plugin-transform-export-extensions": "^6.22.0",
    "babel-preset-react-native": "4.0.0",
    "jest": "21.2.1"
  },
  "jest": {
    "preset": "react-native"
  }

任何人都有同样的问题吗?

问候。

2 个答案:

答案 0 :(得分:0)

SyntaxError:严格模式不允许在词法嵌套语句中使用函数声明

按照下面列出的步骤搜索并替换node_modules文件夹中的3个字符串:

  

第1步| NativeModules.js

  • 转到:/node_modules/react-native/Libraries/BatchedBridge/BatchedBridgedModules/NativeModules.js
  • 发现:function normalizePrefix(moduleName: string)
  • 替换为:const normalizePrefix = function(moduleName: string)
  

第2步| UIManager.js

  • 转到:/node_modules/react-native/Libraries/Utilities/UIManager.js
  • 发现:function normalizePrefix(moduleName: string)
  • 替换为:const normalizePrefix = function(moduleName: string)
  

第3步| InitializeJavascriptAppEngine.js

  • 转到:node_modules\react-native\Libraries\JavaScriptAppEngine\Initialization\InitializeJavaScriptAppEngine.js
  • 发现:function handleError(e, isFatal)
  • 替换为:var handleError = function(e, isFatal)
  

第4步| npm start - --reset-cache

替换所有字符串后运行npm start -- --reset-cache,它现在应该可以正常工作

答案 1 :(得分:0)

我只是清理.babelrc中的所有插件,就像魅力一样。

像这样:

{
  "presets": [
    "react-native"
  ]
}

我的问题的原因是=&gt; &#34;变换ES2015模块-CommonJS的&#34;

感谢Craig的帮助!