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