gradle sync失败导致:java.lang.NullPointerException

时间:2016-11-15 14:32:41

标签: android-studio gradle

今天我盯着我的Android Studio并弹出这个错误,昨天一切都很好...... 真的不知道会出什么问题,所以我尝试重新安装android studio,安装Android SDK构建工具,安装android SDK工具25.2.2

帮助

来自模块应用

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'
}

来自项目

// 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
}

启动android studio后的EVENT LOG

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

6 个答案:

答案 0 :(得分:10)

以下步骤帮助我摆脱了这种情况:

  • 文件 - &gt;无效缓存/重新启动 - &gt;无效并重新启动
  • 构建 - &gt;清洁项目

希望有所帮助!

答案 1 :(得分:2)

在我全新安装工作室之后,我的问题得到了解决。

对于此

步骤1. 卸载Android Studio 。在卸载时,请确保您还选择了其他选项 Android用户设置

步骤2.转到用户的主页文件夹和删除文件夹 .gradle,.AndroidStudio xx(如果它&#39;仍然在那里)。无需删除或重命名或重定位Workspace fodler。

步骤3.现在再次安装android studio

步骤4.让它下载并构建gradle。

步骤4.完成..:D

答案 2 :(得分:1)

所以,经过如此多的尝试让Android Studio 2.2.2真正发挥作用之后,下面描述了更少的痛苦和最佳解决方案:),所以对于那些使用这个新版本的Android保持遇到问题的人工作室( 2.2.2 )...构建将无法正常工作,即使裸安装也无法成功完成我建议全新安装旧版本 - 在我的情况下<强> 2.1.1

全新安装:

1 打开控制面板 - &gt;卸载Android Studio - &gt;选择SDK和用户设置

2 go:C:/ Program Files / Android - &gt;删除

3 go:C:/ Users / UserName /并删除.android,。Android Studio2.2,.gradle以及任何m2文件夹

4 下载版本2.1.1,您可以使用以下链接:http://tools.android.com/download/studio/builds/2-1-1

下载解压缩文件后

5 转到文件夹android-studio / bin - &gt;双击studio.exe(32位)或studio64.exe(64位)打开安装程序

6 最后开始写一些代码^^

答案 3 :(得分:1)

我错误地打开React Native项目时遇到了这个问题。

要解决此问题,我:

  • 文件>关闭项目
  • 从“欢迎”屏幕中删除了项目(美观,不要让我再次陷入困境)
  • 选择>导入项目(Gradle,Eclipse,ADT等)
  • 选择我的int N = 10379 int S1 = 3701; int d = 37; int T1 = S1 ^ d % N; double F = 10379 double S2 = 3701; double e = 37; double T2 = Math.Pow(S2, e) % F;

这样做之后,所有错误都消失了。

答案 4 :(得分:0)

对我来说有用的是

  1. 确保备份源和资产。

  2. 删除项目并重新创建。

  3. 在项目创建完成后添加Gdx-freetype扩展名后,我遇到了这个问题。当我重新创建项目时,我确保选中它的框,以便在创建项目时添加它。

答案 5 :(得分:0)

在编辑 Flutter 项目的项目结构时遇到了这个问题。在那之前我的项目运行良好。
可能是由于配置错误所致。
我解决了这个问题:

  • 关闭AndroidStudio
  • 转到your/project/path并从文件系统中删除.idea文件夹
  • 再次使用android studio打开项目

在此之前,我尝试过一个File > Invalidate Cache / Restart ..,但可能没用。