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?
In Java, the java. lang. NullPointerException is thrown when a reference variable is accessed (or de-referenced) and is not pointing to any object. This error can be resolved by using a try-catch block or an if-else condition to check if a reference variable is null before dereferencing it.
The java. lang. NullPointerException is a runtime exception in Java that occurs when a variable is accessed which is not pointing to any object and refers to nothing or null. Since the NullPointerException is a runtime exception, it doesn't need to be caught and handled explicitly in application code.
Detecting NullPointerException is very easy, just look at the exception trace and it will show you the class name and line number of the exception. Then look at the code and see what could be null causing the NullPointerException.
Generally It is recommend that one should not catch NullPointerException and let it be handled by JVM. if you will not do, then chances are there that NullPointerException can occur if no data is there. In reality, your example shows why it is a BAD IDEA to catch NPEs.
I've deleted .gradle folder from the project and was able to rebuild it again.
N.B: Make a backup, just in case.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With