安装环境:
1.python2,android sdk,java环境变量,nodejs
2.npm install -g react-native-cli
3.react-native init yourProjectName --version 0.55.4(不要安装0.56.1,会出现很多bug,0.55.4版本很稳定,--version 0.55.4一定要指定版本安装,新版本bug很多,比如
Unable to resolve module ‘AccessibilityInfo’ 的异常
1. Clear watchman watches: `watchman watch-del-all`.\n
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n
3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.
4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`."
rm都是linux命令,在window上不好使,且安装他的方法也没用,这是版本不稳定造成的
还有可能是系统问题,我是重装了系统解决(报了个setup.env.bat)
我当前react-native版本是
C:\Users\lmj>react-native -v
react-native-cli: 2.0.1
react-native: 0.55.4
)
4.总结:
1. react-native init yourProjectName --version 0.55.4
2.在react native项目的android目录下(如:D:\react native\1\app\android\local.proportites)创建文件localhost.properties,写入代码如下:
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Mon Sep 10 21:10:25 CST 2018
sdk.dir=D\:\\local software manager\\install\\android studio sdk
//注:D\:\\local software manager\\install\\android studio sdk是你本地的sdk安装目录
3.cnpm install
补充:
在MainApplication类的onCreate()中的代码如下:
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
/* 注释 */
@Override
public void onCreate() {
super.onCreate();
//SoLoader.init(this, /* native exopackage */ false);
SharedPreferences mPreferneces= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor=mPreferneces.edit();
editor.putString("debug_http_host","192.168.3.16:8081");
editor.commit();
}
4.手机连上电脑,输入:react-native run-android
5.安装完成