xref: /expo/android/build.gradle (revision 7aeb2b0c)
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 = 30
7    compileSdkVersion = 30
8
9    dbFlowVersion = '4.2.4'
10    buildToolsVersion = '30.0.2'
11    kotlinVersion = '1.6.10'
12    gradlePluginVersion = '4.2.2'
13    gradleDownloadTaskVersion = '3.4.3'
14    repositoryUrl = "file:${System.env.HOME}/.m2/repository/"
15  }
16  repositories {
17    google()
18    mavenCentral()
19  }
20  dependencies {
21    classpath "com.android.tools.build:gradle:${gradlePluginVersion}"
22    classpath 'com.google.gms:google-services:4.3.5'
23    classpath "de.undercouch:gradle-download-task:$gradleDownloadTaskVersion"
24    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
25  }
26}
27
28// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
29// We don't need linter on turtle.
30plugins {
31  id "com.diffplug.spotless" version "5.14.1"
32}
33// WHEN_DISTRIBUTING_REMOVE_TO_HERE
34
35allprojects {
36  repositories {
37    // For non-detach
38    maven {
39      url "$rootDir/maven"
40    }
41    // For old expoviews to work
42    maven {
43      url "$rootDir/versioned-abis/expoview-abi44_0_0/maven"
44    }
45    maven {
46      url "$rootDir/versioned-abis/expoview-abi43_0_0/maven"
47    }
48    maven {
49      url "$rootDir/versioned-abis/expoview-abi42_0_0/maven"
50    }
51    maven {
52      url "$rootDir/versioned-abis/maven"
53    }
54    google()
55    mavenCentral {
56      // We don't want to fetch react-native from Maven Central as there are
57      // older versions over there.
58      content {
59        excludeGroup "com.facebook.react"
60      }
61    }
62    jcenter()
63    maven {
64      // Local Maven repo containing AARs with JSC built for Android
65      url "$rootDir/../node_modules/jsc-android/dist"
66    }
67    maven {
68      // Local expo-camera Maven repo containing our slightly modified
69      // Google's cameraview from expo/cameraview.
70      url "$rootDir/../packages/expo-camera/android/maven"
71    }
72    flatDir {
73      dirs 'libs'
74      // dirs project(':expoview').file('libs')
75    }
76    // Using www.jitpack.io instead of plain jitpack.io due to
77    // https://github.com/jitpack/jitpack.io/issues/4002
78    maven { url "https://www.jitpack.io" }
79
80    // Want this last so that we never end up with a stale cache
81    mavenLocal()
82  }
83
84  // used to override ndk path/version from env variables on CI
85  ext["ANDROID_NDK_PATH"] = null
86  if (System.getenv("LOCAL_ANDROID_NDK_VERSION") != null) {
87    setProperty("ANDROID_NDK_VERSION", System.getenv("LOCAL_ANDROID_NDK_VERSION"))
88    ext["ANDROID_NDK_PATH"] =  System.getenv("ANDROID_NDK")
89  }
90
91  configurations.all {
92    // WHEN_DISTRIBUTING_REMOVE_FROM_HERE
93    resolutionStrategy.dependencySubstitution {
94      substitute module("com.facebook.react:react-native:+") with project(":ReactAndroid")
95
96      // Gradle needs another hint (apart from plain dependency substitution)
97      // to know that it should first evaluate the replacing project before resolving
98      // classpaths etc. Without this block an error is thrown when running tests
99      // in a project that depends on react-native (eg. expo-updates):
100      //   > No matching configuration of project :ReactAndroid was found.
101      //   > The consumer was configured to find a runtime of a component,
102      //   > as well as attribute 'com.android.build.api.attributes.BuildTypeAttr'
103      //   > with value 'debug' but:
104      //   >   - None of the consumable configurations have attributes.
105      all {
106        if (requested.displayName == "com.facebook.react:react-native:+") {
107          evaluationDependsOn(":ReactAndroid")
108        }
109      }
110    }
111    // WHEN_DISTRIBUTING_REMOVE_TO_HERE
112  }
113}
114
115// This var needs to be defined outside any "remove_from_here" comment blocks
116// because the "*/" in there could affect the resulted code by closing the comment to early.
117def ktlintTarget = '**/*.kt'
118
119// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
120// We don't need linter on turtle.
121subprojects {
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      ktlint("0.41.0").userData([
133        "disabled_rules"           : "no-wildcard-imports,import-ordering",
134        "charset"                  : "utf-8",
135        "end_of_line"              : "lf",
136        "indent_size"              : "2",
137        "indent_style"             : "space",
138        "insert_final_newline"     : "true",
139        "tab_width"                : "2",
140        "trim_trailing_whitespace" : "true"
141      ])
142      trimTrailingWhitespace()
143      indentWithSpaces()
144      endWithNewline()
145    }
146  }
147}
148// WHEN_DISTRIBUTING_REMOVE_TO_HERE
149