11apply plugin : " com.android.application"
2+ apply plugin : " org.jetbrains.kotlin.android"
3+ apply plugin : " com.facebook.react"
24
35import com.android.build.OutputFile
46import org.apache.tools.ant.taskdefs.condition.Os
@@ -78,13 +80,6 @@ import org.apache.tools.ant.taskdefs.condition.Os
7880 * ]
7981 */
8082
81- project. ext. react = [
82- enableHermes : true , // clean and rebuild if changing
83- entryFile : " index.tsx"
84- ]
85-
86- apply from : " ../../node_modules/react-native/react.gradle"
87-
8883/**
8984 * Set this to true to create two separate APKs instead of one:
9085 * - An APK that only works on ARM devices
@@ -113,103 +108,18 @@ def enableProguardInReleaseBuilds = false
113108 */
114109def jscFlavor = ' org.webkit:android-jsc:+'
115110
116- /**
117- * Whether to enable the Hermes VM.
118- *
119- * This should be set on project.ext.react and that value will be read here. If it is not set
120- * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
121- * and the benefits of using Hermes will therefore be sharply reduced.
122- */
123- def enableHermes = project. ext. react. get(" enableHermes" , false );
124-
125- /**
126- * Architectures to build native code for.
127- */
128- def reactNativeArchitectures () {
129- def value = project. getProperties(). get(" reactNativeArchitectures" )
130- return value ? value. split(" ," ) : [" armeabi-v7a" , " x86" , " x86_64" , " arm64-v8a" ]
131- }
132-
133111android {
134112 ndkVersion rootProject. ext. ndkVersion
113+ buildToolsVersion rootProject. ext. buildToolsVersion
114+ compileSdk rootProject. ext. compileSdkVersion
135115
136- compileSdkVersion rootProject. ext. compileSdkVersion
137-
116+ namespace " com.geolocationexample"
138117 defaultConfig {
139118 applicationId " com.geolocationexample"
140119 minSdkVersion rootProject. ext. minSdkVersion
141120 targetSdkVersion rootProject. ext. targetSdkVersion
142121 versionCode 1
143122 versionName " 1.0"
144- buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
145-
146- if (isNewArchitectureEnabled()) {
147- // We configure the NDK build only if you decide to opt-in for the New Architecture.
148- externalNativeBuild {
149- cmake {
150- arguments " -DPROJECT_BUILD_DIR=$buildDir " ,
151- " -DREACT_ANDROID_DIR=$rootDir /../node_modules/react-native/ReactAndroid" ,
152- " -DREACT_ANDROID_BUILD_DIR=$rootDir /../node_modules/react-native/ReactAndroid/build" ,
153- " -DNODE_MODULES_DIR=$rootDir /../node_modules" ,
154- " -DANDROID_STL=c++_shared"
155- }
156- }
157- if (! enableSeparateBuildPerCPUArchitecture) {
158- ndk {
159- abiFilters (* reactNativeArchitectures())
160- }
161- }
162- }
163- }
164-
165- if (isNewArchitectureEnabled()) {
166- // We configure the NDK build only if you decide to opt-in for the New Architecture.
167- externalNativeBuild {
168- cmake {
169- path " $projectDir /src/main/jni/CMakeLists.txt"
170- }
171- }
172- def reactAndroidProjectDir = project(' :ReactAndroid' ). projectDir
173- def packageReactNdkDebugLibs = tasks. register(" packageReactNdkDebugLibs" , Copy ) {
174- dependsOn(" :ReactAndroid:packageReactNdkDebugLibsForBuck" )
175- from(" $reactAndroidProjectDir /src/main/jni/prebuilt/lib" )
176- into(" $buildDir /react-ndk/exported" )
177- }
178- def packageReactNdkReleaseLibs = tasks. register(" packageReactNdkReleaseLibs" , Copy ) {
179- dependsOn(" :ReactAndroid:packageReactNdkReleaseLibsForBuck" )
180- from(" $reactAndroidProjectDir /src/main/jni/prebuilt/lib" )
181- into(" $buildDir /react-ndk/exported" )
182- }
183- afterEvaluate {
184- // If you wish to add a custom TurboModule or component locally,
185- // you should uncomment this line.
186- // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
187- preDebugBuild. dependsOn(packageReactNdkDebugLibs)
188- preReleaseBuild. dependsOn(packageReactNdkReleaseLibs)
189-
190- // Due to a bug inside AGP, we have to explicitly set a dependency
191- // between configureCMakeDebug* tasks and the preBuild tasks.
192- // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
193- configureCMakeRelWithDebInfo. dependsOn(preReleaseBuild)
194- configureCMakeDebug. dependsOn(preDebugBuild)
195- reactNativeArchitectures(). each { architecture ->
196- tasks. findByName(" configureCMakeDebug[${ architecture} ]" )?. configure {
197- dependsOn(" preDebugBuild" )
198- }
199- tasks. findByName(" configureCMakeRelWithDebInfo[${ architecture} ]" )?. configure {
200- dependsOn(" preReleaseBuild" )
201- }
202- }
203- }
204- }
205-
206- splits {
207- abi {
208- reset()
209- enable enableSeparateBuildPerCPUArchitecture
210- universalApk false // If true, also generate a universal APK
211- include (* reactNativeArchitectures())
212- }
213123 }
214124 signingConfigs {
215125 debug {
@@ -231,83 +141,18 @@ android {
231141 proguardFiles getDefaultProguardFile(" proguard-android.txt" ), " proguard-rules.pro"
232142 }
233143 }
234-
235- // applicationVariants are e.g. debug, release
236- applicationVariants. all { variant ->
237- variant. outputs. each { output ->
238- // For each separate APK per architecture, set a unique version code as described here:
239- // https://developer.android.com/studio/build/configure-apk-splits.html
240- // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
241- def versionCodes = [" armeabi-v7a" : 1 , " x86" : 2 , " arm64-v8a" : 3 , " x86_64" : 4 ]
242- def abi = output. getFilter(OutputFile . ABI )
243- if (abi != null ) { // null for the universal-debug, universal-release variants
244- output. versionCodeOverride =
245- defaultConfig. versionCode * 1000 + versionCodes. get(abi)
246- }
247-
248- }
249- }
250144}
251145
252146dependencies {
253- implementation fileTree(dir : " libs" , include : [" *.jar" ])
254-
255- // noinspection GradleDynamicVersion
256- implementation " com.facebook.react:react-native:+" // From node_modules
147+ implementation(" com.facebook.react:react-android" )
148+ implementation(" com.facebook.react:flipper-integration" )
257149 implementation " androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
258150
259- debugImplementation(" com.facebook.flipper:flipper:${ FLIPPER_VERSION} " ) {
260- exclude group :' com.facebook.fbjni'
261- }
262-
263- debugImplementation(" com.facebook.flipper:flipper-network-plugin:${ FLIPPER_VERSION} " ) {
264- exclude group :' com.facebook.flipper'
265- exclude group :' com.squareup.okhttp3' , module :' okhttp'
266- }
267-
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- }
151+ if (hermesEnabled. toBoolean()) {
152+ implementation(" com.facebook.react:hermes-android" )
277153 } else {
278154 implementation jscFlavor
279155 }
280156}
281157
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-
305158apply 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- }
0 commit comments