Gradle Sync Kotlin Error in Android Studio 3.3.2 - kotlin

Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.3.11/kotlin-reflect-1.3.11.jar'.
at org.gradle.internal.resource.ResourceExceptions.failure(ResourceExceptions.java:74)
at org.gradle.internal.resource.ResourceExceptions.getFailed(ResourceExceptions.java:57)
at org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor.copyToCache(DefaultCacheAwareExternalResourceAccessor.java:201)
at org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor.access$300(DefaultCacheAwareExternalResourceAccessor.java:54)
at org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor$1.create(DefaultCacheAwareExternalResourceAccessor.java:89)
at org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor$1.create(DefaultCacheAwareExternalResourceAccessor.java:81)
at org.gradle.cache.internal.ProducerGuard$AdaptiveProducerGuard.guardByKey(ProducerGuard.java:97)
at org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor.getResource(DefaultCacheAwareExternalResourceAccessor.java:81)
at org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver.downloadByCoords(DefaultExternalResourceArtifactResolver.java:133)
at org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver.downloadStaticResource(DefaultExternalResourceArtifactResolver.java:97)
at org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver.resolveArtifact(DefaultExternalResourceArtifactResolver.java:66)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver$RemoteRepositoryAccess.resolveArtifact(ExternalResourceResolver.java:477)

Fixed by change the gradle version from classpath 'com.android.tools.build:gradle:3.3.0' classpath' to 'com.android.tools.build:gradle:3.3.2'

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.

Gradle fails after kotlin serialization plugin update to 1.7.10

My build.gradle.kts starts as follows:
...
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
...
kotlin("jvm") //target version is java 11
kotlin("plugin.serialization") version "1.6.21"
}
When I try to update the kotlin serialization plugin to the more recent 1.7.10 version, I get the following compilation error:
A problem occurred configuring project ':my-little-project'.
> Failed to notify project evaluation listener.
> org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin: org.jetbrains.kotlinx.serialization.gradle.SerializationGradleSubplugin not a subtype
> org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin: org.jetbrains.kotlinx.serialization.gradle.SerializationGradleSubplugin not a subtype
How do I fix this? Thanks!
Stack trace (too large to post completely, for more just ask):
Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':my-little-project'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:68)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:51)
...
Caused by: org.gradle.internal.event.ListenerNotificationException: Failed to notify project evaluation listener.
at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:89)
at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:346)
at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:249)
...
Thanks #aSemy for listing what turned out to be the issue. Our microservice architecture meant there was another, overarching, build.gradle.kts file which contained this line that also needed updating:
kotlin("jvm") version "1.6.10" apply false

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'

New Gradle version creates conflict with depedency

I have a simple build script (shorted for clarity) which uses Guava as a dependency
group 'test'
version '0.1.0'
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'Test'
repositories {mavenCentral()}
task wrapper(type: Wrapper) {gradleVersion = '3.5'}
dependencies {compile 'com.google.guava:guava:21.0'}
When running this code:
public class Test {
public static void main(String[] args) {
LoadingCache<Long, String> applicantCache = CacheBuilder.newBuilder()
.maximumSize(30000)
.expireAfterAccess(31, TimeUnit.DAYS)
.build(new CacheLoader<Long, String>() {
#Override
public String load(Long key) {
return "";
}
});
}
}
I get this error:
java.lang.NoClassDefFoundError: com/google/common/cache/CacheLoader
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.google.common.cache.CacheLoader
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"
When downgrading the Gradle Wrapper version to 3.3 the problem is fixed but, I need version 3.5 for something else that is not feasible in version 3.3. As far as I can understand there is some dependency conflict between this version of Gradle and Guava but according to this post - it is not possible.
I know the jar is in place + using gradle dependencyInsight --dependency com.google.guava shows that the dependency exists:
:dependencyInsight
com.google.guava:guava:21.0
\--- compile
Thanks for any help
EDIT:
After testing on other computers it seems the problem only occurs when I update the wrapper task, execute it and then refresh the gradle project by clicking on the Refresh all Gradle projects button (see attached image). When running the executing distribution script every thing works fine - so it only happens in Intellij. I'm guessing I'm missing something in how Gradle Wrapper works or when to execute it...
EDIT
Tested on Gradle version 3.4 and the problem occurres.
if anyone else encounters similar issues the answer is here.
A bug in my Intellij version (2016.2.5) caused compile scoped dependencies to transform into provided scoped dependencies by Intellij. This, in turn, makes dependencies to appear only in Intellij's compile classpath but not in it's runtime classpath. That's why when running the ./gradlew run command the issue could not be reproduced as there was no issue on Gradle's part.
Upgrading the Intellij version (2017.1) solved the issue.

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。