xref: /expo/android/build.gradle (revision 600cd0cc)
1// Top-level build file where you can add configuration options common to all sub-projects/modules.
2import com.android.build.api.variant.AndroidComponentsExtension
3
4buildscript {
5  ext {
6    minSdkVersion = 21
7    targetSdkVersion = 33
8    compileSdkVersion = 33
9
10    dbFlowVersion = '4.2.4'
11    buildToolsVersion = '33.0.0'
12    kotlinVersion = '1.8.10'
13    gradlePluginVersion = '7.4.1'
14    gradleDownloadTaskVersion = '5.0.1'
15    repositoryUrl = "file:${System.env.HOME}/.m2/repository/"
16
17    // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
18    ndkVersion = "23.1.7779620"
19  }
20  repositories {
21    google()
22    mavenCentral()
23  }
24  dependencies {
25    classpath "com.android.tools.build:gradle:${gradlePluginVersion}"
26    classpath 'com.google.gms:google-services:4.3.5'
27    classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.4'
28    classpath "de.undercouch:gradle-download-task:$gradleDownloadTaskVersion"
29    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
30
31    // WHEN_DISTRIBUTING_REMOVE_FROM_HERE
32    classpath "com.facebook.react:react-native-gradle-plugin"
33    // WHEN_DISTRIBUTING_REMOVE_TO_HERE
34  }
35}
36
37// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
38// We don't need linter on turtle.
39plugins {
40  id "com.diffplug.spotless" version "5.14.1"
41}
42// WHEN_DISTRIBUTING_REMOVE_TO_HERE
43
44def reactProperties = new Properties()
45file("${project(':packages:react-native:ReactAndroid').projectDir}/gradle.properties").withInputStream { reactProperties.load(it) }
46
47allprojects {
48  repositories {
49    // For non-detach
50    maven {
51      url "$rootDir/maven"
52    }
53    // For old expoviews to work
54    maven {
55      url "$rootDir/versioned-abis/expoview-abi48_0_0/maven"
56    }
57    maven {
58      url "$rootDir/versioned-abis/expoview-abi47_0_0/maven"
59    }
60    maven {
61      url "$rootDir/versioned-abis/maven"
62    }
63    google()
64    mavenCentral {
65      // We don't want to fetch react-native from Maven Central as there are
66      // older versions over there.
67      content {
68        excludeGroup "com.facebook.react"
69      }
70    }
71    maven {
72      // Local Maven repo containing AARs with JSC built for Android
73      url "$rootDir/../node_modules/jsc-android/dist"
74    }
75    maven {
76      // Local expo-camera Maven repo containing our slightly modified
77      // Google's cameraview from expo/cameraview.
78      url "$rootDir/../packages/expo-camera/android/maven"
79    }
80    flatDir {
81      dirs 'libs'
82      // dirs project(':expoview').file('libs')
83    }
84    maven { url "https://jitpack.io" }
85
86    // Want this last so that we never end up with a stale cache
87    mavenLocal()
88  }
89
90  configurations.all {
91    // WHEN_DISTRIBUTING_REMOVE_FROM_HERE
92    resolutionStrategy.dependencySubstitution {
93      substitute(module("com.facebook.react:react-native"))
94        .using(project(":packages:react-native:ReactAndroid"))
95        .because("Building React Native from source")
96      substitute(module("com.facebook.react:react-native:+"))
97        .using(project(":packages:react-native:ReactAndroid"))
98        .because("Building React Native from source")
99      substitute(module("com.facebook.react:react-android"))
100        .using(project(":packages:react-native:ReactAndroid"))
101        .because("Building React Native from source")
102    }
103    // WHEN_DISTRIBUTING_REMOVE_TO_HERE
104
105    resolutionStrategy.force(
106      "com.facebook.fresco:fbcore:${reactProperties.getProperty('FRESCO_VERSION')}",
107      "com.facebook.fresco:fresco:${reactProperties.getProperty('FRESCO_VERSION')}",
108      "com.facebook.fresco:imagepipeline-okhttp3:${reactProperties.getProperty('FRESCO_VERSION')}",
109      "com.facebook.fresco:ui-common:${reactProperties.getProperty('FRESCO_VERSION')}",
110    )
111  }
112}
113
114// to prevent duplicated lib error, pick first of libc++_shared.so and libfbjni.so for instrumented tests
115allprojects { subProject ->
116  subProject.afterEvaluate {
117    def androidComponents = subProject.extensions.findByType(AndroidComponentsExtension.class)
118    androidComponents?.with {
119      onVariants(selector().all()) {
120        getAndroidTest()?.packaging?.jniLibs?.pickFirsts?.addAll([
121          "**/libc++_shared.so",
122          "**/libfbjni.so",
123        ])
124      }
125    }
126  }
127}
128
129// This var needs to be defined outside any "remove_from_here" comment blocks
130// because the "*/" in there could affect the resulted code by closing the comment to early.
131def ktlintTarget = '**/*.kt'
132
133// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
134// We don't need linter on turtle.
135subprojects { project ->
136  if (project.name == "ReactAndroid") { return; }
137  if (project.name.startsWith("vendored_")) { return; }
138
139  plugins.apply("com.diffplug.spotless")
140  spotless {
141    format 'gradle', {
142      target '*.gradle'
143      trimTrailingWhitespace()
144      indentWithSpaces()
145      endWithNewline()
146    }
147    kotlin {
148      target(ktlintTarget)
149      // TODO: (barthap) Replace this with raw string when dropped shell app macros
150      // The star "*" signs interferes with slash "/" and treated wildcard path as comment ¯\_(ツ)_/¯
151      targetExclude(["**", "versioned/host/exp/exponent/modules/api", "**", "*.kt"].join("/"))
152      ktlint("0.41.0").userData([
153        "disabled_rules"           : "no-wildcard-imports,import-ordering",
154        "charset"                  : "utf-8",
155        "end_of_line"              : "lf",
156        "indent_size"              : "2",
157        "indent_style"             : "space",
158        "insert_final_newline"     : "true",
159        "tab_width"                : "2",
160        "trim_trailing_whitespace" : "true"
161      ])
162      trimTrailingWhitespace()
163      indentWithSpaces()
164      endWithNewline()
165    }
166  }
167}
168// WHEN_DISTRIBUTING_REMOVE_TO_HERE
169