react native 常用命令

注意:在 Windows 中 gradlew 前面要加 ./

  • 新建 react native 项目
    react-native init AwesomeProject
    
  • 运行 react native (Android / iOS)
    cd AwesomeProject
    react-native run-android / react-native run-ios
    
  • android 清理
    cd android
    gradlew clean
    
  • android 打包
    1.打包配置
    
    # 使用 Androidstudio 生成签名,或者用 keytool 命令生成一个私有密钥
    keytool -genkey -v -keystore test.keystore -alias test -keyalg RSA -keysize 2048 -validity 10000
    
    # 把 test.keystore 文件放到你工程中的 android/app 文件夹下,添加以下配置到 gradle.properties 中
    MYAPP_RELEASE_STORE_FILE = test.keystore
    MYAPP_RELEASE_KEY_ALIAS = test
    MYAPP_RELEASE_STORE_PASSWORD = xxxxxx
    MYAPP_RELEASE_KEY_PASSWORD = xxxxxx
    
    # 添加以下配置到 android/app/build.gradle 中
    android {
      ……
      signingConfigs {
        debug {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
        release {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
      }
      ……
    }
    
    2.执行打包
    
    cd android
    gradlew assembleRelease
    
  • iOS 打包
    1.打包命令配置
    
    # 在项目中的 package.json 中添加以下配置
    "scripts": {
        "bundle-ios": "node node_modules/react-native/local-cli/cli.js bundle --entry-file index.js --platform ios --dev false --bundle-output ./ios/bundle/index.ios.jsbundle --assets-dest ./ios/bundle"
    },
    
    # 通过命令打包 .jsbundle 文件
    npm run bundle-ios
    
    # 在 xcode 打开项目,并添加
    - (void)viewDidLoad {
        [super viewDidLoad];
        NSURL *jsCodeLocation;
        #ifdef DEBUG //debug
          jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
        #else //release
          jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"bundle/index.ios" withExtension:@"jsbundle"];
        #endif
        RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"项目名" initialProperties:nil launchOptions:nil];
        rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
        self.view = rootView;
    }
    
    2.然后就是使用 xcode 打包啦,具体打包流程请--->还看,百度不会啊
    
  • react native 升级(单个)第三方库版本 <--点击查看原文
    注意:如果 npm update 命令后面不写库名,将会把可以更新的(npm outdated 命令后红色字体的库)全部更新
    # 查看当前有哪些组件或者第三方库版本有版本更新 
    npm outdated
    
    # 在 package.json 文件里面找到需要更新的库,修改版本号
    npm update 库名
    
  • 删除 node_module
    rm -rf node_modules
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文为React Native开发的入门介绍,包括搭建环境,开发调试,编译打包,版本发布,热更新等方面的基...
    前端连环话阅读 771评论 0 2
  • 应老大的要求, 最近看了几天的混合开发(Android). 一开始打算使用Ionic来做的, 毕竟前端用的Angu...
    MinuitZ阅读 244评论 0 0
  • 今天开学,迎来了萌哒哒的小机器人,孩子们看到了可兴奋了,我这个大朋友看到,都忍不住细细看看拍拍摸摸!不知...
    范秀红阅读 435评论 0 0
  • 日日行,不怕万千里;常常做,不怕千万事。 只有不断的挑战自己才能激发自己的潜能。 今天公布了股票营的学委名单,自己...
    花麗阅读 153评论 0 0
  • 由于文章长度限制,本文作为[译]线程编程指南(一)后续部分。 Run Loops Run loop是与线程相关的基...
    巧巧的二表哥阅读 1,232评论 0 5