11apply plugin : " com.android.application"
2+ apply plugin : " com.facebook.react"
23apply from : " ../../node_modules/react-native-vector-icons/fonts.gradle"
34
45import com.android.build.OutputFile
56
6- project. ext. react = [
7- enableHermes : false , // clean and rebuild if changing
8- ]
9-
10- apply from : " ../../node_modules/react-native/react.gradle"
7+ /**
8+ * This is the configuration block to customize your React Native Android app.
9+ * By default you don't need to apply any configuration, just uncomment the lines you need.
10+ */
11+ react {
12+ /* Folders */
13+ // The root of your project, i.e. where "package.json" lives. Default is '..'
14+ // root = file("../")
15+ // The folder where the react-native NPM package is. Default is ../node_modules/react-native
16+ // reactNativeDir = file("../node_modules/react-native")
17+ // The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
18+ // codegenDir = file("../node_modules/react-native-codegen")
19+ // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
20+ // cliFile = file("../node_modules/react-native/cli.js")
21+
22+ /* Variants */
23+ // The list of variants to that are debuggable. For those we're going to
24+ // skip the bundling of the JS bundle and the assets. By default is just 'debug'.
25+ // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
26+ // debuggableVariants = ["liteDebug", "prodDebug"]
27+
28+ /* Bundling */
29+ // A list containing the node command and its flags. Default is just 'node'.
30+ // nodeExecutableAndArgs = ["node"]
31+ //
32+ // The command to run when bundling. By default is 'bundle'
33+ // bundleCommand = "ram-bundle"
34+ //
35+ // The path to the CLI configuration file. Default is empty.
36+ // bundleConfig = file(../rn-cli.config.js)
37+ //
38+ // The name of the generated asset file containing your JS bundle
39+ // bundleAssetName = "MyApplication.android.bundle"
40+ //
41+ // The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
42+ // entryFile = file("../js/MyApplication.android.js")
43+ //
44+ // A list of extra flags to pass to the 'bundle' commands.
45+ // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
46+ // extraPackagerArgs = []
47+
48+ /* Hermes Commands */
49+ // The hermes compiler command to run. By default it is 'hermesc'
50+ // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
51+ //
52+ // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
53+ // hermesFlags = ["-O", "-output-source-map"]
54+ }
1155
56+ /**
57+ * Set this to true to create four separate APKs instead of one,
58+ * one for each native architecture. This is useful if you don't
59+ * use App Bundles (https://developer.android.com/guide/app-bundle/)
60+ * and want to have separate APKs to upload to the Play Store.
61+ */
1262def enableSeparateBuildPerCPUArchitecture = false
63+
64+ /**
65+ * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
66+ */
1367def enableProguardInReleaseBuilds = false
68+
69+ /**
70+ * The preferred build flavor of JavaScriptCore (JSC)
71+ *
72+ * For example, to use the international variant, you can use:
73+ * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
74+ *
75+ * The international variant includes ICU i18n library and necessary data
76+ * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
77+ * give correct results when using with locales other than en-US. Note that
78+ * this variant is about 6MiB larger per architecture than default.
79+ */
1480def jscFlavor = ' org.webkit:android-jsc:+'
15- def enableHermes = project. ext. react. get(" enableHermes" , false );
1681
82+ /**
83+ * Private function to get the list of Native Architectures you want to build.
84+ * This reads the value from reactNativeArchitectures in your gradle.properties
85+ * file and works together with the --active-arch-only flag of react-native run-android.
86+ */
1787def reactNativeArchitectures () {
1888 def value = project. getProperties(). get(" reactNativeArchitectures" )
1989 return value ? value. split(" ," ) : [" armeabi-v7a" , " x86" , " x86_64" , " arm64-v8a" ]
@@ -24,86 +94,13 @@ android {
2494
2595 compileSdkVersion rootProject. ext. compileSdkVersion
2696
27- // ? You can remove if you don't want to use JAVA Version 18
28- compileOptions {
29- sourceCompatibility JavaVersion . VERSION_1_8
30- targetCompatibility JavaVersion . VERSION_1_8
31- }
32-
97+ namespace " com.rntypescriptboilerplate"
3398 defaultConfig {
3499 applicationId " com.rntypescriptboilerplate"
35100 minSdkVersion rootProject. ext. minSdkVersion
36101 targetSdkVersion rootProject. ext. targetSdkVersion
37102 versionCode 1
38103 versionName " 1.0"
39- buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
40-
41- if (isNewArchitectureEnabled()) {
42- // We configure the NDK build only if you decide to opt-in for the New Architecture.
43- externalNativeBuild {
44- ndkBuild {
45- arguments " APP_PLATFORM=android-21" ,
46- " APP_STL=c++_shared" ,
47- " NDK_TOOLCHAIN_VERSION=clang" ,
48- " GENERATED_SRC_DIR=$buildDir /generated/source" ,
49- " PROJECT_BUILD_DIR=$buildDir " ,
50- " REACT_ANDROID_DIR=$rootDir /../node_modules/react-native/ReactAndroid" ,
51- " REACT_ANDROID_BUILD_DIR=$rootDir /../node_modules/react-native/ReactAndroid/build" ,
52- " NODE_MODULES_DIR=$rootDir /../node_modules"
53- cFlags " -Wall" , " -Werror" , " -fexceptions" , " -frtti" , " -DWITH_INSPECTOR=1"
54- cppFlags " -std=c++17"
55- // Make sure this target name is the same you specify inside the
56- // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
57- targets " rntypescriptboilerplate_appmodules"
58- }
59- }
60- if (! enableSeparateBuildPerCPUArchitecture) {
61- ndk {
62- abiFilters (* reactNativeArchitectures())
63- }
64- }
65- }
66- }
67-
68- if (isNewArchitectureEnabled()) {
69- // We configure the NDK build only if you decide to opt-in for the New Architecture.
70- externalNativeBuild {
71- ndkBuild {
72- path " $projectDir /src/main/jni/Android.mk"
73- }
74- }
75- def reactAndroidProjectDir = project(' :ReactAndroid' ). projectDir
76- def packageReactNdkDebugLibs = tasks. register(" packageReactNdkDebugLibs" , Copy ) {
77- dependsOn(" :ReactAndroid:packageReactNdkDebugLibsForBuck" )
78- from(" $reactAndroidProjectDir /src/main/jni/prebuilt/lib" )
79- into(" $buildDir /react-ndk/exported" )
80- }
81- def packageReactNdkReleaseLibs = tasks. register(" packageReactNdkReleaseLibs" , Copy ) {
82- dependsOn(" :ReactAndroid:packageReactNdkReleaseLibsForBuck" )
83- from(" $reactAndroidProjectDir /src/main/jni/prebuilt/lib" )
84- into(" $buildDir /react-ndk/exported" )
85- }
86- afterEvaluate {
87- // If you wish to add a custom TurboModule or component locally,
88- // you should uncomment this line.
89- // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
90- preDebugBuild. dependsOn(packageReactNdkDebugLibs)
91- preReleaseBuild. dependsOn(packageReactNdkReleaseLibs)
92-
93- // Due to a bug inside AGP, we have to explicitly set a dependency
94- // between configureNdkBuild* tasks and the preBuild tasks.
95- // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
96- configureNdkBuildRelease. dependsOn(preReleaseBuild)
97- configureNdkBuildDebug. dependsOn(preDebugBuild)
98- reactNativeArchitectures(). each { architecture ->
99- tasks. findByName(" configureNdkBuildDebug[${ architecture} ]" )?. configure {
100- dependsOn(" preDebugBuild" )
101- }
102- tasks. findByName(" configureNdkBuildRelease[${ architecture} ]" )?. configure {
103- dependsOn(" preReleaseBuild" )
104- }
105- }
106- }
107104 }
108105
109106 splits {
@@ -150,77 +147,25 @@ android {
150147
151148 }
152149 }
153-
154- packagingOptions {
155- pickFirst ' **/armeabi-v7a/libc++_shared.so'
156- pickFirst ' **/x86/libc++_shared.so'
157- pickFirst ' **/arm64-v8a/libc++_shared.so'
158- pickFirst ' **/x86_64/libc++_shared.so'
159- pickFirst ' **/x86/libjsc.so'
160- pickFirst ' **/armeabi-v7a/libjsc.so'
161- }
162150}
163151
164152dependencies {
165- implementation fileTree(dir : " libs" , include : [" *.jar" ])
166-
167- // noinspection GradleDynamicVersion
168- implementation " com.facebook.react:react-native:+" // From node_modules
169-
170- implementation " androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
153+ // The version of react-native is set by the React Native Gradle Plugin
154+ implementation(" com.facebook.react:react-android" )
171155
172- debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " ) {
173- exclude group :' com.facebook.fbjni'
174- }
156+ implementation(" androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" )
175157
158+ debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " )
176159 debugImplementation(" com.facebook.flipper:flipper-network-plugin:${ FLIPPER_VERSION} " ) {
177- exclude group :' com.facebook.flipper'
178160 exclude group :' com.squareup.okhttp3' , module :' okhttp'
179161 }
180162
181- debugImplementation(" com.facebook.flipper:flipper-fresco-plugin:${ FLIPPER_VERSION} " ) {
182- exclude group :' com.facebook.flipper'
183- }
184-
185- if (enableHermes) {
186- // noinspection GradleDynamicVersion
187- implementation(" com.facebook.react:hermes-engine:+" ) { // From node_modules
188- exclude group :' com.facebook.fbjni'
189- }
163+ debugImplementation(" com.facebook.flipper:flipper-fresco-plugin:${ FLIPPER_VERSION} " )
164+ if (hermesEnabled. toBoolean()) {
165+ implementation(" com.facebook.react:hermes-android" )
190166 } else {
191167 implementation jscFlavor
192168 }
193169}
194170
195- if (isNewArchitectureEnabled()) {
196- // If new architecture is enabled, we let you build RN from source
197- // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
198- // This will be applied to all the imported transtitive dependency.
199- configurations. all {
200- resolutionStrategy. dependencySubstitution {
201- substitute(module(" com.facebook.react:react-native" ))
202- .using(project(" :ReactAndroid" ))
203- .because(" On New Architecture we're building React Native from source" )
204- substitute(module(" com.facebook.react:hermes-engine" ))
205- .using(project(" :ReactAndroid:hermes-engine" ))
206- .because(" On New Architecture we're building Hermes from source" )
207- }
208- }
209- }
210-
211- // Run this once to be able to run the application with BUCK
212- // puts all compile dependencies into folder libs for BUCK to use
213- task copyDownloadableDepsToLibs (type : Copy ) {
214- from configurations. implementation
215- into ' libs'
216- }
217-
218171apply from : file(" ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle" ); applyNativeModulesAppBuildGradle(project)
219-
220- def isNewArchitectureEnabled () {
221- // To opt-in for the New Architecture, you can either:
222- // - Set `newArchEnabled` to true inside the `gradle.properties` file
223- // - Invoke gradle with `-newArchEnabled=true`
224- // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
225- return project. hasProperty(" newArchEnabled" ) && project. newArchEnabled == " true"
226- }
0 commit comments