1
1
apply plugin : " com.android.application"
2
+ apply plugin : " com.facebook.react"
2
3
3
4
import com.android.build.OutputFile
4
- import org.apache.tools.ant.taskdefs.condition.Os
5
5
6
6
/**
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. If none specified and
20
- * // "index.android.js" exists, it will be used. Otherwise "index.js" is
21
- * // default. Can be overridden with ENTRY_FILE environment variable.
22
- * entryFile: "index.android.js",
23
- *
24
- * // https://reactnative.dev/docs/performance#enable-the-ram-format
25
- * bundleCommand: "ram-bundle",
26
- *
27
- * // whether to bundle JS and assets in debug mode
28
- * bundleInDebug: false,
29
- *
30
- * // whether to bundle JS and assets in release mode
31
- * bundleInRelease: true,
32
- *
33
- * // whether to bundle JS and assets in another build variant (if configured).
34
- * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
35
- * // The configuration property can be in the following formats
36
- * // 'bundleIn${productFlavor}${buildType}'
37
- * // 'bundleIn${buildType}'
38
- * // bundleInFreeDebug: true,
39
- * // bundleInPaidRelease: true,
40
- * // bundleInBeta: true,
41
- *
42
- * // whether to disable dev mode in custom build variants (by default only disabled in release)
43
- * // for example: to disable dev mode in the staging build type (if configured)
44
- * devDisabledInStaging: true,
45
- * // The configuration property can be in the following formats
46
- * // 'devDisabledIn${productFlavor}${buildType}'
47
- * // 'devDisabledIn${buildType}'
48
- *
49
- * // the root of your project, i.e. where "package.json" lives
50
- * root: "../../",
51
- *
52
- * // where to put the JS bundle asset in debug mode
53
- * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
54
- *
55
- * // where to put the JS bundle asset in release mode
56
- * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
57
- *
58
- * // where to put drawable resources / React Native assets, e.g. the ones you use via
59
- * // require('./image.png')), in debug mode
60
- * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
61
- *
62
- * // where to put drawable resources / React Native assets, e.g. the ones you use via
63
- * // require('./image.png')), in release mode
64
- * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
65
- *
66
- * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
67
- * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
68
- * // date; if you have any other folders that you want to ignore for performance reasons (gradle
69
- * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
70
- * // for example, you might want to remove it from here.
71
- * inputExcludes: ["android/**", "ios/**"],
72
- *
73
- * // override which node gets called and with what additional arguments
74
- * nodeExecutableAndArgs: ["node"],
75
- *
76
- * // supply additional arguments to the packager
77
- * extraPackagerArgs: []
78
- * ]
7
+ * This is the configuration block to customize your React Native Android app.
8
+ * By default you don't need to apply any configuration, just uncomment the lines you need.
79
9
*/
80
-
81
- project. ext. react = [
82
- enableHermes : true , // clean and rebuild if changing
83
- ]
84
-
85
- apply from : " ../../node_modules/react-native/react.gradle"
10
+ react {
11
+ /* Folders */
12
+ // The root of your project, i.e. where "package.json" lives. Default is '..'
13
+ // root = file("../")
14
+ // The folder where the react-native NPM package is. Default is ../node_modules/react-native
15
+ // reactNativeDir = file("../node_modules/react-native")
16
+ // The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
17
+ // codegenDir = file("../node_modules/react-native-codegen")
18
+ // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
19
+ // cliFile = file("../node_modules/react-native/cli.js")
20
+
21
+ /* Variants */
22
+ // The list of variants to that are debuggable. For those we're going to
23
+ // skip the bundling of the JS bundle and the assets. By default is just 'debug'.
24
+ // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
25
+ // debuggableVariants = ["liteDebug", "prodDebug"]
26
+
27
+ /* Bundling */
28
+ // A list containing the node command and its flags. Default is just 'node'.
29
+ // nodeExecutableAndArgs = ["node"]
30
+ //
31
+ // The command to run when bundling. By default is 'bundle'
32
+ // bundleCommand = "ram-bundle"
33
+ //
34
+ // The path to the CLI configuration file. Default is empty.
35
+ // bundleConfig = file(../rn-cli.config.js)
36
+ //
37
+ // The name of the generated asset file containing your JS bundle
38
+ // bundleAssetName = "MyApplication.android.bundle"
39
+ //
40
+ // The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
41
+ // entryFile = file("../js/MyApplication.android.js")
42
+ //
43
+ // A list of extra flags to pass to the 'bundle' commands.
44
+ // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
45
+ // extraPackagerArgs = []
46
+
47
+ /* Hermes Commands */
48
+ // The hermes compiler command to run. By default it is 'hermesc'
49
+ // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
50
+ //
51
+ // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
52
+ // hermesFlags = ["-O", "-output-source-map"]
53
+ }
86
54
87
55
/**
88
- * Set this to true to create two separate APKs instead of one:
89
- * - An APK that only works on ARM devices
90
- * - An APK that only works on x86 devices
91
- * The advantage is the size of the APK is reduced by about 4MB.
92
- * Upload all the APKs to the Play Store and people will download
93
- * the correct one based on the CPU architecture of their device.
56
+ * Set this to true to create four separate APKs instead of one,
57
+ * one for each native architecture. This is useful if you don't
58
+ * use App Bundles (https://developer.android.com/guide/app-bundle/)
59
+ * and want to have separate APKs to upload to the Play Store.
94
60
*/
95
61
def enableSeparateBuildPerCPUArchitecture = false
96
62
97
63
/**
98
- * Run Proguard to shrink the Java bytecode in release builds .
64
+ * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
99
65
*/
100
66
def enableProguardInReleaseBuilds = false
101
67
102
68
/**
103
- * The preferred build flavor of JavaScriptCore.
69
+ * The preferred build flavor of JavaScriptCore (JSC)
104
70
*
105
71
* For example, to use the international variant, you can use:
106
72
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
107
73
*
108
74
* The international variant includes ICU i18n library and necessary data
109
75
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
110
- * give correct results when using with locales other than en-US. Note that
76
+ * give correct results when using with locales other than en-US. Note that
111
77
* this variant is about 6MiB larger per architecture than default.
112
78
*/
113
79
def jscFlavor = ' org.webkit:android-jsc:+'
114
80
115
81
/**
116
- * Whether to enable the Hermes VM.
117
- *
118
- * This should be set on project.ext.react and that value will be read here. If it is not set
119
- * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
120
- * and the benefits of using Hermes will therefore be sharply reduced.
121
- */
122
- def enableHermes = project. ext. react. get(" enableHermes" , false );
123
-
124
- /**
125
- * Architectures to build native code for.
82
+ * Private function to get the list of Native Architectures you want to build.
83
+ * This reads the value from reactNativeArchitectures in your gradle.properties
84
+ * file and works together with the --active-arch-only flag of react-native run-android.
126
85
*/
127
86
def reactNativeArchitectures () {
128
87
def value = project. getProperties(). get(" reactNativeArchitectures" )
@@ -134,72 +93,13 @@ android {
134
93
135
94
compileSdkVersion rootProject. ext. compileSdkVersion
136
95
96
+ namespace " com.fabricexample"
137
97
defaultConfig {
138
98
applicationId " com.fabricexample"
139
99
minSdkVersion rootProject. ext. minSdkVersion
140
100
targetSdkVersion rootProject. ext. targetSdkVersion
141
101
versionCode 1
142
102
versionName " 1.0"
143
- buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
144
-
145
- if (isNewArchitectureEnabled()) {
146
- // We configure the CMake build only if you decide to opt-in for the New Architecture.
147
- externalNativeBuild {
148
- cmake {
149
- arguments " -DPROJECT_BUILD_DIR=$buildDir " ,
150
- " -DREACT_ANDROID_DIR=$rootDir /../node_modules/react-native/ReactAndroid" ,
151
- " -DREACT_ANDROID_BUILD_DIR=$rootDir /../node_modules/react-native/ReactAndroid/build" ,
152
- " -DNODE_MODULES_DIR=$rootDir /../node_modules" ,
153
- " -DANDROID_STL=c++_shared"
154
- }
155
- }
156
- if (! enableSeparateBuildPerCPUArchitecture) {
157
- ndk {
158
- abiFilters (* reactNativeArchitectures())
159
- }
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
- cmake {
168
- path " $projectDir /src/main/jni/CMakeLists.txt"
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
-
189
- // Due to a bug inside AGP, we have to explicitly set a dependency
190
- // between configureCMakeDebug* tasks and the preBuild tasks.
191
- // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
192
- configureCMakeRelWithDebInfo. dependsOn(preReleaseBuild)
193
- configureCMakeDebug. dependsOn(preDebugBuild)
194
- reactNativeArchitectures(). each { architecture ->
195
- tasks. findByName(" configureCMakeDebug[${ architecture} ]" )?. configure {
196
- dependsOn(" preDebugBuild" )
197
- }
198
- tasks. findByName(" configureCMakeRelWithDebInfo[${ architecture} ]" )?. configure {
199
- dependsOn(" preReleaseBuild" )
200
- }
201
- }
202
- }
203
103
}
204
104
205
105
splits {
@@ -249,65 +149,22 @@ android {
249
149
}
250
150
251
151
dependencies {
252
- implementation fileTree(dir : " libs" , include : [" *.jar" ])
253
-
254
- // noinspection GradleDynamicVersion
255
- implementation " com.facebook.react:react-native:+" // From node_modules
256
-
257
- implementation " androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
152
+ // The version of react-native is set by the React Native Gradle Plugin
153
+ implementation(" com.facebook.react:react-android" )
258
154
259
- debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " ) {
260
- exclude group :' com.facebook.fbjni'
261
- }
155
+ implementation(" androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" )
262
156
157
+ debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " )
263
158
debugImplementation(" com.facebook.flipper:flipper-network-plugin:${ FLIPPER_VERSION} " ) {
264
- exclude group :' com.facebook.flipper'
265
159
exclude group :' com.squareup.okhttp3' , module :' okhttp'
266
160
}
267
161
268
- debugImplementation(" com.facebook.flipper:flipper-fresco-plugin:${ FLIPPER_VERSION} " ) {
269
- exclude group :' com.facebook.flipper'
270
- }
271
-
272
- if (enableHermes) {
273
- // noinspection GradleDynamicVersion
274
- implementation(" com.facebook.react:hermes-engine:+" ) { // From node_modules
275
- exclude group :' com.facebook.fbjni'
276
- }
162
+ debugImplementation(" com.facebook.flipper:flipper-fresco-plugin:${ FLIPPER_VERSION} " )
163
+ if (hermesEnabled. toBoolean()) {
164
+ implementation(" com.facebook.react:hermes-android" )
277
165
} else {
278
166
implementation jscFlavor
279
167
}
280
168
}
281
169
282
- if (isNewArchitectureEnabled()) {
283
- // If new architecture is enabled, we let you build RN from source
284
- // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
285
- // This will be applied to all the imported transtitive dependency.
286
- configurations. all {
287
- resolutionStrategy. dependencySubstitution {
288
- substitute(module(" com.facebook.react:react-native" ))
289
- .using(project(" :ReactAndroid" ))
290
- .because(" On New Architecture we're building React Native from source" )
291
- substitute(module(" com.facebook.react:hermes-engine" ))
292
- .using(project(" :ReactAndroid:hermes-engine" ))
293
- .because(" On New Architecture we're building Hermes from source" )
294
- }
295
- }
296
- }
297
-
298
- // Run this once to be able to run the application with BUCK
299
- // puts all compile dependencies into folder libs for BUCK to use
300
- task copyDownloadableDepsToLibs (type : Copy ) {
301
- from configurations. implementation
302
- into ' libs'
303
- }
304
-
305
- apply from : file(" ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle" ); applyNativeModulesAppBuildGradle(project)
306
-
307
- def isNewArchitectureEnabled () {
308
- // To opt-in for the New Architecture, you can either:
309
- // - Set `newArchEnabled` to true inside the `gradle.properties` file
310
- // - Invoke gradle with `-newArchEnabled=true`
311
- // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
312
- return project. hasProperty(" newArchEnabled" ) && project. newArchEnabled == " true"
313
- }
170
+ apply from : file(" ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle" ); applyNativeModulesAppBuildGradle(project)
0 commit comments