xref: /expo/android/build.gradle (revision 400d1b67)
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 = 23
7    targetSdkVersion = 33
8    compileSdkVersion = 33
9
10    dbFlowVersion = '4.2.4'
11    buildToolsVersion = '33.0.0'
12    kotlinVersion = '1.8.10'
13    gradlePluginVersion = '7.4.2'
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 'com.google.firebase:firebase-crashlytics-gradle:2.9.6'
28    classpath "de.undercouch:gradle-download-task:$gradleDownloadTaskVersion"
29    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
30
31    // WHEN_DISTRIBUTING_REMOVE_FROM_HERE
32    classpath "com.facebook.react:react-native-gradle-plugin"
33    // WHEN_DISTRIBUTING_REMOVE_TO_HERE
34  }
35}
36
37// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
38// We don't need linter on turtle.
39plugins {
40  id "com.diffplug.spotless" version "5.14.1"
41}
42// WHEN_DISTRIBUTING_REMOVE_TO_HERE
43
44def reactProperties = new Properties()
45file("${project(':packages:react-native:ReactAndroid').projectDir}/gradle.properties").withInputStream { reactProperties.load(it) }
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-abi49_0_0/maven"
56    }
57    maven {
58      url "$rootDir/versioned-abis/expoview-abi48_0_0/maven"
59    }
60    maven {
61      url "$rootDir/versioned-abis/expoview-abi47_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    maven { url "https://jitpack.io" }
88
89    // Want this last so that we never end up with a stale cache
90    mavenLocal()
91  }
92
93  configurations.all {
94    // WHEN_DISTRIBUTING_REMOVE_FROM_HERE
95    resolutionStrategy.dependencySubstitution {
96      substitute(module("com.facebook.react:react-native"))
97        .using(project(":packages:react-native:ReactAndroid"))
98        .because("Building React Native from source")
99      substitute(module("com.facebook.react:react-native:+"))
100        .using(project(":packages:react-native:ReactAndroid"))
101        .because("Building React Native from source")
102      substitute(module("com.facebook.react:react-android"))
103        .using(project(":packages:react-native:ReactAndroid"))
104        .because("Building React Native from source")
105    }
106    // WHEN_DISTRIBUTING_REMOVE_TO_HERE
107
108    resolutionStrategy.force(
109      "com.facebook.fresco:fbcore:${reactProperties.getProperty('FRESCO_VERSION')}",
110      "com.facebook.fresco:fresco:${reactProperties.getProperty('FRESCO_VERSION')}",
111      "com.facebook.fresco:imagepipeline-okhttp3:${reactProperties.getProperty('FRESCO_VERSION')}",
112      "com.facebook.fresco:ui-common:${reactProperties.getProperty('FRESCO_VERSION')}",
113    )
114  }
115}
116
117// to prevent duplicated lib error, pick first of libc++_shared.so and libfbjni.so for instrumented tests
118allprojects { subProject ->
119  subProject.afterEvaluate {
120    def androidComponents = subProject.extensions.findByType(AndroidComponentsExtension.class)
121    androidComponents?.with {
122      onVariants(selector().all()) {
123        getAndroidTest()?.packaging?.jniLibs?.pickFirsts?.addAll([
124          "**/libc++_shared.so",
125          "**/libfbjni.so",
126        ])
127      }
128    }
129  }
130}
131
132// This var needs to be defined outside any "remove_from_here" comment blocks
133// because the "*/" in there could affect the resulted code by closing the comment to early.
134def ktlintTarget = '**/*.kt'
135
136// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
137// We don't need linter on turtle.
138subprojects { project ->
139  if (project.name == "ReactAndroid") { return; }
140  if (project.name.startsWith("vendored_")) { return; }
141
142  plugins.apply("com.diffplug.spotless")
143  spotless {
144    format 'gradle', {
145      target '*.gradle'
146      trimTrailingWhitespace()
147      indentWithSpaces()
148      endWithNewline()
149    }
150    kotlin {
151      target(ktlintTarget)
152      // TODO: (barthap) Replace this with raw string when dropped shell app macros
153      // The star "*" signs interferes with slash "/" and treated wildcard path as comment ¯\_(ツ)_/¯
154      targetExclude(["**", "versioned/host/exp/exponent/modules/api", "**", "*.kt"].join("/"))
155      ktlint("0.41.0").userData([
156        "disabled_rules"           : "no-wildcard-imports,import-ordering",
157        "charset"                  : "utf-8",
158        "end_of_line"              : "lf",
159        "indent_size"              : "2",
160        "indent_style"             : "space",
161        "insert_final_newline"     : "true",
162        "tab_width"                : "2",
163        "trim_trailing_whitespace" : "true"
164      ])
165      trimTrailingWhitespace()
166      indentWithSpaces()
167      endWithNewline()
168    }
169  }
170}
171// WHEN_DISTRIBUTING_REMOVE_TO_HERE
172