1
1
apply plugin : " com.android.application"
2
+ apply plugin : " com.facebook.react"
2
3
3
4
import com.android.build.OutputFile
4
5
5
6
/**
6
- * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7
- * and bundleReleaseJsAndAssets).
8
- * These basically call `react-native bundle` with the correct arguments during the Android build
9
- * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10
- * bundle directly from the development server. Below you can see all the possible configurations
11
- * and their defaults. If you decide to add a configuration block, make sure to add it before the
12
- * `apply from: "../../node_modules/react-native/react.gradle"` line.
13
- *
14
- * project.ext.react = [
15
- * // the name of the generated asset file containing your JS bundle
16
- * bundleAssetName: "index.android.bundle",
17
- *
18
- * // the entry file for bundle generation
19
- * entryFile: "index.android.js",
20
- *
21
- * // https://reactnative.dev/docs/performance#enable-the-ram-format
22
- * bundleCommand: "ram-bundle",
23
- *
24
- * // whether to bundle JS and assets in debug mode
25
- * bundleInDebug: false,
26
- *
27
- * // whether to bundle JS and assets in release mode
28
- * bundleInRelease: true,
29
- *
30
- * // whether to bundle JS and assets in another build variant (if configured).
31
- * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
32
- * // The configuration property can be in the following formats
33
- * // 'bundleIn${productFlavor}${buildType}'
34
- * // 'bundleIn${buildType}'
35
- * // bundleInFreeDebug: true,
36
- * // bundleInPaidRelease: true,
37
- * // bundleInBeta: true,
38
- *
39
- * // whether to disable dev mode in custom build variants (by default only disabled in release)
40
- * // for GraphExample: to disable dev mode in the staging build type (if configured)
41
- * devDisabledInStaging: true,
42
- * // The configuration property can be in the following formats
43
- * // 'devDisabledIn${productFlavor}${buildType}'
44
- * // 'devDisabledIn${buildType}'
45
- *
46
- * // the root of your project, i.e. where "package.json" lives
47
- * root: "../../",
48
- *
49
- * // where to put the JS bundle asset in debug mode
50
- * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
51
- *
52
- * // where to put the JS bundle asset in release mode
53
- * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
54
- *
55
- * // where to put drawable resources / React Native assets, e.g. the ones you use via
56
- * // require('./image.png')), in debug mode
57
- * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
58
- *
59
- * // where to put drawable resources / React Native assets, e.g. the ones you use via
60
- * // require('./image.png')), in release mode
61
- * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
62
- *
63
- * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
64
- * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
65
- * // date; if you have any other folders that you want to ignore for performance reasons (gradle
66
- * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
67
- * // for GraphExample, you might want to remove it from here.
68
- * inputExcludes: ["android/**", "ios/**"],
69
- *
70
- * // override which node gets called and with what additional arguments
71
- * nodeExecutableAndArgs: ["node"],
72
- *
73
- * // supply additional arguments to the packager
74
- * extraPackagerArgs: []
75
- * ]
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.
76
9
*/
77
-
78
- project. ext. react = [
79
- enableHermes : true , // clean and rebuild if changing
80
- entryFile : " index.js" ,
81
- ]
82
-
83
- 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
+ }
84
54
85
55
/**
86
- * Set this to true to create two separate APKs instead of one:
87
- * - An APK that only works on ARM devices
88
- * - An APK that only works on x86 devices
89
- * The advantage is the size of the APK is reduced by about 4MB.
90
- * Upload all the APKs to the Play Store and people will download
91
- * 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.
92
60
*/
93
61
def enableSeparateBuildPerCPUArchitecture = false
94
62
95
63
/**
96
- * 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.
97
65
*/
98
66
def enableProguardInReleaseBuilds = false
99
67
100
68
/**
101
- * The preferred build flavor of JavaScriptCore.
69
+ * The preferred build flavor of JavaScriptCore (JSC)
102
70
*
103
- * For GraphExample , to use the international variant, you can use:
71
+ * For example , to use the international variant, you can use:
104
72
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
105
73
*
106
74
* The international variant includes ICU i18n library and necessary data
107
75
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
108
- * 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
109
77
* this variant is about 6MiB larger per architecture than default.
110
78
*/
111
79
def jscFlavor = ' org.webkit:android-jsc:+'
112
80
113
81
/**
114
- * Whether to enable the Hermes VM.
115
- *
116
- * This should be set on project.ext.react and mirrored here. If it is not set
117
- * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
118
- * and the benefits of using Hermes will therefore be sharply reduced.
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.
119
85
*/
120
- def enableHermes = project. ext. react. get(" enableHermes" , false );
86
+ def reactNativeArchitectures () {
87
+ def value = project. getProperties(). get(" reactNativeArchitectures" )
88
+ return value ? value. split(" ," ) : [" armeabi-v7a" , " x86" , " x86_64" , " arm64-v8a" ]
89
+ }
121
90
122
91
android {
92
+ ndkVersion rootProject. ext. ndkVersion
93
+
123
94
compileSdkVersion rootProject. ext. compileSdkVersion
124
95
96
+ namespace " com.example.reactnativegraph"
125
97
defaultConfig {
126
98
applicationId " com.example.reactnativegraph"
127
99
minSdkVersion rootProject. ext. minSdkVersion
128
100
targetSdkVersion rootProject. ext. targetSdkVersion
129
101
versionCode 1
130
102
versionName " 1.0"
131
103
}
104
+
132
105
splits {
133
106
abi {
134
107
reset()
135
108
enable enableSeparateBuildPerCPUArchitecture
136
109
universalApk false // If true, also generate a universal APK
137
- include " armeabi-v7a " , " x86 " , " arm64-v8a " , " x86_64 "
110
+ include ( * reactNativeArchitectures())
138
111
}
139
112
}
140
113
signingConfigs {
@@ -148,11 +121,6 @@ android {
148
121
buildTypes {
149
122
debug {
150
123
signingConfig signingConfigs. debug
151
- if (nativeArchitectures) {
152
- ndk {
153
- abiFilters nativeArchitectures. split(' ,' )
154
- }
155
- }
156
124
}
157
125
release {
158
126
// Caution! In production, you need to generate your own keystore file.
@@ -162,55 +130,41 @@ android {
162
130
proguardFiles getDefaultProguardFile(" proguard-android.txt" ), " proguard-rules.pro"
163
131
}
164
132
}
133
+
165
134
// applicationVariants are e.g. debug, release
166
135
applicationVariants. all { variant ->
167
136
variant. outputs. each { output ->
168
137
// For each separate APK per architecture, set a unique version code as described here:
169
138
// https://developer.android.com/studio/build/configure-apk-splits.html
139
+ // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
170
140
def versionCodes = [" armeabi-v7a" : 1 , " x86" : 2 , " arm64-v8a" : 3 , " x86_64" : 4 ]
171
141
def abi = output. getFilter(OutputFile . ABI )
172
142
if (abi != null ) { // null for the universal-debug, universal-release variants
173
143
output. versionCodeOverride =
174
- versionCodes . get(abi) * 1048576 + defaultConfig . versionCode
144
+ defaultConfig . versionCode * 1000 + versionCodes . get(abi)
175
145
}
176
146
177
147
}
178
148
}
179
149
}
180
150
181
151
dependencies {
182
- implementation fileTree(dir : " libs" , include : [" *.jar" ])
183
- // noinspection GradleDynamicVersion
184
- 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" )
185
154
155
+ implementation(" androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" )
186
156
187
- implementation " androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
188
- debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " ) {
189
- exclude group :' com.facebook.fbjni'
190
- }
157
+ debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " )
191
158
debugImplementation(" com.facebook.flipper:flipper-network-plugin:${ FLIPPER_VERSION} " ) {
192
- exclude group :' com.facebook.flipper'
193
159
exclude group :' com.squareup.okhttp3' , module :' okhttp'
194
160
}
195
- debugImplementation(" com.facebook.flipper:flipper-fresco-plugin:${ FLIPPER_VERSION} " ) {
196
- exclude group :' com.facebook.flipper'
197
- }
198
161
199
- if (enableHermes) {
200
- def hermesPath = " ../../node_modules/hermes-engine/android/" ;
201
- debugImplementation files(hermesPath + " hermes-debug.aar" )
202
- 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" )
203
165
} else {
204
166
implementation jscFlavor
205
167
}
206
-
207
- }
208
-
209
- // Run this once to be able to run the application with BUCK
210
- // puts all compile dependencies into folder libs for BUCK to use
211
- task copyDownloadableDepsToLibs (type : Copy ) {
212
- from configurations. implementation
213
- into ' libs'
214
168
}
215
169
216
170
apply from : file(" ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle" ); applyNativeModulesAppBuildGradle(project)
0 commit comments