我有一个派生版本的React Native,它位于node_modules。
然而,Android Studio仍然使用~/.gradle/caches中的React Native安装。我之所以知道这一点,是因为如果我像这样进行导入:
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;在它的最后部分,它在~/.gradle/caches中打开的文件是非常旧的React command+click (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"
}
}
}发布于 2017-09-19 08:07:36
好的,这是有帮助的:
./gradlew :ReactAndroid:assembleDebug然后:
./gradlew :ReactAndroid:installArchives资料来源:
https://github.com/Microsoft/react-native-code-push/issues/858
https://github.com/uk-ar/react-native/tree/master/ReactAndroid
https://stackoverflow.com/questions/46289689
复制相似问题