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