xref: /expo/android/build.gradle (revision dfd15ebd)
1// Top-level build file where you can add configuration options common to all sub-projects/modules.
2
3buildscript {
4  ext {
5    minSdkVersion = 21
6    targetSdkVersion = 31
7    compileSdkVersion = 33
8
9    dbFlowVersion = '4.2.4'
10    buildToolsVersion = '31.0.0'
11    kotlinVersion = '1.6.10'
12    gradlePluginVersion = '7.2.1'
13    gradleDownloadTaskVersion = '5.0.1'
14    repositoryUrl = "file:${System.env.HOME}/.m2/repository/"
15
16    if (System.properties['os.arch'] == "aarch64") {
17      // For M1 Users we need to use the NDK 24 which added support for aarch64
18      ndkVersion = "24.0.8215888"
19    } else {
20      // Otherwise we default to the side-by-side NDK version from AGP.
21      ndkVersion = "21.4.7075529"
22    }
23  }
24  repositories {
25    google()
26    mavenCentral()
27  }
28  dependencies {
29    classpath "com.android.tools.build:gradle:${gradlePluginVersion}"
30    classpath 'com.google.gms:google-services:4.3.5'
31    classpath "de.undercouch:gradle-download-task:$gradleDownloadTaskVersion"
32    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
33
34    // WHEN_DISTRIBUTING_REMOVE_FROM_HERE
35    classpath "com.facebook.react:react-native-gradle-plugin"
36    // WHEN_DISTRIBUTING_REMOVE_TO_HERE
37  }
38}
39
40// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
41// We don't need linter on turtle.
42plugins {
43  id "com.diffplug.spotless" version "5.14.1"
44}
45// WHEN_DISTRIBUTING_REMOVE_TO_HERE
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-abi47_0_0/maven"
56    }
57    maven {
58      url "$rootDir/versioned-abis/expoview-abi46_0_0/maven"
59    }
60    maven {
61      url "$rootDir/versioned-abis/expoview-abi45_0_0/maven"
62    }
63    maven {
64      url "$rootDir/versioned-abis/maven"
65    }
66    google()
67    mavenCentral {
68      // We don't want to fetch react-native from Maven Central as there are
69      // older versions over there.
70      content {
71        excludeGroup "com.facebook.react"
72      }
73    }
74    maven {
75      // Local Maven repo containing AARs with JSC built for Android
76      url "$rootDir/../node_modules/jsc-android/dist"
77    }
78    maven {
79      // Local expo-camera Maven repo containing our slightly modified
80      // Google's cameraview from expo/cameraview.
81      url "$rootDir/../packages/expo-camera/android/maven"
82    }
83    flatDir {
84      dirs 'libs'
85      // dirs project(':expoview').file('libs')
86    }
87    maven { url "https://jitpack.io" }
88
89    // Want this last so that we never end up with a stale cache
90    mavenLocal()
91  }
92
93  configurations.all {
94    // WHEN_DISTRIBUTING_REMOVE_FROM_HERE
95    resolutionStrategy.dependencySubstitution {
96      substitute module("com.facebook.react:react-native:+") with project(":ReactAndroid")
97
98      // Gradle needs another hint (apart from plain dependency substitution)
99      // to know that it should first evaluate the replacing project before resolving
100      // classpaths etc. Without this block an error is thrown when running tests
101      // in a project that depends on react-native (eg. expo-updates):
102      //   > No matching configuration of project :ReactAndroid was found.
103      //   > The consumer was configured to find a runtime of a component,
104      //   > as well as attribute 'com.android.build.api.attributes.BuildTypeAttr'
105      //   > with value 'debug' but:
106      //   >   - None of the consumable configurations have attributes.
107      all {
108        if (requested.displayName == "com.facebook.react:react-native:+") {
109          evaluationDependsOn(":ReactAndroid")
110        }
111      }
112    }
113    // WHEN_DISTRIBUTING_REMOVE_TO_HERE
114  }
115}
116
117// This var needs to be defined outside any "remove_from_here" comment blocks
118// because the "*/" in there could affect the resulted code by closing the comment to early.
119def ktlintTarget = '**/*.kt'
120
121// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
122// We don't need linter on turtle.
123subprojects { project ->
124  if (project.name == "ReactAndroid") { return; }
125  if (project.name.startsWith("vendored_")) { return; }
126
127  plugins.apply("com.diffplug.spotless")
128  spotless {
129    format 'gradle', {
130      target '*.gradle'
131      trimTrailingWhitespace()
132      indentWithSpaces()
133      endWithNewline()
134    }
135    kotlin {
136      target(ktlintTarget)
137      // TODO: (barthap) Replace this with raw string when dropped shell app macros
138      // The star "*" signs interferes with slash "/" and treated wildcard path as comment ¯\_(ツ)_/¯
139      targetExclude(["**", "versioned/host/exp/exponent/modules/api", "**", "*.kt"].join("/"))
140      ktlint("0.41.0").userData([
141        "disabled_rules"           : "no-wildcard-imports,import-ordering",
142        "charset"                  : "utf-8",
143        "end_of_line"              : "lf",
144        "indent_size"              : "2",
145        "indent_style"             : "space",
146        "insert_final_newline"     : "true",
147        "tab_width"                : "2",
148        "trim_trailing_whitespace" : "true"
149      ])
150      trimTrailingWhitespace()
151      indentWithSpaces()
152      endWithNewline()
153    }
154  }
155}
156// WHEN_DISTRIBUTING_REMOVE_TO_HERE
157