Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

./gradlew command line error after updating Android Studio

After updating Android studio to 3.2, and making the corresponding changes to the gradle version and gradle plugins, I can no longer run ./gradlew from the command line without getting errors. I can still sync gradle and build the app from the toolbar however. The error I get is:

> Failed to apply plugin [id 'com.android.application']
> Could not create an instance of type com.android.build.gradle.AppExtension_Decorated.
  > Could not create an instance of type com.android.build.gradle.internal.api.DefaultAndroidSourceSet.
     > Uninitialized object exists on backward branch 70
       Exception Details:
         Location:
           com/android/build/gradle/internal/scope/BuildArtifactsHolder.newArtifact(Lcom/android/build/api/artifact/BuildableArtifact;)Lcom/android/build/gradle/internal/scope/BuildArtifactsHolder$BuildableArtifactData; @119: goto
         Reason:
           Error exists in the bytecode

Any help in understanding what is going wrong would be really appreciated. I am using the jdk embedded in Android Studio, and have tried deleting various folders like .gradle, build, .idea and reimporting the project, but nothing seems to fix it. I am using Kotlin if that is relevant. Not really sure how to go about debugging this.

gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip

relevant portion of project root build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }
dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0-alpha08'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.31"
}
like image 583
bryant Avatar asked Jan 20 '26 14:01

bryant


1 Answers

It turns out that while Android Studio comes with an embedded version of jdk, the gradle wrapper doesn't by default use that version of jdk embedded in Android Studio, but instead uses whatever JDK you have installed on your system. In my case that version was too old, so I just updated it to the latest version of java8 with brew, and my ./gradlew tasks work fine now. Note: initially brew updated java to java10, which didn't work, so I had to specifically install latest java8.

like image 198
bryant Avatar answered Jan 22 '26 03:01

bryant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!