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 : false , // 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,84 +93,13 @@ android {
134
93
135
94
compileSdkVersion rootProject. ext. compileSdkVersion
136
95
96
+ namespace " com.alacrity"
137
97
defaultConfig {
138
98
applicationId " com.alacrity"
139
99
minSdkVersion rootProject. ext. minSdkVersion
140
100
targetSdkVersion rootProject. ext. targetSdkVersion
141
101
versionCode 1
142
- versionName " 1.0"
143
- buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
144
-
145
- if (isNewArchitectureEnabled()) {
146
- // We configure the NDK build only if you decide to opt-in for the New Architecture.
147
- externalNativeBuild {
148
- ndkBuild {
149
- arguments " APP_PLATFORM=android-21" ,
150
- " APP_STL=c++_shared" ,
151
- " NDK_TOOLCHAIN_VERSION=clang" ,
152
- " GENERATED_SRC_DIR=$buildDir /generated/source" ,
153
- " PROJECT_BUILD_DIR=$buildDir " ,
154
- " REACT_ANDROID_DIR=$rootDir /../node_modules/react-native/ReactAndroid" ,
155
- " REACT_ANDROID_BUILD_DIR=$rootDir /../node_modules/react-native/ReactAndroid/build"
156
- cFlags " -Wall" , " -Werror" , " -fexceptions" , " -frtti" , " -DWITH_INSPECTOR=1"
157
- cppFlags " -std=c++17"
158
- // Make sure this target name is the same you specify inside the
159
- // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
160
- targets " alacrity_appmodules"
161
-
162
- // Fix for windows limit on number of character in file paths and in command lines
163
- if (Os . isFamily(Os . FAMILY_WINDOWS )) {
164
- arguments " NDK_APP_SHORT_COMMANDS=true"
165
- }
166
- }
167
- }
168
- if (! enableSeparateBuildPerCPUArchitecture) {
169
- ndk {
170
- abiFilters (* reactNativeArchitectures())
171
- }
172
- }
173
- }
174
- }
175
-
176
- if (isNewArchitectureEnabled()) {
177
- // We configure the NDK build only if you decide to opt-in for the New Architecture.
178
- externalNativeBuild {
179
- ndkBuild {
180
- path " $projectDir /src/main/jni/Android.mk"
181
- }
182
- }
183
- def reactAndroidProjectDir = project(' :ReactAndroid' ). projectDir
184
- def packageReactNdkDebugLibs = tasks. register(" packageReactNdkDebugLibs" , Copy ) {
185
- dependsOn(" :ReactAndroid:packageReactNdkDebugLibsForBuck" )
186
- from(" $reactAndroidProjectDir /src/main/jni/prebuilt/lib" )
187
- into(" $buildDir /react-ndk/exported" )
188
- }
189
- def packageReactNdkReleaseLibs = tasks. register(" packageReactNdkReleaseLibs" , Copy ) {
190
- dependsOn(" :ReactAndroid:packageReactNdkReleaseLibsForBuck" )
191
- from(" $reactAndroidProjectDir /src/main/jni/prebuilt/lib" )
192
- into(" $buildDir /react-ndk/exported" )
193
- }
194
- afterEvaluate {
195
- // If you wish to add a custom TurboModule or component locally,
196
- // you should uncomment this line.
197
- // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
198
- preDebugBuild. dependsOn(packageReactNdkDebugLibs)
199
- preReleaseBuild. dependsOn(packageReactNdkReleaseLibs)
200
-
201
- // Due to a bug inside AGP, we have to explicitly set a dependency
202
- // between configureNdkBuild* tasks and the preBuild tasks.
203
- // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
204
- configureNdkBuildRelease. dependsOn(preReleaseBuild)
205
- configureNdkBuildDebug. dependsOn(preDebugBuild)
206
- reactNativeArchitectures(). each { architecture ->
207
- tasks. findByName(" configureNdkBuildDebug[${ architecture} ]" )?. configure {
208
- dependsOn(" preDebugBuild" )
209
- }
210
- tasks. findByName(" configureNdkBuildRelease[${ architecture} ]" )?. configure {
211
- dependsOn(" preReleaseBuild" )
212
- }
213
- }
214
- }
102
+ versionName " 1.0.0"
215
103
}
216
104
217
105
splits {
@@ -261,60 +149,22 @@ android {
261
149
}
262
150
263
151
dependencies {
264
- implementation fileTree(dir : " libs" , include : [" *.jar" ])
265
-
266
- // noinspection GradleDynamicVersion
267
- implementation " com.facebook.react:react-native:+" // From node_modules
152
+ // The version of react-native is set by the React Native Gradle Plugin
153
+ implementation(" com.facebook.react:react-android" )
268
154
269
- implementation " androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
270
-
271
- debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " ) {
272
- exclude group :' com.facebook.fbjni'
273
- }
155
+ implementation(" androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" )
274
156
157
+ debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " )
275
158
debugImplementation(" com.facebook.flipper:flipper-network-plugin:${ FLIPPER_VERSION} " ) {
276
- exclude group :' com.facebook.flipper'
277
159
exclude group :' com.squareup.okhttp3' , module :' okhttp'
278
160
}
279
161
280
- debugImplementation(" com.facebook.flipper:flipper-fresco-plugin:${ FLIPPER_VERSION} " ) {
281
- exclude group :' com.facebook.flipper'
282
- }
283
-
284
- if (enableHermes) {
285
- def hermesPath = " ../../node_modules/hermes-engine/android/" ;
286
- debugImplementation files(hermesPath + " hermes-debug.aar" )
287
- releaseImplementation files(hermesPath + " hermes-release.aar" )
162
+ debugImplementation(" com.facebook.flipper:flipper-fresco-plugin:${ FLIPPER_VERSION} " )
163
+ if (hermesEnabled. toBoolean()) {
164
+ implementation(" com.facebook.react:hermes-android" )
288
165
} else {
289
166
implementation jscFlavor
290
167
}
291
168
}
292
169
293
- if (isNewArchitectureEnabled()) {
294
- // If new architecture is enabled, we let you build RN from source
295
- // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
296
- // This will be applied to all the imported transtitive dependency.
297
- configurations. all {
298
- resolutionStrategy. dependencySubstitution {
299
- substitute(module(" com.facebook.react:react-native" ))
300
- .using(project(" :ReactAndroid" )). because(" On New Architecture we're building React Native from source" )
301
- }
302
- }
303
- }
304
-
305
- // Run this once to be able to run the application with BUCK
306
- // puts all compile dependencies into folder libs for BUCK to use
307
- task copyDownloadableDepsToLibs (type : Copy ) {
308
- from configurations. implementation
309
- into ' libs'
310
- }
311
-
312
- apply from : file(" ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle" ); applyNativeModulesAppBuildGradle(project)
313
-
314
- def isNewArchitectureEnabled () {
315
- // To opt-in for the New Architecture, you can either:
316
- // - Set `newArchEnabled` to true inside the `gradle.properties` file
317
- // - Invoke gradle with `-newArchEnabled=true`
318
- // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
319
- return project. hasProperty(" newArchEnabled" ) && project. newArchEnabled == " true"
320
- }
170
+ apply from : file(" ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle" ); applyNativeModulesAppBuildGradle(project)
0 commit comments