1. 环境
    react-native 0.7.0
  2. 安装
    npm i -S react-native-config
  3. 设置.env文件
// .env.staging
API_URL = https://dev.xxxx.com
  1. 配置package.json
 "scripts": {
    "android:staging": "ENVFILE=.env.staging react-native run-android",
  },
  1. 安卓配置
    android/app/build.gradle 文件最末尾
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" 
  1. 打包时指定环境
    $ cd android && ENVFILE=.env.staging ./gradlew assembleRelease
  2. 解决 Failed to transform react-native-0.71.0-rc.0-release.aar
    android/app/build.gradle
buildscript {
    // ...
}


allprojects {
    repositories {
       exclusiveContent {
           filter {
               includeGroup "com.facebook.react"
           }
           forRepository {
               maven {
                   url "$rootDir/../node_modules/react-native/android"
               }
           }
       }
        // ...
    }
}

参考来源 https://github.com/facebook/react-native/issues/35204

  1. iOS配置
    未配置
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐