-
Notifications
You must be signed in to change notification settings - Fork 97
/
build.gradle
188 lines (152 loc) · 6.07 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import java.nio.file.Paths
static int toVersionNumber(String version) {
def (major, minor, patch) = version.findAll(/\d+/)
return (major as int) * 10000 + (minor as int) * 100 + (patch as int)
}
buildscript {
ext.ensureProperty = { config, property ->
if (!config.containsKey(property)) {
throw new MissingPropertyException("Missing '$property' in 'react-native-test-app-msal' config")
}
return config[property]
}
ext.findFile = { fileName ->
def currentDirPath = rootDir == null ? null : rootDir.toString()
while (currentDirPath != null) {
def currentDir = file(currentDirPath);
def requestedFile = Paths.get(currentDirPath, fileName).toFile()
if (requestedFile.exists()) {
return requestedFile
}
currentDirPath = currentDir.getParent()
}
return null
}
ext.findNodeModulesPath = { packageName ->
return findFile(Paths.get("node_modules", packageName).toString())
}
ext.getExtProp = { prop, defaultValue ->
return rootProject.ext.has(prop) ? rootProject.ext.get(prop) : defaultValue
}
ext.getStringArray = { config, property ->
return (!config.containsKey(property) || config[property].size() == 0)
? ""
: "\"${config[property].join('", "')}\""
}
ext.kotlinVersion = getExtProp("kotlinVersion", "1.7.21")
repositories {
google()
mavenCentral()
}
dependencies {
def androidPluginVersion = getExtProp("androidPluginVersion", "7.2.2")
classpath("com.android.tools.build:gradle:${androidPluginVersion}")
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}
repositories {
maven {
url("${findNodeModulesPath('react-native')}/android")
}
google()
mavenCentral()
// https://github.com/AzureAD/microsoft-authentication-library-for-android#step-1-declare-dependency-on-msal
maven {
url "https://pkgs.dev.azure.com/MicrosoftDeviceSDK/DuoSDK-Public/_packaging/Duo-SDK-Feed/maven/v1"
}
}
def rnxAuthPackage = findNodeModulesPath("@rnx-kit/react-native-auth")
def rnxDisableAuthProperty = "com.microsoft.reacttestapp.msal.disableRnxAuthModule"
def rnxAuthSkipModuleRegistration =
rnxAuthPackage == null ||
(rootProject.hasProperty(rnxDisableAuthProperty) && rootProject.property(rnxDisableAuthProperty).toString().equalsIgnoreCase("true"))
android {
def manifest = new JsonSlurper().parseText(findFile("app.json").text)
def config = manifest["react-native-test-app-msal"]
if (config == null) {
throw new MissingPropertyException("Missing 'react-native-test-app-msal' field in 'app.json'")
}
def signatureHash = ensureProperty(config, "signatureHash")
compileSdkVersion getExtProp("compileSdkVersion", 31)
defaultConfig {
minSdkVersion getExtProp("minSdkVersion", 23)
targetSdkVersion getExtProp("targetSdkVersion", 29)
buildConfigField "String[]",
"ReactTestAppMSAL_msaScopes",
"new String[]{${getStringArray(config, "msaScopes")}}"
buildConfigField "String[]",
"ReactTestAppMSAL_orgScopes",
"new String[]{${getStringArray(config, "orgScopes")}}"
manifestPlaceholders = [
msalRedirectUriPath: "/$signatureHash"
]
}
lintOptions {
abortOnError false
}
sourceSets {
def clientId = ensureProperty(config, "clientId")
def appProject = rootProject.subprojects.find { it.name == "app" }
def applicationId = appProject.android.defaultConfig.applicationId
def redirectUri = "msauth://${applicationId}/${URLEncoder.encode(signatureHash, "UTF-8")}"
def generatedResDir = file("${appProject.buildDir}/generated/react-native-test-app-msal/src/main/res")
task copyMsalConfig {
mustRunAfter(":app:clean")
doLast {
def generatedRawDir = file("${generatedResDir}/raw")
generatedRawDir.mkdirs()
new FileTreeBuilder(generatedRawDir).file("msal_config.json").newWriter().withWriter {
it << JsonOutput.toJson([
authorities: [
[
type: "AAD",
audience: [
type: "AzureADandPersonalMicrosoftAccount"
],
default: true
],
[
type: "AAD",
audience: [
type: "PersonalMicrosoftAccount"
],
],
],
client_id: clientId,
redirect_uri: redirectUri,
broker_redirect_uri_registered: false,
account_mode: "MULTIPLE"
])
}
}
}
preBuild.dependsOn(copyMsalConfig)
main.res.srcDirs += generatedResDir
if (rnxAuthSkipModuleRegistration) {
main.java.srcDirs += "src/nornx/java"
} else {
main.java.srcDirs += "src/rnx/java"
}
}
}
dependencies {
def kotlinVersionNumber = toVersionNumber(kotlinVersion)
if (kotlinVersionNumber >= 10800) {
implementation "androidx.activity:activity-ktx:1.7.2"
} else {
implementation(["androidx.activity", "activity-ktx", "1.6.1"].join(":"))
}
implementation "com.google.android.material:material:1.9.0"
implementation "com.microsoft.identity.client:msal:4.7.0"
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
if (rnxAuthPackage != null) {
implementation project(path: ":rnx-kit_react-native-auth")
}
}