1- apply plugin : ' com.android.application'
2- apply plugin : ' kotlin-android '
1+ apply plugin : " com.android.application"
2+ apply plugin : " com.facebook.react "
33
44import com.android.build.OutputFile
55
66/**
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.
799 */
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+ }
8654
8755/**
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.
9460 */
9561def enableSeparateBuildPerCPUArchitecture = false
9662
9763/**
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.
9965 */
10066def enableProguardInReleaseBuilds = false
10167
10268/**
103- * The preferred build flavor of JavaScriptCore.
69+ * The preferred build flavor of JavaScriptCore (JSC)
10470 *
10571 * For example, to use the international variant, you can use:
10672 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
10773 *
10874 * The international variant includes ICU i18n library and necessary data
10975 * 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
11177 * this variant is about 6MiB larger per architecture than default.
11278 */
11379def jscFlavor = ' org.webkit:android-jsc:+'
11480
11581/**
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 in debug.
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.
12685 */
127- def nativeArchitectures = project. getProperties(). get(" reactNativeDebugArchitectures" )
86+ def reactNativeArchitectures () {
87+ def value = project. getProperties(). get(" reactNativeArchitectures" )
88+ return value ? value. split(" ," ) : [" armeabi-v7a" , " x86" , " x86_64" , " arm64-v8a" ]
89+ }
12890
12991android {
13092 ndkVersion rootProject. ext. ndkVersion
13193
13294 compileSdkVersion rootProject. ext. compileSdkVersion
13395
96+ namespace " com.example"
13497 defaultConfig {
135- applicationId ' com.example'
98+ applicationId " com.example"
13699 minSdkVersion rootProject. ext. minSdkVersion
137100 targetSdkVersion rootProject. ext. targetSdkVersion
138101 versionCode 1
139- versionName ' 1.0'
102+ versionName " 1.0"
140103 }
104+
141105 splits {
142106 abi {
143107 reset()
144108 enable enableSeparateBuildPerCPUArchitecture
145109 universalApk false // If true, also generate a universal APK
146- include ' armeabi-v7a ' , ' x86 ' , ' arm64-v8a ' , ' x86_64 '
110+ include ( * reactNativeArchitectures())
147111 }
148112 }
149113 signingConfigs {
@@ -157,18 +121,13 @@ android {
157121 buildTypes {
158122 debug {
159123 signingConfig signingConfigs. debug
160- if (nativeArchitectures) {
161- ndk {
162- abiFilters nativeArchitectures. split(' ,' )
163- }
164- }
165124 }
166125 release {
167126 // Caution! In production, you need to generate your own keystore file.
168127 // see https://reactnative.dev/docs/signed-apk-android.
169128 signingConfig signingConfigs. debug
170129 minifyEnabled enableProguardInReleaseBuilds
171- proguardFiles getDefaultProguardFile(' proguard-android.txt' ), ' proguard-rules.pro'
130+ proguardFiles getDefaultProguardFile(" proguard-android.txt" ), " proguard-rules.pro"
172131 }
173132 }
174133
@@ -178,7 +137,7 @@ android {
178137 // For each separate APK per architecture, set a unique version code as described here:
179138 // https://developer.android.com/studio/build/configure-apk-splits.html
180139 // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
181- def versionCodes = [' armeabi-v7a' : 1 , ' x86' : 2 , ' arm64-v8a' : 3 , ' x86_64' : 4 ]
140+ def versionCodes = [" armeabi-v7a" : 1 , " x86" : 2 , " arm64-v8a" : 3 , " x86_64" : 4 ]
182141 def abi = output. getFilter(OutputFile . ABI )
183142 if (abi != null ) { // null for the universal-debug, universal-release variants
184143 output. versionCodeOverride =
@@ -190,39 +149,22 @@ android {
190149}
191150
192151dependencies {
193- implementation fileTree(dir : ' libs' , include : [' *.jar' ])
194- // noinspection GradleDynamicVersion
195- implementation ' com.facebook.react:react-native:+' // From node_modules
196-
197- implementation ' androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
152+ // The version of react-native is set by the React Native Gradle Plugin
153+ implementation(" com.facebook.react:react-android" )
198154
199- debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " ) {
200- exclude group : ' com.facebook.fbjni'
201- }
155+ implementation(" androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" )
202156
157+ debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " )
203158 debugImplementation(" com.facebook.flipper:flipper-network-plugin:${ FLIPPER_VERSION} " ) {
204- exclude group : ' com.facebook.flipper'
205- exclude group : ' com.squareup.okhttp3' , module : ' okhttp'
159+ exclude group :' com.squareup.okhttp3' , module :' okhttp'
206160 }
207161
208- debugImplementation(" com.facebook.flipper:flipper-fresco-plugin:${ FLIPPER_VERSION} " ) {
209- exclude group : ' com.facebook.flipper'
210- }
211-
212- if (enableHermes) {
213- def hermesPath = ' ../../node_modules/hermes-engine/android/' ;
214- debugImplementation files(hermesPath + ' hermes-debug.aar' )
215- 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" )
216165 } else {
217166 implementation jscFlavor
218167 }
219168}
220169
221- // Run this once to be able to run the application with BUCK
222- // puts all compile dependencies into folder libs for BUCK to use
223- task copyDownloadableDepsToLibs (type : Copy ) {
224- from configurations. implementation
225- into ' libs'
226- }
227-
228- apply from : file(' ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle' ); applyNativeModulesAppBuildGradle(project)
170+ apply from : file(" ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle" ); applyNativeModulesAppBuildGradle(project)
0 commit comments