I know that this question of mine has been asked many times and I did follow most of the answers but none of those helped me. So this is my problem, whenever I sync my proje
I was getting a NPE due to the jdk version, downgrading from 11 to 8 solved this issue
To remove jdk 11
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kaptDebugKotlin'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
Caused by: java.lang.NullPointerException
at org.gradle.workers.internal.DefaultWorkerExecutor$2.transform(DefaultWorkerExecutor.java:164)
at org.gradle.workers.internal.DefaultWorkerExecutor$2.transform(DefaultWorkerExecutor.java:161)
at org.gradle.util.CollectionUtils.collect(CollectionUtils.java:204)
at org.gradle.util.CollectionUtils.collect(CollectionUtils.java:187)
at org.gradle.util.CollectionUtils.collect(CollectionUtils.java:191)
at org.gradle.workers.internal.DefaultWorkerExecutor.getDaemonForkOptions(DefaultWorkerExecutor.java:161)
at org.gradle.workers.internal.DefaultWorkerExecutor.submit(DefaultWorkerExecutor.java:96)
at org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask.compile(KaptWithoutKotlincTask.kt:75)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
If you are still having this problem, even after deleting .gradle folder under your project's path, as suggested above, kill all Java processes running on the task manager and try to update your Android Studio.
I was in the same situation but now it works fine.
Hope it helps!
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'com.google.firebase:firebase-database:9.0.2'
Not sure this is the culprit, but you got pretty mess with used versions here. Try to use recent versions or at least the same for all components related.
This tool may help you stay in sync in future: https://github.com/ben-manes/gradle-versions-plugin
The issue is likely the gradle.properties file. If you type ./gradlew tasks
in the terminal, you see the error you mentioned but ./gradlew tasks --info
shows more details about the error. For me, in all my projects, it was the same error message:
Java home is different.
Wanted: DefaultDaemonContext[uid=null,javaHome=/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home,daemonRegistryDir=/Users/christian/.gradle/daemon,pid=66346,idleTimeout=null,daemonOpts=-XX:MaxPermSize=512m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1536m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
Actual: DefaultDaemonContext[uid=4bf81505-0eab-4f50-859a-8c9c616b97e5,javaHome=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home,daemonRegistryDir=/Users/christian/.gradle/daemon,pid=65018,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=512m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1536m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
Solution: (no need to edit .bash_profile
or downgrade gradle or delete gradle.folder).
org.gradle.java.home=path
in gradle.properties. where path
is the Android Studio java path (actual java home stated in the --info
log). For me, it's /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
, for you, the path could be different.This is what my gradle.properties file looks like after the change:
org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
org.gradle.daemon=true
Notes: The space between "Android Studio" in the path is intentional, it doesn't work if an underscore is used. Escape characters \
are allowed but not needed: ...Android\ Studio.app/Contents/jre....
I have also enabled the daemon build runner but not needed for gradlew to run its tasks. If your null pointer error is different, use --info
to point you in the right direction.
I'm running:
Android Studio 3.1.4 (on a Mac 10.13)
java version "10"
classpath 'com.android.tools.build:gradle:3.1.4' (dependency)
Hope it helps someone!
I've deleted .gradle folder from the project and was able to rebuild it again.
N.B: Make a backup, just in case.