New Gradle project (command-line and single-module) can't find Android plugin - android-gradle-plugin

I had a single-module project working in command-line Ant and want to convert it to Gradle but it fails at: 'gradle tasks', because it can't find the Android plugin.
This failure coincided with an upgrade to the Android SDK/Tools & Support Repository.
I'm using windows 10 and the TextPad editor (DOS command line screen is included).
The Gradle version is 2.12
build.gradle:
apply plugin: 'com.android.library'
android{
compileSdkVersion 20
buildToolsVersion '23'
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
repositories{
jcenter()
}
dependencies{
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
Note:
I've tried moving the repositories and dependencies out from under the android {}'s.
Error Message:
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\Android\Clox\build.gradle' line: 1
* What went wrong:
A problem occurred evaluating root project 'Clox'.
Plugin with id 'com.android.library' not found.
local.properties file:
sdk.dir=c:\users\chatt\AppData\Local\Android\sdk1
or
sdk.dir=C\:\\Users\\chatt\\AppData\\Local\\Android\\sdk1
I included this because it seems to ignore my JDK_HOME.
JDK_HOME started off pointing at JAVA_HOME. I tried changing JDK_HOME to: 'XXX' and it just gave the usual error.
JDK_HOME is now c:\users\chatt\AppData\Local\Android\sdk1, which I got from the header of the Android SDK Manager, and ANDROID_HOME=%JDK_HOME%.
RECENT TESTING:
I had a sequence of errors that I found the answers to in:
https://stackoverflow.com/questions/
(thank you people)
and then I updated the JDK, adding the Build Tools, with the results:
Packages
- Android SDK Tools, revision 25.1.1
- Android SDK Build-tools, revision 23.0.3
...
- Android Support Repository, revision 30
plus I see there is installed:
-Android SDK Platform 6.0 (API 23)
-Android Support Library v.23.2.1
Apparently this update is what caused the com.android.library plugin not found error; apart from a JAVA_HOME error that's all it gives me.

Apparently my build.gradle structure was wasn't sufficiently standard.
I've switched to a version from:
http://tools.android.com/tech-docs/new-build-system/user-guide
buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
}

Related

Johnrengelman shadow 5.1.0 not running in gradle 5.6.3

I'm trying to create a fat jar for my kotlin + micronaut lambda project with shadow plugin.
My build.gradle
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.41"
id "org.jetbrains.kotlin.kapt" version "1.3.41"
id "io.micronaut.library" version "1.5.4"
id "org.jetbrains.kotlin.plugin.allopen" version "1.3.41"
id "org.jetbrains.kotlin.plugin.serialization" version "1.3.50"
id("com.github.johnrengelman.shadow") version "5.1.0"
}
When i try to execute a gradle task i receive an error to upgrade gradle to 6.x but the shadow 5.1.0 was supposed to work in gradle 5.x
Error:
FAILURE: Build failed with an exception.
* Where:
Build file 'my-app\app\build.gradle' line: 7
* What went wrong:
An exception occurred applying plugin request [id: 'com.github.johnrengelman.shadow', version: '5.1.0']
> Failed to apply plugin [class 'com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin']
> This version of Shadow supports Gradle 6.0+ only. Please upgrade.

Quarkus gradle test fails

I am trying to run the simple 'getting-started'-type gradle project with quarkus and my unit test fails everytime with this error
Caused by: io.quarkus.bootstrap.BootstrapException: Failed to locate project pom.xml for C:\Users\myuser\IdeaProjects\myproj\build\classes\java\main
Followed instructions here https://quarkus.io/guides/gradle-tooling
Any suggestions or thoughts on what is going on?
Gradle version details
Gradle 5.4
Build time: 2019-04-16 02:44:16 UTC
Revision: a4f3f91a30d4e36d82cc7592c4a0726df52aba0d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Windows 10 10.0 amd64
btw. the problem is still open (current version 0.19.1) and issue (2307) is still unresolved.
The reason is that #QuarkusTest points to the QuarkusTestExtension, which in BootstrapClassLoaderFactory.newDeploymentClassLoader attempts to resolve local project with Maven.
We have options:
wait for official solution (see issue)
write own extension overriding BootstrapClassLoaderFactory to "understand" gradle project structure
apply a workaround (for time being), i.e. generate pom.xml from gradle build
Workaround
in build.grade:
plugins {
id 'java'
id 'io.quarkus' version '0.19.1'
// ...
id 'maven-publish'
}
// ...
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
// augment your pom here if necessary
}
}
}
// ...
task createPom(type: Copy) {
description 'This is workaround to generate pom.xml, needed for #QuarkusTest tests.'
dependsOn('generatePomFileForMavenJavaPublication')
from "$buildDir/publications/mavenJava/pom-default.xml"
into '.'
rename('pom-default.xml', 'pom.xml')
}
Note:
use 'maven-publish', not obsolete 'maven' plugin.
do not forget to apply ./gradlew createPom on dependencies changes

Gradle build using Fabric plugin for Crashlytics with groovy plugins DSL

I had a perfectly good gradle build of an android app using Crashlytics and the standard Gradle setup as documented in the Crashlytics gradle doc. I;m using Android Studio 3.2.1, Gradle 4.6 Android plugin version 3.2.1,
As part of prep to convert the build scripts to Kotlin later, I removed the buildscript and apply plugin clauses and replaced them with the plugins clause gradle supports and Kotlin requires. I have seen pure kotlin projects doing this successfully, but can't get this intermediate/prep step using Groovy to work. The plugins clause is getting this error:
Crashlytics was applied to a project without an Android plugin. Please make sure the Crashlytics plugin is applied after the appropriate Android plugin for your project.
Since the Fabric plugin does not exist in the gradle plugin portal (yet?), I'm using this settings.gradle and this part seems to work fine. It finds the Fabric stuff no problem:
pluginManagement {
repositories {
jcenter()
google()
maven { url "https://maven.google.com" }
gradlePluginPortal()
maven { url "https://maven.fabric.io/public" }
}
resolutionStrategy {
eachPlugin {
switch (requested.id.id) {
case "com.android.application":
useModule("com.android.tools.build:gradle:${requested.version}")
break
case "io.fabric":
useModule("io.fabric.tools:gradle:${requested.version}")
break
}
}
}
}
include ':app'
It doesn't seem to matter if the com.android.application case in the switch is present or not, behavior is the same either way.
The corresponding plugins clause in the app's build.gradle looks like this:
plugins {
id "com.android.application"
id "signing"
id "io.fabric" version "1.27.0"
}
In case it's useful the full exception stack from the sync attempt in the build looks like this:
Caused by: org.gradle.internal.exceptions.LocationAwareException: Build file 'D:\Working\Monay\trunk\app\build.gradle' line: 5
An exception occurred applying plugin request [id: 'io.fabric', version: '1.27.0', artifact: 'io.fabric.tools:gradle:1.27.0']
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:232)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:148)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:184)
at org.gradle.configuration.BuildOperationScriptPlugin$1.run(BuildOperationScriptPlugin.java:61)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:58)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:41)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:64)
... 84 more
Caused by: org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'io.fabric', version: '1.27.0', artifact: 'io.fabric.tools:gradle:1.27.0']
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.exceptionOccurred(DefaultPluginRequestApplicator.java:247)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:229)
... 96 more
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'io.fabric']
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:150)
at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:125)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$3.run(DefaultPluginRequestApplicator.java:151)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:225)
... 96 more
Caused by: org.gradle.api.GradleException: Crashlytics was applied to a project without an Android plugin. Please make sure the Crashlytics plugin is applied after the appropriate Android plugin for your project.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
at com.crashlytics.tools.gradle.ExternalPluginsState.deriveFrom(ExternalPluginsState.groovy:23)
at com.crashlytics.tools.gradle.ExternalPluginsState$deriveFrom.call(Unknown Source)
at com.crashlytics.tools.gradle.CrashlyticsPlugin.apply(CrashlyticsPlugin.groovy:50)
at com.crashlytics.tools.gradle.CrashlyticsPlugin.apply(CrashlyticsPlugin.groovy)
at org.gradle.api.internal.plugins.ImperativeOnlyPluginTarget.applyImperative(ImperativeOnlyPluginTarget.java:42)
at org.gradle.api.internal.plugins.RuleBasedPluginTarget.applyImperative(RuleBasedPluginTarget.java:50)
at org.gradle.api.internal.plugins.DefaultPluginManager.addPlugin(DefaultPluginManager.java:164)
at org.gradle.api.internal.plugins.DefaultPluginManager.access$200(DefaultPluginManager.java:47)
at org.gradle.api.internal.plugins.DefaultPluginManager$AddPluginBuildOperation.run(DefaultPluginManager.java:252)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:144)
... 99 more
For some reason Crashlytics plugin doesn't see the android app plugin this way. Anyone know what I'm doing wrong, or if this use of the plugins clause should work with the Fabric plugin? Thanks in advance for any help
For others running into this, the simple fix is to skip applying the plugin in the plugins{} block, and instead apply it later in the build script (even immediately following the plugins{} block is fine):
plugins {
id("com.android.application")
id("io.fabric") version("1.27.0") apply(false)
}
apply plugin: 'io.fabric'

Could not find kotlin-gradle-plugin for Kotlin script Gradle

build fails, classpath error:
thufir#dur:~/NetBeansProjects/kotlinShadowJar$
thufir#dur:~/NetBeansProjects/kotlinShadowJar$ gradle clean
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'kotlinShadowJar'.
> Could not resolve all files for configuration ':classpath'.
> Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:.
Searched in the following locations:
file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
Required by:
project :
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
cat build.gradle.kts:
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
buildscript {
repositories {
mavenCentral()
gradleScriptKotlin()
}
dependencies {
classpath(kotlinModule("gradle-plugin"))
classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3")
}
}
apply {
plugin("kotlin")
plugin("com.github.johnrengelman.shadow")
}
repositories {
mavenCentral()
}
val shadowJar: ShadowJar by tasks
shadowJar.apply {
manifest.attributes.apply {
put("Implementation-Title", "Gradle Jar File Example")
put("Implementation-Version" version)
put("Main-Class", "com.mkyong.DateUtils")
}
baseName = project.name + "-all"
}
The buildfile was a direct copy of a working build. The context is getting started with Kotlin script Gradle. So far as I can tell the script should be good.
Note that I'm not using intelli-J, this is strictly from the CLI with Kotlin script Gradle.
perhaps it's something quite simple, like "plugin" versus "plugins"...
Looking at the error logs, you can see the plugin version request:
Searched in the following locations:
file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
You can see that a version is not requested on each plugin request because they are looking for kotlin-gradle-plugin-.jar.
If you look at the source, you will also see that kotlinModule is deprecated.
I would recommend a few different changes to improve the build script:
Using the Gradle wrapper (./gradlew
Specify a version for your kotlinModule until you upgrade your Gradle version - kotlinModule("gradle-plugin", "1.1.51")
Use the plugins {} block instead of buildscript for plugins

Android studio 2.2 gradle plugin for instant run error

I am using android studio 2.2 and getting the below error while trying to build the project
Error:Cause: com.android.build.gradle.AppPlugin cannot be cast to groovy.lang.GroovyObject
I added classpath 'com.android.tools.build:gradle:2.2.0'
in my top level gradle
My project has 11 modules and compilesdk version is 23,buildtools version is 24.0.2
How can I build the fix the issues and build the project
I met the same problem。
“Your project may be using a third-party plugin which is not compatible with the other plugins... ”as the console reminders。
So you should check your buildscript{dependencies{}} in build.gradle file。
Like this:
dependencies {
......
classpath 'com.android.tools.build:gradle:2.2'
classpath 'com.xxx.gradle.sign:sign:0.2.0'
......
}
and I update the sign plugin from sign:0.2.0 to sign:0.1.0,then it's ok。So you should find the incompatible plugin and update it。