react-native mobx android realease報錯解決方案

rn使用mobx時,debug模式?jīng)]有任何問題,但是release時發(fā)現(xiàn)ios和android都會出現(xiàn)閃退現(xiàn)象。ios比較好弄,android費了一天功夫查閱各種資料最終解決了。下面把解決過程分享一下。

環(huán)境

"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發(fā)現(xiàn)報錯

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'}}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容