xref: /expo/android/build.gradle (revision f2fbea2e)
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 = 31
8
9    dbFlowVersion = '4.2.4'
10    buildToolsVersion = '31.0.0'
11    kotlinVersion = '1.6.10'
12    gradlePluginVersion = '7.1.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-abi45_0_0/maven"
56    }
57    maven {
58      url "$rootDir/versioned-abis/expoview-abi44_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    // Using www.jitpack.io instead of plain jitpack.io due to
85    // https://github.com/jitpack/jitpack.io/issues/4002
86    maven { url "https://www.jitpack.io" }
87
88    // Want this last so that we never end up with a stale cache
89    mavenLocal()
90  }
91
92  configurations.all {
93    // WHEN_DISTRIBUTING_REMOVE_FROM_HERE
94    resolutionStrategy.dependencySubstitution {
95      substitute module("com.facebook.react:react-native:+") with project(":ReactAndroid")
96
97      // Gradle needs another hint (apart from plain dependency substitution)
98      // to know that it should first evaluate the replacing project before resolving
99      // classpaths etc. Without this block an error is thrown when running tests
100      // in a project that depends on react-native (eg. expo-updates):
101      //   > No matching configuration of project :ReactAndroid was found.
102      //   > The consumer was configured to find a runtime of a component,
103      //   > as well as attribute 'com.android.build.api.attributes.BuildTypeAttr'
104      //   > with value 'debug' but:
105      //   >   - None of the consumable configurations have attributes.
106      all {
107        if (requested.displayName == "com.facebook.react:react-native:+") {
108          evaluationDependsOn(":ReactAndroid")
109        }
110      }
111    }
112    // WHEN_DISTRIBUTING_REMOVE_TO_HERE
113  }
114}
115
116// This var needs to be defined outside any "remove_from_here" comment blocks
117// because the "*/" in there could affect the resulted code by closing the comment to early.
118def ktlintTarget = '**/*.kt'
119
120// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
121// We don't need linter on turtle.
122subprojects { project ->
123  if (project.name == "ReactAndroid") { return; }
124  if (project.name.startsWith("vendored_")) { return; }
125
126  plugins.apply("com.diffplug.spotless")
127  spotless {
128    format 'gradle', {
129      target '*.gradle'
130      trimTrailingWhitespace()
131      indentWithSpaces()
132      endWithNewline()
133    }
134    kotlin {
135      target(ktlintTarget)
136      // TODO: (barthap) Replace this with raw string when dropped shell app macros
137      // The star "*" signs interferes with slash "/" and treated wildcard path as comment ¯\_(ツ)_/¯
138      targetExclude(["**", "versioned/host/exp/exponent/modules/api", "**", "*.kt"].join("/"))
139      ktlint("0.41.0").userData([
140        "disabled_rules"           : "no-wildcard-imports,import-ordering",
141        "charset"                  : "utf-8",
142        "end_of_line"              : "lf",
143        "indent_size"              : "2",
144        "indent_style"             : "space",
145        "insert_final_newline"     : "true",
146        "tab_width"                : "2",
147        "trim_trailing_whitespace" : "true"
148      ])
149      trimTrailingWhitespace()
150      indentWithSpaces()
151      endWithNewline()
152    }
153  }
154}
155// WHEN_DISTRIBUTING_REMOVE_TO_HERE
156