react-native|react-native mobx android realease报错解决方案

rn使用mobx时,debug模式没有任何问题,但是release时发现ios和android都会出现闪退现象。ios比较好弄,android费了一天功夫查阅各种资料最终解决了。下面把解决过程分享一下。
【react-native|react-native mobx android realease报错解决方案】环境

"react": "16.4.1",
"react-native": "0.56.0",
"mobx": "^5.9.4",
"mobx-react": "5.2.0"
pckage.json
"devDependencies": {
"@babel/core": "7.0.0-beta.47",
"@babel/plugin-proposal-decorators": "7.0.0-beta.47",
"@babel/plugin-transform-runtime": "7.0.0-beta.47",
"@babel/runtime": "7.0.0-beta.47",
"babel-jest": "24.1.0",
"babel-preset-mobx": "^2.0.0",
"babel-preset-react-native": "^5",
"jest": "24.1.0",
"metro-react-native-babel-preset": "^0.53.1",
"react-test-renderer": "16.4.1"
},
.babelrc
{
"presets": ["react-native"],
"plugins": [
[ "@babel/plugin-proposal-decorators", {"legacy": true}],
[ "@babel/plugin-transform-runtime",
{
"helpers": true,
"polyfill": false,
"regenerator": false
}
]
]
}
--------------------------------------------------华丽的分割线--------------------------------------------------------
1.ios闪退解决方案 将你的index.js文件挪动到下一级文件夹,比如我的是src
外层index.js像下面这样
import { AppRegistry } from 'react-native';

import applyDecoratedDescriptor from '@babel/runtime/helpers/es6/applyDecoratedDescriptor';
import initializerDefineProperty from '@babel/runtime/helpers/es6/initializerDefineProperty';
Object.assign(babelHelpers, {
applyDecoratedDescriptor,
initializerDefineProperty
});
import App from './src';
AppRegistry.registerComponent('rn', () => App);
2.android闪退解决方案 android-studio下debug发现报错
Can not finde Symbol
Module AppRegistry is not a registered callable module
如果遇到这种错误,大多因为mobx的版本太高,android本身jscore不支持高版本的mobx,有两种解决方案,看mobx作者给的方案,https://github.com/mobxjs/mobx/issues/1582#issuecomment-416131218
我采用的是第一种方案,升级android 的jsc,具体过程参照https://fir.im/uxn7?release_id=5c3ea122ca87a81d10588db8,不过值得一提的是,packge.json里的jsc-android的版本必须与
build.gradle里的一致。注意
packge.json
"dependencies": {
.....省略
"axios": "^0.18.0",
"git": "^0.1.5",
"jsc-android": "^236355.1.1",
.....省略
}
configurations.all {resolutionStrategy {force 'org.webkit:android-jsc:r236355'}}

    推荐阅读