Search code examples
androidgradleandroid-gradle-plugingradle-kotlin-dsl

Local AGP jar was not found in any of the following sources


It happened so that I need to make an app buildable using local tools only.

I am stuck with local AGP jar.

I have tried to add it to classpath:

classpath(files("gradle/com.android.tools.build.gradle-2.7.1.jar"))

but it seems like I am missing something.

Currently I have the following issue:

    Plugin [id: 'com.android.application', version: '2.7.1', artifact: 'com.android.tools.build:gradle:2.7.1', apply: false] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.android.tools.build:gradle:2.7.1')
  Searched in the following repositories:
    Gradle Central Plugin Repository
    Google
    MavenRepo
    flatDir(/storage/emulated/0/Root/My Application35/gradle)
    maven(https://s01.oss.sonatype.org/content/repositories/snapshots/)
    Google2
    maven2(https://s01.oss.sonatype.org/content/groups/public/)
    MavenRepo2
    Gradle Central Plugin Repository2

Have any of you had similar issues?

As I see, it might be bacause com.android.tools.build:gradle does not have com.android.application as a part of it. But maven does not have https://mvnrepository.com/artifact/com.android.application jar.

So I am really puzzled.

Project level gradle:

buildscript {
    repositories {
        google()  // Add Google's Maven repository
        mavenCentral()  // Add Maven Central repository (optional)
        flatDir {
          dirs("gradle") // Directory containing your local JAR
        }
    }
    dependencies {
        classpath(files("gradle/com.android.tools.build.gradle-2.7.1.jar"))
    }
}

tasks.register<Delete>("clean") {
    delete(rootProject.buildDir)
}

Settings gradle file:

pluginManagement {
  repositories {
    gradlePluginPortal()
    google()
    mavenCentral()
    flatDir {
        dirs("gradle") // Directory containing your local JAR
    }
  }
  
  resolutionStrategy {
     eachPlugin {
          if (requested.id.id == "com.android.application") {
              useModule("com.android.tools.build:gradle:2.7.1")
          }
     }
  }
}

dependencyResolutionManagement {
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
  repositories {
    google()
    mavenCentral()
  }
}

App level gradle:

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.jetbrains.kotlin.android)
}

android {
    namespace = "com.example.debugee"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.debugee"
        minSdk = 24
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
    }
    ...
}

dependencies {
...
}

Solution

  • The Android Application Gradle plugin is contained in the artifact located at coordinates com.android.application:com.android.application.gradle.plugin.

    You can obtain it from Google's Maven repository.

    The POM of that artifact points to the further artifact com.android.tools.build:gradle, which is also hosted at Google's Maven repo, and the JAR is located there.