97

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 project it always fails. Here is how the gradle console look like:

Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]

Configuration on demand is an incubating feature. Incremental java compilation is an incubating feature. :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAnimatedVectorDrawable2420Library UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72420Library UP-TO-DATE :app:prepareComAndroidSupportDesign2420Library UP-TO-DATE :app:prepareComAndroidSupportMediarouterV72300Library UP-TO-DATE :app:prepareComAndroidSupportRecyclerviewV72420Library UP-TO-DATE :app:prepareComAndroidSupportSupportCompat2420Library UP-TO-DATE :app:prepareComAndroidSupportSupportCoreUi2420Library UP-TO-DATE :app:prepareComAndroidSupportSupportCoreUtils2420Library UP-TO-DATE :app:prepareComAndroidSupportSupportFragment2420Library UP-TO-DATE :app:prepareComAndroidSupportSupportMediaCompat2420Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42420Library UP-TO-DATE :app:prepareComAndroidSupportSupportVectorDrawable2420Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServices940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAds940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAdsLite940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAnalytics940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAppindexing940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAppinvite940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAuth940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAuthBase940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesBase940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesBasement940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesCast940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesCastFramework940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesClearcut940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesContextmanager940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesDrive940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesFitness940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesGames940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesGass940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesGcm940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesIdentity940Library FAILURE: Build failed with an exception.

  • What went wrong: java.lang.NullPointerException (no error message)

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.518 secs

AND these are my dependencies

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    testCompile 'junit:junit:4.12'
    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'
    compile 'com.firebase:firebase-client-android:2.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
}

apply plugin: 'com.google.gms.google-services'

How to resolve the issue?

rbashish
  • 2,073
  • 2
  • 24
  • 35
sweetzyl pili
  • 1,023
  • 1
  • 7
  • 13
  • 4
    I was having the same issue just now. Build -> Clean Project, then rerun worked for me. – w3bshark Nov 01 '16 at 14:38
  • some times Android Studio not indentify errors like. 1.error sintaxis, 2.resources not found, 3.changes in code.. and others.. My case has changes not found.. – marlonpya Mar 06 '18 at 15:51
  • @marlonpya take a look [here](https://stackoverflow.com/a/52462269/1008011), the issue is most likely with gradle.properties. – chornge Sep 23 '18 at 01:45
  • Every time I update Android Studio, weird stuff like this happens. w3bshark's clean build worked for me. – Dale Mar 22 '19 at 20:25
  • Just restarting android studio solved my issue – Zain Nov 02 '21 at 18:31

17 Answers17

209

I've deleted .gradle folder from the project and was able to rebuild it again.

N.B: Make a backup, just in case.

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
rastik
  • 2,537
  • 2
  • 12
  • 14
  • Which gradle file do u mean? – sweetzyl pili Sep 21 '16 at 16:41
  • 6
    In the root folder of your project, there's ".gradle" folder. Delete it and restart Android Studio, it will be recreated during build. – rastik Sep 22 '16 at 21:46
  • Did you guys face something similar like this? ( http://stackoverflow.com/questions/39749380/failure-build-failed-with-an-exception-with-java-lang-nullpointerexception-no ). This certainly didn't work for me :/ @rastik – Siddhant Rimal Sep 28 '16 at 13:54
  • i cannot found any .gradle folder under my project folder , only gradle folder but not .gradle , i am using MAC , any1 solve this ? – aznelite89 Dec 30 '16 at 01:31
  • I'm trying to integrate Bamboo and there it responding same error. Remove folder did not work. Any other suggestion ? – CoDe Jan 31 '17 at 13:13
  • @aznelite89- in windows (.gradle) folder is hidden by default, you might wanna check that for mac. – Bawa Feb 21 '17 at 08:26
  • 6
    deleting .gradle is not working any other solutions? I see this compileDebugJavaWithJavac folder in app-tmp folder and it has empty folder named emptySourcePathRef... cleaning project deletes this folder so I assume this is it but still error appears – Aalap Patel Jul 28 '17 at 16:46
30

This Problem created when the suddenly System restarted, then gradle file corrupted. and that corrupted file cached, so we need to Delete this file from your project

your_project_path/.gradle/2.14.1/taskArtifacts

It will be re-generate again.

Then restart the Android studio and re-compile the project.

source : https://code.google.com/p/android/issues/detail?id=220741#c13

It is worked for me.

Kona Suresh
  • 1,836
  • 1
  • 15
  • 25
  • Just a note, ensure you close all projects window to restart the Android Studio, not just the project window. – 林果皞 Jun 19 '17 at 05:23
  • it works for me (pb with ionic (Ionic CLI) : 3.19.0) Execution failed for task ':compileArmv7DebugJavaWithJavac'. > java.lang.NullPointerException (no error message) – m50 Nov 22 '17 at 13:43
  • its there: your_project_path/android/.gradle – Shazaib Danish Oct 08 '22 at 13:36
6

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!

Community
  • 1
  • 1
Geraldo Neto
  • 3,670
  • 1
  • 30
  • 33
4

I have same problem when the java version is 1.9

jenv use java 1.8 

all problem is solved.

zhen She
  • 129
  • 1
  • 9
2

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).

  • Add 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!

chornge
  • 2,021
  • 3
  • 28
  • 37
  • 3
    when i am runnign command ./gradlew tasks then i am not getting any issue but on build time i am getting mentioned issue. – Anuj Mar 25 '19 at 09:56
2

The accepted solution is kinda risk and might not be the solution to most people.

The correct answer is that unfortunately there is not a single answer.

You must look the logs for your case ( Help > Show Logs, or Show Logs in Explorer and then open the idea.log file in your text editor)

There you will see the entire stack trace with the actual error where it happened.

From there, it would make sense to clear idea cache as the currently accepted solution mentions, or do something else (in my case it was a mismatched gradle/cmake/ndk versions and not deleting my .gradle cache folder would have helped)

gcb
  • 13,901
  • 7
  • 67
  • 92
1

I also had the same error. I solved it by: Invalidating Caches and Restart Android Studio

DharmanBot
  • 1,066
  • 2
  • 6
  • 10
Ali Zahid
  • 151
  • 2
  • 10
0
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

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

I had a similar problem when importing firebase into my project. First of all make sure that you followed the tutorial steps correctly and have imported the provided .json file into the right directory.

Also, since firebase v9.0 it has been implemented into the google play services, so for firebase to work properly, make sure that the Google play services are up to date on the device that you're testing,

I've also found this answer to be helpful while solving my issue https://stackoverflow.com/a/37310513/6728099

Community
  • 1
  • 1
sketch204
  • 1
  • 1
  • 5
  • actually even before I imported firebase it's still has the same error. I just added the firebase so I can move on on my project. Infact I created a dummy app to check if I correctly followed the tutorial. I also updated my AS and the SDK yet it wasn't solve the problem. – sweetzyl pili Aug 27 '16 at 17:27
0

Remove below lines from dependency's, because already you compile complete play services dependency

    compile 'com.google.android.gms:play-services-location:9.4.0'
    compile 'com.google.android.gms:play-services-appindexing:9.4.0'
Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81
  • 1
    Rebuild your project – Yogesh Rathi Aug 27 '16 at 17:39
  • Use firebase and play service 9.0 , i am using then working perfectly so can you check again with 9.0 version – Yogesh Rathi Aug 27 '16 at 17:40
  • I did Rebuild many times. Instead of solving the problem it got more NullPointerException:null. – sweetzyl pili Aug 27 '16 at 17:41
  • Have you integrated multidex support library – Yogesh Rathi Aug 27 '16 at 17:42
  • yes I did it this way. defaultConfig { ... multiDexEnabled true } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } Is this correct? And also I already check the 9.0 version of play service and firebase still got the same error. – sweetzyl pili Aug 27 '16 at 17:48
  • http://stackoverflow.com/questions/26925264/android-support-multidex-library-implementation. Here is implementation how to integrate can you check, if you not understand then tell me ok – Yogesh Rathi Aug 27 '16 at 17:50
0

Check your app/build.gradle. My problem was a ' in a dependency.

Pablo Cegarra
  • 20,955
  • 12
  • 92
  • 110
0

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)
AntPachon
  • 1,152
  • 12
  • 14
0

For me it worked to delete the Gradle cache on user directory level: /Users/<username>/.gradle/cache. The --info option showed an inconsistency there.

Sandro
  • 1,757
  • 1
  • 19
  • 29
0

For me, the issue was the open source project was using older version of gradle 3.4.0.

Edit build.gradle and change com.android.tools.build:gradle:x.x.x to the latest version in the dependency. In my case, com.android.tools.build:gradle:4.1.2

Open the project in Android Studio again, you will now see another error message about minimum Gradle version like in the screenshot below

A screenshot of the gradle version error

Click on the blue text Fix Gradle wrapper and re-import project. You should be good to go

0

Also check your dependencies in the build.gradle file

In my own case, I removed the Glide library (implementation "com.github.bumptech.glide:glide:4.9.0") without deleting the corresponding annotation library (annotationProcessor "com.github.bumptech.glide:compiler:4.11.0")

After removing these two libraries, the build error was fixed.

inspiredMichael
  • 370
  • 4
  • 9
0

check local.properties file. See if the *.dir value is pointing to correct folder.

In my case ndk.dir was poiting to some other folder. When I fixed that the issue was gone.

ndk.dir=E\:\\Android\\local\\Android\\Sdk\\ndk-bundle
sdk.dir=E\:\\Android\\local\\Android\\Sdk
tanni tanna
  • 544
  • 4
  • 12
0

I'm in Android Studio Electric Eel | 2022.1.1

In my case the Problem occurred when the IDE was not responding and I force quit then restarted the IDE, then maybe (gradle file corrupted. and that corrupted file cached)

I've solved the issue simply by Invalidating cache and restart.

Note:

Click File-> Invalidate Caches...

You may need to check all the cases on the popup window.