Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle sync failed caused: java.lang.NullPointerException

Today i stared my Android Studio and this error pop up, yesterday everything was fine... really don't know what could go wrong, so i tried reinstall android studio, Android SDK build tools are installed, android SDK tools 25.2.2 also

help

from module app

apply plugin: 'com.android.application'


android {
    compileSdkVersion 23
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "oo"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
}

from project

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

EVENT LOG after starting android studio

> Error:Cause: java.lang.NullPointerException   at
> java.util.Objects.requireNonNull(Objects.java:203)    at
> java.util.Arrays$ArrayList.<init>(Arrays.java:3813)   at
> java.util.Arrays.asList(Arrays.java:3800)     at
> com.intellij.openapi.util.io.FileUtilRt.doCreateTempFile(FileUtilRt.java:399)
>   at
> com.intellij.openapi.util.io.FileUtilRt.createTempFile(FileUtilRt.java:361)
>   at
> com.intellij.openapi.util.io.FileUtilRt.createTempFile(FileUtilRt.java:341)
>   at
> com.intellij.openapi.util.io.FileUtilRt.createTempFile(FileUtilRt.java:334)
>   at
> com.intellij.openapi.util.io.FileUtil.createTempFile(FileUtil.java:1479)
>   at
> com.android.tools.idea.gradle.util.GradleUtil.addInitScriptCommandLineOption(GradleUtil.java:1064)
>   at
> com.android.tools.idea.gradle.util.GradleUtil.addLocalMavenRepoInitScriptCommandLineOption(GradleUtil.java:1057)
>   at
> com.android.tools.idea.gradle.util.GradleUtil.addLocalMavenRepoInitScriptCommandLineOption(GradleUtil.java:1023)
>   at
> com.android.tools.idea.gradle.project.AndroidGradleProjectResolver.getExtraCommandLineArgs(AndroidGradleProjectResolver.java:345)
>   at
> org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.doResolveProjectInfo(GradleProjectResolver.java:175)
>   at
> org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.access$300(GradleProjectResolver.java:73)
>   at
> org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:768)
>   at
> org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:752)
>   at
> org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper.execute(GradleExecutionHelper.java:238)
>   at
> org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:112)
>   at
> org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:73)
>   at
> com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:41)
>   at
> com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:37)
>   at
> com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:59)
>   at
> com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:37)
>   at
> com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:49)
>   at
> com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:51)
>   at
> com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:138)
>   at
> com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:124)
>   at
> com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3.execute(ExternalSystemUtil.java:419)
>   at
> com.intellij.openapi.externalSystem.util.ExternalSystemUtil$4$2.run(ExternalSystemUtil.java:500)
>   at
> com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:563)
>   at
> com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:142)
>   at
> com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:446)
>   at
> com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:392)
>   at
> com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
>   at
> com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:127)
>   at
> com.intellij.openapi.progress.impl.ProgressManagerImpl$1.run(ProgressManagerImpl.java:126)
>   at
> com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:369)
>   at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>   at java.util.concurrent.FutureTask.run(FutureTask.java:266)     at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>   at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>   at java.lang.Thread.run(Thread.java:745)
like image 298
Perhpethua Avatar asked Nov 15 '16 14:11

Perhpethua


People also ask

Why does gradle Sync Fail?

In some cases when your Gradle files are deleted or corrupted you will not be able to download new Gradle files in android studio. In this case, we have to delete the Gradle files which are present already and then again sync your project to download our Gradle files again.


4 Answers

The steps below helped me get out of this situation:

  • File -> Invalidate Caches / Restart -> Invalidate and Restart
  • Build -> Clean Project

Hope that helps!

like image 63
karthiks Avatar answered Oct 19 '22 03:10

karthiks


I ran into this issue when opening a React Native project incorrectly.

To fix this, I:

  • File > Close Project
  • Removed Project from the Welcome screen (cosmetic and not to get me into this mess again)
  • Chose > Import project (Gradle, Eclipse, ADT, etc.)
  • Chose my react-native-app-folder/android

After doing this, all errors were gone.

like image 29
TechnoTim Avatar answered Oct 19 '22 04:10

TechnoTim


I had this issue while editing the project structure of a Flutter project. My project was working fine before that.
So probably it was due to some misconfiguration.
I solved doing this:

  • close AndroidStudio
  • go to your/project/path and delete the .idea folder from your filesystem
  • open again your project with android studio

I tried one File > Invalidate Cache / Restart .. before doing that, but it was probably useless.

like image 3
Pado Avatar answered Oct 19 '22 03:10

Pado


The problem was resolved for me , after I made a fresh installation of studio.

For this

Step 1. Uninstall Android Studio. While uninstalling please make sure that you selected the additional option Android User Settings also.

Step 2. Goto user's home folder and delete folders .gradle, .AndroidStudiox.x(if it's still there). No need to delete or rename or relocate Workspace fodler.

Step 3. Now install android studio again.

Step 4. Let it download and build gradle.

Step 4. DONE.. :D

like image 2
Nikhil Bose Avatar answered Oct 19 '22 02:10

Nikhil Bose