3

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"
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
bryant
  • 2,041
  • 3
  • 18
  • 26

3 Answers3

2

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.

bryant
  • 2,041
  • 3
  • 18
  • 26
0

Try with restarting Android Studio with Invalidate Caches/Restart.

ravip
  • 91
  • 1
  • 6
  • forgot to mention that I have tried that too, but it didn't help. I have also tried re-importing the project which didn't help either. – bryant Mar 30 '18 at 10:40
0

Try to add gradle to enviroment variables: set PATH=d:\tools\gradle\bin;%PATH% you can also define a new environment variable called GRADLE_HOME.

Check again the installation steps . https://www.javacodegeeks.com/2013/04/how-to-install-gradle-2.html

Raluca Lucaci
  • 2,058
  • 3
  • 20
  • 37
  • I already have gradle installed using Homebrew, and am able to access it from the project directory already. I never had a problem with gradle before upgrading the version of Android Studio/Gradle – bryant Mar 30 '18 at 11:21
  • Do you have the latest version of gradle also ? https://stackoverflow.com/questions/17727645/how-to-update-gradle-in-android-studio – Raluca Lucaci Mar 30 '18 at 11:28
  • Yes, I have 4.6 installed on my system, and have set the project wrapper properties to 4.5 per the documentation – bryant Mar 30 '18 at 11:33