1
1
apply plugin : " com.android.application"
2
+ apply plugin : " com.facebook.react"
2
3
3
4
import com.android.build.OutputFile
4
5
import org.apache.tools.ant.taskdefs.condition.Os
5
6
6
7
/**
7
- * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
8
- * and bundleReleaseJsAndAssets).
9
- * These basically call `react-native bundle` with the correct arguments during the Android build
10
- * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
11
- * bundle directly from the development server. Below you can see all the possible configurations
12
- * and their defaults. If you decide to add a configuration block, make sure to add it before the
13
- * `apply from: "../../node_modules/react-native/react.gradle"` line.
14
- *
15
- * project.ext.react = [
16
- * // the name of the generated asset file containing your JS bundle
17
- * bundleAssetName: "index.android.bundle",
18
- *
19
- * // the entry file for bundle generation
20
- * entryFile: "index.android.js",
21
- *
22
- * // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
23
- * bundleCommand: "ram-bundle",
24
- *
25
- * // whether to bundle JS and assets in debug mode
26
- * bundleInDebug: false,
27
- *
28
- * // whether to bundle JS and assets in release mode
29
- * bundleInRelease: true,
30
- *
31
- * // whether to bundle JS and assets in another build variant (if configured).
32
- * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
33
- * // The configuration property can be in the following formats
34
- * // 'bundleIn${productFlavor}${buildType}'
35
- * // 'bundleIn${buildType}'
36
- * // bundleInFreeDebug: true,
37
- * // bundleInPaidRelease: true,
38
- * // bundleInBeta: true,
39
- *
40
- * // whether to disable dev mode in custom build variants (by default only disabled in release)
41
- * // for BottomSheetExample: to disable dev mode in the staging build type (if configured)
42
- * devDisabledInStaging: true,
43
- * // The configuration property can be in the following formats
44
- * // 'devDisabledIn${productFlavor}${buildType}'
45
- * // 'devDisabledIn${buildType}'
46
- *
47
- * // the root of your project, i.e. where "package.json" lives
48
- * root: "../../",
49
- *
50
- * // where to put the JS bundle asset in debug mode
51
- * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
52
- *
53
- * // where to put the JS bundle asset in release mode
54
- * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
55
- *
56
- * // where to put drawable resources / React Native assets, e.g. the ones you use via
57
- * // require('./image.png')), in debug mode
58
- * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
59
- *
60
- * // where to put drawable resources / React Native assets, e.g. the ones you use via
61
- * // require('./image.png')), in release mode
62
- * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
63
- *
64
- * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
65
- * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
66
- * // date; if you have any other folders that you want to ignore for performance reasons (gradle
67
- * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
68
- * // for BottomSheetExample, you might want to remove it from here.
69
- * inputExcludes: ["android/**", "ios/**"],
70
- *
71
- * // override which node gets called and with what additional arguments
72
- * nodeExecutableAndArgs: ["node"],
73
- *
74
- * // supply additional arguments to the packager
75
- * extraPackagerArgs: []
76
- * ]
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.
77
10
*/
78
-
79
- project. ext. react = [
80
- enableHermes : true ,
81
- entryFile : " index.ts" ,
82
- ]
83
-
84
- apply from : " ../../node_modules/react-native/react.gradle"
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
+ }
85
55
86
56
/**
87
57
* Set this to true to create two separate APKs instead of one:
@@ -111,15 +81,6 @@ def enableProguardInReleaseBuilds = false
111
81
*/
112
82
def jscFlavor = ' org.webkit:android-jsc:+'
113
83
114
- /**
115
- * Whether to enable the Hermes VM.
116
- *
117
- * This should be set on project.ext.react and that value will be read here. If it is not set
118
- * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
119
- * and the benefits of using Hermes will therefore be sharply reduced.
120
- */
121
- def enableHermes = project. ext. react. get(" enableHermes" , false );
122
-
123
84
/**
124
85
* Architectures to build native code for in debug.
125
86
*/
@@ -137,68 +98,6 @@ android {
137
98
targetSdkVersion rootProject. ext. targetSdkVersion
138
99
versionCode 1
139
100
versionName " 1.0"
140
- buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
141
- if (isNewArchitectureEnabled()) {
142
- // We configure the NDK build only if you decide to opt-in for the New Architecture.
143
- externalNativeBuild {
144
- ndkBuild {
145
- arguments " APP_PLATFORM=android-21" ,
146
- " APP_STL=c++_shared" ,
147
- " NDK_TOOLCHAIN_VERSION=clang" ,
148
- " GENERATED_SRC_DIR=$buildDir /generated/source" ,
149
- " PROJECT_BUILD_DIR=$buildDir " ,
150
- " REACT_ANDROID_DIR=$rootDir /../node_modules/react-native/ReactAndroid" ,
151
- " REACT_ANDROID_BUILD_DIR=$rootDir /../node_modules/react-native/ReactAndroid/build" ,
152
- " NODE_MODULES_DIR=$rootDir /../node_modules"
153
- cFlags " -Wall" , " -Werror" , " -fexceptions" , " -frtti" , " -DWITH_INSPECTOR=1"
154
- cppFlags " -std=c++17"
155
- }
156
- }
157
- if (! enableSeparateBuildPerCPUArchitecture) {
158
- ndk {
159
- abiFilters (* reactNativeArchitectures())
160
- }
161
- }
162
- }
163
- }
164
- if (isNewArchitectureEnabled()) {
165
- // We configure the NDK build only if you decide to opt-in for the New Architecture.
166
- externalNativeBuild {
167
- ndkBuild {
168
- path " $projectDir /src/main/jni/Android.mk"
169
- }
170
- }
171
- def reactAndroidProjectDir = project(' :ReactAndroid' ). projectDir
172
- def packageReactNdkDebugLibs = tasks. register(" packageReactNdkDebugLibs" , Copy ) {
173
- dependsOn(" :ReactAndroid:packageReactNdkDebugLibsForBuck" )
174
- from(" $reactAndroidProjectDir /src/main/jni/prebuilt/lib" )
175
- into(" $buildDir /react-ndk/exported" )
176
- }
177
- def packageReactNdkReleaseLibs = tasks. register(" packageReactNdkReleaseLibs" , Copy ) {
178
- dependsOn(" :ReactAndroid:packageReactNdkReleaseLibsForBuck" )
179
- from(" $reactAndroidProjectDir /src/main/jni/prebuilt/lib" )
180
- into(" $buildDir /react-ndk/exported" )
181
- }
182
- afterEvaluate {
183
- // If you wish to add a custom TurboModule or component locally,
184
- // you should uncomment this line.
185
- // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
186
- preDebugBuild. dependsOn(packageReactNdkDebugLibs)
187
- preReleaseBuild. dependsOn(packageReactNdkReleaseLibs)
188
- // Due to a bug inside AGP, we have to explicitly set a dependency
189
- // between configureNdkBuild* tasks and the preBuild tasks.
190
- // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
191
- configureNdkBuildRelease. dependsOn(preReleaseBuild)
192
- configureNdkBuildDebug. dependsOn(preDebugBuild)
193
- reactNativeArchitectures(). each { architecture ->
194
- tasks. findByName(" configureNdkBuildDebug[${ architecture} ]" )?. configure {
195
- dependsOn(" preDebugBuild" )
196
- }
197
- tasks. findByName(" configureNdkBuildRelease[${ architecture} ]" )?. configure {
198
- dependsOn(" preReleaseBuild" )
199
- }
200
- }
201
- }
202
101
}
203
102
splits {
204
103
abi {
@@ -245,63 +144,24 @@ android {
245
144
}
246
145
247
146
dependencies {
248
- implementation fileTree(dir : " libs" , include : [" *.jar" ])
147
+ // The version of react-native is set by the React Native Gradle Plugin
148
+ implementation(" com.facebook.react:react-android" )
149
+
249
150
// noinspection GradleDynamicVersion
250
- implementation " com.facebook.react:react-native:+" // From node_modules
251
151
implementation " androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
252
152
implementation ' androidx.work:work-runtime-ktx:2.7.1'
253
153
254
- debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " ) {
255
- exclude group :' com.facebook.fbjni'
256
- }
154
+ debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " )
257
155
debugImplementation(" com.facebook.flipper:flipper-network-plugin:${ FLIPPER_VERSION} " ) {
258
- exclude group :' com.facebook.flipper'
259
156
exclude group :' com.squareup.okhttp3' , module :' okhttp'
260
157
}
261
- debugImplementation(" com.facebook.flipper:flipper-fresco-plugin:${ FLIPPER_VERSION} " ) {
262
- exclude group :' com.facebook.flipper'
263
- }
264
158
265
- if (enableHermes) {
266
- // noinspection GradleDynamicVersion
267
- implementation(" com.facebook.react:hermes-engine:+" ) { // From node_modules
268
- exclude group :' com.facebook.fbjni'
269
- }
159
+ debugImplementation(" com.facebook.flipper:flipper-fresco-plugin:${ FLIPPER_VERSION} " )
160
+ if (hermesEnabled. toBoolean()) {
161
+ implementation(" com.facebook.react:hermes-android" )
270
162
} else {
271
163
implementation jscFlavor
272
164
}
273
-
274
165
}
275
166
276
- if (isNewArchitectureEnabled()) {
277
- // If new architecture is enabled, we let you build RN from source
278
- // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
279
- // This will be applied to all the imported transtitive dependency.
280
- configurations. all {
281
- resolutionStrategy. dependencySubstitution {
282
- substitute(module(" com.facebook.react:react-native" ))
283
- .using(project(" :ReactAndroid" ))
284
- .because(" On New Architecture we're building React Native from source" )
285
- substitute(module(" com.facebook.react:hermes-engine" ))
286
- .using(project(" :ReactAndroid:hermes-engine" ))
287
- .because(" On New Architecture we're building Hermes from source" )
288
- }
289
- }
290
- }
291
-
292
- // Run this once to be able to run the application with BUCK
293
- // puts all compile dependencies into folder libs for BUCK to use
294
- task copyDownloadableDepsToLibs (type : Copy ) {
295
- from configurations. implementation
296
- into ' libs'
297
- }
298
-
299
- apply from : file(" ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle" ); applyNativeModulesAppBuildGradle(project)
300
-
301
- def isNewArchitectureEnabled () {
302
- // To opt-in for the New Architecture, you can either:
303
- // - Set `newArchEnabled` to true inside the `gradle.properties` file
304
- // - Invoke gradle with `-newArchEnabled=true`
305
- // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
306
- return project. hasProperty(" newArchEnabled" ) && project. newArchEnabled == " true"
307
- }
167
+ apply from : file(" ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle" ); applyNativeModulesAppBuildGradle(project)
0 commit comments