Am having a small problem with opening/importing a react-native into Android studio.
On the other hand, if I import using the import a gradle project dialog and select the build.gradle file, the project is imported, but I only see the files inside the android directory instead of the main project directory. But this method allows me to push changes easily to the emulator.
How can I fix my problem?
Thanks,
Just import android directory from Android Studio, make changes to your app/build.gradle add these codes before 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: []
]
Now create task for "react-native start" to your 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()
}
}
You can run your app as usual, after app installed to your device, run startReactNative task in order to activate Hot Reload
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With