【发布时间】:2017-09-18 23:45:30
【问题描述】:
我有一个分支版本的 React Native,它位于 node_modules。
不过,Android Studio 仍在使用 ~/.gradle/caches 中的 React Native 安装。我知道这一点,因为如果我进行如下导入:
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
然后我命令+单击它的最后一部分,它在~/.gradle/caches 中实时打开文件,它是 React Native (0.20.1) 的一个非常旧的版本
如果我删除缓存并重新构建项目,则会自动下载相同的版本。
如何让 Android Studio 查看我的 node_modules 目录而不是 React Native 的缓存目录?
在 settings.gradle 中:
...
include ':react-native-android'
project(':react-native-android').projectDir = new File(rootProject.projectDir, '../node_modules/react-native/ReactAndroid')
在 app/build.gradle 中
...
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile project(':react-native-android')
}
configurations.all {
exclude group: 'com.facebook.react', module: 'react-native'
}
在 build.gradle 中:
buildscript {
repositories {
jcenter()
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'de.undercouch:gradle-download-task:3.1.2'
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
【问题讨论】:
标签: android android-studio react-native