React-native makes it easier to adapt to multiple applications. However, in the project, I encountered a lot of special customization and fixed bugs that were not officially planned. The most direct solution was to modify the React-Native source code. So we need to modify the Android package configuration file so that we can use the React-native source code in node_modules directly in the project.
-
Modify the Android /settings.gradle file
include ':ReactAndroid' project(':ReactAndroid').projectDir = new File(rootProject.projectDir, '.. /node_modules/react-native/ReactAndroid')Copy the code
-
Modify the Android /local.properties file (if not, create your own)
sdk.dir=XXX ndk.dir=XXX Copy the code
So here’s the caveat
- For the NDK version, you need to download the corresponding version. The online version is a relatively old version, corresponding to the R10B NDK. And I used it in my latest project
"The react - native" : "0.63.3"
Use the R20B NDK. - If more than one dependent libraries in the project need to use different editions of the NDK, we’d better honestly in node_modules/react – native/ReactAndroid/build. Gradle specified in the NDK version.
- For the NDK version, you need to download the corresponding version. The online version is a relatively old version, corresponding to the R10B NDK. And I used it in my latest project
-
Modify the Android /app/build.gradle file
Configurations. All {exclude group: 'com.facebook.react', module: 'react-native'}} dependencies {// implementation "com.facebook.react:react-native:+" implementation project(':ReactAndroid') }Copy the code
-
Modify the Android /build.gradle file
Classpath 'de. Undercouch :gradle-download-task:3.4.3'} allprojects {configurations. resolutionStrategy { dependencySubstitution { substitute module("com.facebook.react:react-native:+") with project(":ReactAndroid") } } } }Copy the code
CD android &./gradlew clean This time to rebuild, react-native is compiled from node_modules. You can modify the source code directly to achieve this goal.