1. 程式人生 > >Android原生專案引入最新的React Native包

Android原生專案引入最新的React Native包

做一個記錄,解決androidstudio無法下載最新的React Native問題

在你的 android/app/build.gradle新增程式碼

compile 'com.facebook.react:react-native:<your_version_here>'

然後在android/build.gradle檔案裡面新增

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            //********這裡必須寫對應的目錄,否則找不到本地node_modules下面的包
            url "$rootDir/../node_modules/react-native/android"
        }
    }
    configurations.all {
      resolutionStrategy {
        eachDependency { DependencyResolveDetails details ->
          if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native') {
            details.useVersion "<your_version_here>"
          }
        }
      }
   }
}