-
Notifications
You must be signed in to change notification settings - Fork 309
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
357 lines (306 loc) · 11.4 KB
/
build.gradle.kts
File metadata and controls
357 lines (306 loc) · 11.4 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
// Root build script for RunAnywhere monorepo
//
// Available tasks:
// ./gradlew setup - Check environment and create local.properties
//
// Native (C++):
// ./gradlew buildCpp - Build C++ and copy .so to jniLibs
// ./gradlew buildFullSdk - Full pipeline: C++ + copy + Kotlin SDK
// ./gradlew copyNativeLibs - Copy .so from dist/ to jniLibs/ (no rebuild)
//
// Kotlin SDK:
// ./gradlew buildSdk - Build SDK (debug AAR + JVM JAR)
// ./gradlew buildSdkRelease - Build SDK (release AAR)
// ./gradlew publishSdkToMavenLocal - Publish SDK to ~/.m2
//
// Android App:
// ./gradlew buildAndroidApp - Build Android example app
// ./gradlew runAndroidApp - Build, install, and launch Android app
//
// IntelliJ Plugin:
// ./gradlew buildIntellijPlugin - Build IntelliJ plugin
// ./gradlew runIntellijPlugin - Run IntelliJ plugin in sandbox
//
// Utility:
// ./gradlew buildAll - Build everything
// ./gradlew cleanAll - Clean everything
plugins {
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.ktlint) apply false
}
allprojects {
group = "com.runanywhere"
version = "0.1.0"
}
subprojects {
tasks.withType<Test> {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
}
// Shared helpers
fun resolveAndroidHome(): String =
System.getenv("ANDROID_HOME")
?: System.getenv("ANDROID_SDK_ROOT")
?: "${System.getProperty("user.home")}/Android/Sdk"
fun resolveNdkHome(androidHome: String): String =
System.getenv("ANDROID_NDK_HOME")
?: "$androidHome/ndk/27.0.12077973"
fun ensureLocalProperties(dir: java.io.File, includeNdk: Boolean = false) {
val localProps = dir.resolve("local.properties")
if (!localProps.exists() && dir.exists()) {
val androidHome = resolveAndroidHome()
val content = buildString {
appendLine("sdk.dir=$androidHome")
if (includeNdk) appendLine("ndk.dir=${resolveNdkHome(androidHome)}")
}
localProps.writeText(content)
println(" Created: ${localProps.relativeTo(rootDir)}")
}
}
// Setup — single command to check environment, create local.properties, and setup native deps
tasks.register("setup") {
group = "setup"
description = "Check environment, create local.properties, and setup native dependencies if testLocal=true"
doLast {
println("RunAnywhere Development Setup")
println()
// Check environment
val androidHome = resolveAndroidHome()
val ndkHome = resolveNdkHome(androidHome)
val sdkExists = file(androidHome).exists()
val ndkExists = file(ndkHome).exists()
println("Environment:")
println(" Android SDK: ${if (sdkExists) "[OK] $androidHome" else "[WARN] Not found at $androidHome"}")
println(" Android NDK: ${if (ndkExists) "[OK] $ndkHome" else "[WARN] Not found at $ndkHome"}")
println()
// Create local.properties where needed
println("local.properties:")
ensureLocalProperties(projectDir, includeNdk = true)
ensureLocalProperties(file("sdk/runanywhere-kotlin"), includeNdk = true)
ensureLocalProperties(file("examples/android/RunAnywhereAI"))
val locations = mapOf(
"Root" to projectDir,
"SDK" to file("sdk/runanywhere-kotlin"),
"Android App" to file("examples/android/RunAnywhereAI"),
)
locations.forEach { (name, dir) ->
val props = dir.resolve("local.properties")
println(" $name: ${if (props.exists()) "[OK]" else "[MISSING]"} ${props.relativeTo(rootDir)}")
}
println()
// Check build mode and run native setup if needed
val testLocal = projectDir.resolve("gradle.properties").let { f ->
f.exists() && f.readText().contains("runanywhere.testLocal=true")
}
println("Build mode: testLocal=$testLocal")
if (testLocal) {
println()
println("testLocal=true: Running native dependency setup...")
val buildScript = file("sdk/runanywhere-kotlin/scripts/build-kotlin.sh")
if (buildScript.exists()) {
exec {
workingDir = file("sdk/runanywhere-kotlin")
environment("ANDROID_NDK_HOME", ndkHome)
commandLine("bash", buildScript.absolutePath, "--setup", "--skip-build")
}
println("Native setup complete")
} else {
println("[WARN] build-kotlin.sh not found at ${buildScript.relativeTo(rootDir)}")
}
} else {
println("testLocal=false: Native libs will be downloaded from GitHub releases during build")
}
}
}
// =============================================================================
// Native (C++) tasks — wraps build-sdk.sh for IDE integration
// =============================================================================
tasks.register("buildCpp") {
group = "native"
description = "Build C++ (runanywhere-commons) and copy .so to jniLibs"
doLast {
val ndkHome = resolveNdkHome(resolveAndroidHome())
exec {
workingDir = file("sdk/runanywhere-kotlin")
environment("ANDROID_NDK_HOME", ndkHome)
commandLine("bash", "scripts/build-sdk.sh", "--cpp-only")
}
}
}
tasks.register("buildFullSdk") {
group = "native"
description = "Full pipeline: build C++ + copy .so + build Kotlin SDK"
doLast {
val ndkHome = resolveNdkHome(resolveAndroidHome())
exec {
workingDir = file("sdk/runanywhere-kotlin")
environment("ANDROID_NDK_HOME", ndkHome)
commandLine("bash", "scripts/build-sdk.sh")
}
}
}
tasks.register("copyNativeLibs") {
group = "native"
description = "Copy .so from dist/ to jniLibs/ (no C++ rebuild)"
doLast {
val ndkHome = resolveNdkHome(resolveAndroidHome())
exec {
workingDir = file("sdk/runanywhere-kotlin")
environment("ANDROID_NDK_HOME", ndkHome)
commandLine("bash", "scripts/build-kotlin.sh", "--local", "--skip-build")
}
}
}
// =============================================================================
// SDK tasks
// =============================================================================
tasks.register("buildSdk") {
group = "sdk"
description = "Build SDK debug (AAR + JVM JAR)"
dependsOn(":runanywhere-kotlin:assembleDebug", ":runanywhere-kotlin:jvmJar")
doLast {
println("SDK debug build complete")
println(" AAR: sdk/runanywhere-kotlin/build/outputs/aar/")
println(" JAR: sdk/runanywhere-kotlin/build/libs/")
}
}
tasks.register("buildSdkRelease") {
group = "sdk"
description = "Build SDK release AAR"
dependsOn(":runanywhere-kotlin:assembleRelease")
doLast {
println("SDK release build complete")
}
}
tasks.register("publishSdkToMavenLocal") {
group = "sdk"
description = "Publish SDK to Maven Local (~/.m2/repository)"
dependsOn(":runanywhere-kotlin:publishToMavenLocal")
doLast {
println("SDK published to Maven Local")
println(" Group: ${project.group}")
println(" Version: ${project.version}")
}
}
// Android example app tasks
tasks.register("buildAndroidApp") {
group = "android"
description = "Build Android example app"
doFirst {
ensureLocalProperties(file("examples/android/RunAnywhereAI"))
}
doLast {
exec {
workingDir = file("examples/android/RunAnywhereAI")
commandLine("./gradlew", "assembleDebug")
}
println("Android app built: examples/android/RunAnywhereAI/app/build/outputs/apk/")
}
}
tasks.register("runAndroidApp") {
group = "android"
description = "Build, install, and launch Android app on device"
dependsOn("buildAndroidApp")
doLast {
exec {
workingDir = file("examples/android/RunAnywhereAI")
commandLine("./gradlew", "installDebug")
}
exec {
commandLine(
"adb", "shell", "am", "start", "-n",
"com.runanywhere.runanywhereai.debug/com.runanywhere.runanywhereai.MainActivity",
)
}
println("Android app launched")
}
}
// IntelliJ plugin tasks (SDK consumed via Maven Local)
tasks.register("buildIntellijPlugin") {
group = "intellij"
description = "Publish SDK + build IntelliJ plugin"
doLast {
exec {
workingDir = projectDir
commandLine("./gradlew", ":runanywhere-kotlin:publishToMavenLocal")
}
exec {
workingDir = file("examples/intellij-plugin-demo/plugin")
commandLine("./gradlew", "buildPlugin")
}
println("IntelliJ plugin built: examples/intellij-plugin-demo/plugin/build/distributions/")
}
}
tasks.register("runIntellijPlugin") {
group = "intellij"
description = "Publish SDK + run IntelliJ plugin in sandbox"
doLast {
exec {
workingDir = projectDir
commandLine("./gradlew", ":runanywhere-kotlin:publishToMavenLocal")
}
exec {
workingDir = file("examples/intellij-plugin-demo/plugin")
commandLine("./gradlew", "runIde")
}
}
}
// Convenience tasks
tasks.register("buildAll") {
group = "build"
description = "Build SDK and all example apps"
dependsOn("setup")
doLast {
// Build SDK
exec {
workingDir = projectDir
commandLine("./gradlew", ":runanywhere-kotlin:assembleDebug")
}
// Build Android app
exec {
workingDir = file("examples/android/RunAnywhereAI")
commandLine("./gradlew", "assembleDebug")
}
// Publish SDK to Maven Local + build IntelliJ plugin
exec {
workingDir = projectDir
commandLine("./gradlew", ":runanywhere-kotlin:publishToMavenLocal")
}
exec {
workingDir = file("examples/intellij-plugin-demo/plugin")
commandLine("./gradlew", "buildPlugin")
}
println()
println("Build complete:")
println(" SDK AAR: sdk/runanywhere-kotlin/build/outputs/aar/")
println(" Maven Local: ~/.m2/repository/com/runanywhere/runanywhere-sdk/")
println(" Android APK: examples/android/RunAnywhereAI/app/build/outputs/apk/")
println(" IntelliJ Plugin: examples/intellij-plugin-demo/plugin/build/distributions/")
}
}
tasks.register("cleanAll") {
group = "build"
description = "Clean all projects"
doLast {
delete(layout.buildDirectory)
file("sdk/runanywhere-kotlin/build").deleteRecursively()
exec {
workingDir = file("examples/android/RunAnywhereAI")
commandLine("./gradlew", "clean")
}
exec {
workingDir = file("examples/intellij-plugin-demo/plugin")
commandLine("./gradlew", "clean")
}
println("All projects cleaned")
}
}