xref: /expo/android/build.gradle (revision c615fa2e)
1// Top-level build file where you can add configuration options common to all sub-projects/modules.
2import com.android.build.api.variant.AndroidComponentsExtension
3
4buildscript {
5  ext {
6    minSdkVersion = 21
7    targetSdkVersion = 33
8    compileSdkVersion = 33
9
10    dbFlowVersion = '4.2.4'
11    buildToolsVersion = '33.0.0'
12    kotlinVersion = '1.6.10'
13    gradlePluginVersion = '7.3.1'
14    gradleDownloadTaskVersion = '5.0.1'
15    repositoryUrl = "file:${System.env.HOME}/.m2/repository/"
16
17    // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
18    ndkVersion = "23.1.7779620"
19  }
20  repositories {
21    google()
22    mavenCentral()
23  }
24  dependencies {
25    classpath "com.android.tools.build:gradle:${gradlePluginVersion}"
26    classpath 'com.google.gms:google-services:4.3.5'
27    classpath "de.undercouch:gradle-download-task:$gradleDownloadTaskVersion"
28    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
29
30    // WHEN_DISTRIBUTING_REMOVE_FROM_HERE
31    classpath "com.facebook.react:react-native-gradle-plugin"
32    // WHEN_DISTRIBUTING_REMOVE_TO_HERE
33  }
34}
35
36// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
37// We don't need linter on turtle.
38plugins {
39  id "com.diffplug.spotless" version "5.14.1"
40}
41// WHEN_DISTRIBUTING_REMOVE_TO_HERE
42
43allprojects {
44  repositories {
45    // For non-detach
46    maven {
47      url "$rootDir/maven"
48    }
49    // For old expoviews to work
50    maven {
51      url "$rootDir/versioned-abis/expoview-abi47_0_0/maven"
52    }
53    maven {
54      url "$rootDir/versioned-abis/expoview-abi46_0_0/maven"
55    }
56    maven {
57      url "$rootDir/versioned-abis/maven"
58    }
59    google()
60    mavenCentral {
61      // We don't want to fetch react-native from Maven Central as there are
62      // older versions over there.
63      content {
64        excludeGroup "com.facebook.react"
65      }
66    }
67    maven {
68      // Local Maven repo containing AARs with JSC built for Android
69      url "$rootDir/../node_modules/jsc-android/dist"
70    }
71    maven {
72      // Local expo-camera Maven repo containing our slightly modified
73      // Google's cameraview from expo/cameraview.
74      url "$rootDir/../packages/expo-camera/android/maven"
75    }
76    flatDir {
77      dirs 'libs'
78      // dirs project(':expoview').file('libs')
79    }
80    maven { url "https://jitpack.io" }
81
82    // Want this last so that we never end up with a stale cache
83    mavenLocal()
84  }
85
86  configurations.all {
87    // WHEN_DISTRIBUTING_REMOVE_FROM_HERE
88    resolutionStrategy.dependencySubstitution {
89      substitute(module("com.facebook.react:react-native"))
90        .using(project(":ReactAndroid"))
91        .because("Building React Native from source")
92      substitute(module("com.facebook.react:react-native:+"))
93        .using(project(":ReactAndroid"))
94        .because("Building React Native from source")
95      substitute(module("com.facebook.react:react-android"))
96        .using(project(":ReactAndroid"))
97        .because("Building React Native from source")
98    }
99    // WHEN_DISTRIBUTING_REMOVE_TO_HERE
100  }
101}
102
103// to prevent duplicated lib error, pick first of libc++_shared.so and libfbjni.so for instrumented tests
104allprojects { subProject ->
105  subProject.afterEvaluate {
106    def androidComponents = subProject.extensions.findByType(AndroidComponentsExtension.class)
107    androidComponents?.with {
108      onVariants(selector().all()) {
109        getAndroidTest()?.packaging?.jniLibs?.pickFirsts?.addAll([
110          "**/libc++_shared.so",
111          "**/libfbjni.so",
112        ])
113      }
114    }
115  }
116}
117
118// This var needs to be defined outside any "remove_from_here" comment blocks
119// because the "*/" in there could affect the resulted code by closing the comment to early.
120def ktlintTarget = '**/*.kt'
121
122// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
123// We don't need linter on turtle.
124subprojects { project ->
125  if (project.name == "ReactAndroid") { return; }
126  if (project.name.startsWith("vendored_")) { return; }
127
128  plugins.apply("com.diffplug.spotless")
129  spotless {
130    format 'gradle', {
131      target '*.gradle'
132      trimTrailingWhitespace()
133      indentWithSpaces()
134      endWithNewline()
135    }
136    kotlin {
137      target(ktlintTarget)
138      // TODO: (barthap) Replace this with raw string when dropped shell app macros
139      // The star "*" signs interferes with slash "/" and treated wildcard path as comment ¯\_(ツ)_/¯
140      targetExclude(["**", "versioned/host/exp/exponent/modules/api", "**", "*.kt"].join("/"))
141      ktlint("0.41.0").userData([
142        "disabled_rules"           : "no-wildcard-imports,import-ordering",
143        "charset"                  : "utf-8",
144        "end_of_line"              : "lf",
145        "indent_size"              : "2",
146        "indent_style"             : "space",
147        "insert_final_newline"     : "true",
148        "tab_width"                : "2",
149        "trim_trailing_whitespace" : "true"
150      ])
151      trimTrailingWhitespace()
152      indentWithSpaces()
153      endWithNewline()
154    }
155  }
156}
157// WHEN_DISTRIBUTING_REMOVE_TO_HERE
158