只需从Android Studio导入android目录,
更改你的app/build.gradle文件,
在apply from: "../../node_modules/react-native/react.gradle"之前添加以下代码
project.ext.react = [
bundleAssetName: "index.android.bundle",
entryFile: "index.android.js",
bundleInDebug: false,
bundleInRelease: true,
root: "../../",
jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
jsBundleDirRelease: "$buildDir/intermediates/assets/release",
resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
inputExcludes: ["android/", "ios/"],
nodeExecutableAndArgs: ["node"],
extraPackagerArgs: []
]
现在为"react-native start"创建一个gradle任务。
task startReactNative(type: Exec) {
workingDir "../../"
commandLine 'cmd', '/c', 'react-native', 'start'
println "Working Directory for React is: $workingDir"
standardOutput = new ByteArrayOutputStream()
ext.output = {
println "React-Native Output: " + standardOutput.toString()
return standardOutput.toString()
}
}
您可以像往常一样运行应用程序,在将应用程序安装到设备后,运行 startReactNative 任务以激活热重载功能。