一、報錯
Warning:Navigator:isMounted is deprecated. Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to
prevent memory leaks.
原因解析:
isMounted 被棄用
解決方案:
1、
npm install React-native-deprecated-custom-components --save
2、
import Navigator from 'react-native-deprecated-custom-components';
3、用到的地方使用
<Navigator.Navigator initialRoute={{ name: defaultName, component: defaultComponent }} configureScene={(route) => { return Navigator.Navigator.SceneConfigs.VerticalDownSwipeJump; }} renderScene={(route, navigator) => { let Component = route.component; return <Component {...route.params} navigator={navigator} /> }} />
4、千萬記得使用Navigator.Navigator,我一直直接使用<Navigator></Navigator>,總是報錯,
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)
but got: object.
這表明沒有找到Navigator組件,查了好半天才找到問題所在。
5、或者使用這種方式:
import CustomerComponents, {Navigator} from 'react-native-deprecated-custom-components'; <Navigator></Navigator>
二、報錯
Warning:Failed prop type: Invalid prop `style` of type `string` supplied to `Text`, expected `object`
原因解析:
style 類型出錯, 不應該是string類型, 應該是object類型
解決方案:
將 style="styles.face" ,該為 style={styles.face}
三、react-native run-android 報錯
Error: Cannot create directory C:\Users\Administrator\Desktop\react-native\GD\an droid\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values
:app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: Cannot create directory C:\Users\Administrator\Desktop\react-native\GD\ android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\value s
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1 mins 58.56 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
原因解析:
手機安全和隱私設置,默認禁止安裝未知來源的應用
解決方案:
安全和隱私 -- 未知來源 -- 允許安裝來自未知來源的應用
四、 react-native run-android 失敗
04:12:06 E/adb: Unable to obtain result of 'adb version'
:app:installDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: Could not create ADB Bridge. ADB location: D:\adt\sdk\platform-tools\adb.exe
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1 mins 38.099 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
原因解析:
解決方案:
五、react-native run-android 失敗
:app:mergeDebugResources
Error: Cannot create directory C:\Users\Administrator\Desktop\market\XMGBuy\andr oid\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values
:app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: Cannot create directory C:\Users\Administrator\Desktop\market\XMGBuy\an droid\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values
原因解析:
解決方案: