An error occur When i try to build android app - android-gradle-plugin

I got this error when i try to build android app
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'
My top-level file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}

"Compile" Scope for the dependencies are being taken away from Android development, so instead use "Implementation" as a scope for all the dependencies. You can change it by right click on the folder (e.g. App) then "module setting>dependencies>scope" and then sync the project.

There is many solution according to github issues
first remember android have removed Compile Scope for the dependencies new Implementation
one way
right click App then
module setting--->dependencies---->scope and then sync your project
Other way
upgrade classpath com.google.gms:google-services to classpath 'com.google.gms:google-services:3.2.1' in file in build.gradle
buildscript {
repositories {
}
dependencies {
classpath 'com.google.gms:google-services:3.2.1'<-------*****
}
}
allprojects {
repositories {
}
}
}

Related

Why won't Gradle find my locally published plugin?

I have one project which contains and publishes a Gradle plugin:
plugins {
`java-gradle-plugin`
`kotlin-dsl`
kotlin("jvm") version "1.5.31"
`maven-publish`
}
project.group = "com.company.gradle"
project.version = "1.0.0"
repositories {
mavenCentral()
gradlePluginPortal()
}
gradlePlugin {
plugins.create("pomPlugin") {
id = "com.company.gradle.pom"
implementationClass = "com.company.gradle.pom.PomPlugin"
}
}
Building this and publishing (via ./gradlew publishToMavenLocal) succeeds without errors. After it completes, my local maven repo ~/.m2/reposiory contains:
./com/company/
./com/company/gradle
./com/company/gradle/pom
./com/company/gradle/pom/maven-metadata-local.xml
./com/company/gradle/pom/1.0.0
./com/company/gradle/pom/1.0.0/pom-1.0.0.jar
./com/company/gradle/pom/1.0.0/pom-1.0.0.module
./com/company/gradle/pom/1.0.0/pom-1.0.0.pom
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/maven-metadata-local.xml
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/1.0.0
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/1.0.0/com.company.gradle.pom.gradle.plugin-1.0.0.pom
Then I have another project that tries to use the plugin:
buildscript {
repositories {
mavenLocal()
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
kotlin("jvm") version "1.6.10"
id("com.company.gradle.pom") version "1.0.0"
}
repositories {
google()
mavenCentral()
mavenLocal()
}
but Gradle cannot resolve the plugin:
* What went wrong:
Plugin [id: 'com.foxit.gradle.pom', version: '1.0.0'] 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.foxit.gradle.pom:com.foxit.gradle.pom.gradle.plugin:1.0.0')
Searched in the following repositories:
Gradle Central Plugin Repository
Add this at the top of your settings.gradle file in the project where you want to use your plugin.
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
}
The gradlePluginPortal() bit is for "real" gradle plugins which have been published.
The mavenLocal() bit is for your locally published plugins.
The repositories blocks you have in the build.gradle are for dependencies and not plugins.

unable to resolve class com.android.build.OutputFile

How to SOlved that error please answer details
unable to resolve class com.android.build.OutputFile
As said by #Dipan check if your android/build.gradle has a classpath defined in dependencies.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0") // <- this line
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

kotlin-compiler-embeddable missing within gradle build

I am trying to setup a multiproject gradle/kotlin build and I am getting following error:
Could not determine the dependencies of task ':compileKotlin'.
> Could not resolve all files for configuration ':kotlinCompilerClasspath'.
> Cannot resolve external dependency org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.10 because no repositories are defined.
Required by:
project :
Strange thing is the empty project :.
My simplifiged build.gradle.kts looks like this:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
base
kotlin("jvm") version "1.4.10"
}
buildscript {
extra["kotlin_version"] = "1.4.10"
repositories {
jcenter()
mavenCentral()
}
}
subprojects {
apply(plugin = "kotlin")
repositories {
jcenter()
mavenCentral()
}
tasks.compileKotlin {
kotlinOptions.jvmTarget = "11"
}
tasks.compileTestKotlin {
kotlinOptions.jvmTarget = "11"
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:${rootProject.extra["kotlin_version"]}")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${rootProject.extra["kotlin_version"]}")
}
}
Do I need to duplicate the repositories within the buildscript section?
What is that is causing the error above?
It seems like your repositories { ... } configuration done in the subproject section is sufficient, but it is only applied to the supbrojects but not the root project itself (which has the Kotlin plugin applied, too, and whose task :compileKotlin is failing).
There are two ways to fix this.
First, you could move the repositories { ... } section from subprojects { ... } to a new block allprojects { ... } (thus applied to the root project as well).
Or, if you don't actually need the Kotlin plugin in the root project (i.e. you don't have Kotlin code there), you can add .apply(false) to your plugin declaration:
plugins {
kotlin("jvm").version("1.4.10").apply(false)
}

Gradle sync failed because of "Unable to load Maven meta-data from ...", but I can download the file via browser

buildscript {
repositories {
google()
jcenter()
jcenter{ url"http://jcenter.bintray.com"}
maven {
url 'http://dl.bintray.com/amulyakhare/maven'
}
}
dependencies {
classpath "com.android.tools.build:gradle:$android_plugin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
classpath "com.mob.sdk:MobSDK:+"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
allprojects {
repositories {
google()
jcenter()
jcenter{ url"http://jcenter.bintray.com"}
maven {
url 'http://dl.bintray.com/amulyakhare/maven'
}
}
}
Here is my gradle file. When do gradle sync, an error comes out.
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.mob.sdk:MobSDK:+.
Caused by: org.gradle.api.resources.ResourceException: Unable to load Maven meta-data from http://jcenter.bintray.com/com/mob/sdk/MobSDK/maven-metadata.xml.
Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'http://jcenter.bintray.com/com/mob/sdk/MobSDK/maven-metadata.xml'.
Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'http://jcenter.bintray.com/com/mob/sdk/MobSDK/maven-metadata.xml'.
But I can download the url http://jcenter.bintray.com/com/mob/sdk/MobSDK/maven-metadata.xml directly via browser.
Does anyone know why this happens?
buildscript {
repositories {
maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
}
...............
...............
allprojects{
repositories {
maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
}

Gradle-Android: Where is the classpath() coming from?

Here is the root build.gradle file of an android app. I want to ask where does the classpath() method is declared. I guess in Project but I cant find it in the reference.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
From the Interface ScriptHandler, classpath is the configuration's value of public static final String CLASSPATH_CONFIGURATION "classpath".
You can call it via buildscript.CLASSPATH_CONFIGURATION as buildscript returns a ScriptHandler.