Skip to content

Commit c9fa044

Browse files
committed
ADFA-3078: Search the on-device Maven repo before the remote ones
Offline builds failed unless the user turned on the --offline flag, which defeats the point of an offline-first IDE. The on-device repo was registered last. Templates declare gradlePluginPortal(), google() and mavenCentral() first, and this plugin appended with `maven { it.url = uri }`. With no network, dl.google.com fails DNS, and Gradle treats a repository *error* as fatal rather than falling through to the next repository the way it does for a 404. Resolution therefore died at google() and never reached the local repo. --offline worked only because it skips remote repositories entirely. The artifacts were never missing: the AGP plugin marker, kotlin-build-tools-compat and kotlin-build-tools-impl are all present in localMvnRepository on device. Inserting at index 0 instead of appending fixes all four injection points (pluginManagement, dependencyResolutionManagement, and the settings and project buildscript blocks). Verified on a Pixel 9 Pro emulator in airplane mode with offlineMode=false, the Gradle modules-2 cache deleted, and a brand new Empty Activity Kotlin project whose settings.gradle.kts was left untouched: sync reaches "Project initialized" and the build produces app-debug.apk. Both failed under identical conditions before this change. A warm module cache masks the bug, so retests need the cache cleared. Ships in the APK, not the assets zip, so no asset rebuild is required. Claude-Session: https://claude.ai/code/session_017HGpMsUzZ5wxCfMtDZ2HGP
1 parent 02bd363 commit c9fa044

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎gradle-plugin/src/main/java/com/itsaky/androidide/gradle/COTGSettingsPlugin.kt‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ private fun RepositoryHandler.addMavenRepoIfMissing(
116116
logger: Logger,
117117
uri: URI,
118118
) {
119-
if (none { it is MavenArtifactRepository && it.url == uri }) {
120-
logger.info("Adding maven repository: $uri")
121-
maven { it.url = uri }
119+
if (any { it is MavenArtifactRepository && it.url == uri }) {
120+
return
122121
}
122+
123+
logger.info("Adding maven repository: $uri")
124+
val repo = maven { it.url = uri }
125+
126+
remove(repo)
127+
add(0, repo)
123128
}

0 commit comments

Comments
 (0)