java.lang.NullPointerException (无错误信息) APK 构建

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40108471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:56:06  来源:igfitidea点击:

java.lang.NullPointerException (no error message) APK building

javaandroidgradle

提问by Piero Tozzi

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

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        jcenter()
    }
    dependencies {
        classpath "gradle.plugin.me.tatarka:gradle-retrolambda:3.3.0"
        classpath 'com.android.tools.build:gradle:2.2.1'
    }
}
allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

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

The :app file

:app 文件

apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.3"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "it.univpm.gruppoids.iotforemergencyandnavigation"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        HymanOptions {
            enabled true
        }
    }



    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    compile 'com.google.zxing:core:3.2.1'
    compile 'org.jgrapht:jgrapht-core:1.0.0'
}

When i try to build APK it shows me: Error:A problem occurred configuring project ':app'.

当我尝试构建 APK 时,它向我显示:错误:配置项目“:app”时出现问题。

java.lang.NullPointerException (no error message)

java.lang.NullPointerException(无错误信息)

Is it a problem with versions? or with lamdas?? someone can help me?

是不是版本问题?或与lamdas?有人可以帮助我吗?

回答by LLL

I had the same issue after adding:

添加后我遇到了同样的问题:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

It was because my default java version was 10:

这是因为我的默认 java 版本是 10:

$ java -version
java version "10.0.1" 2018-04-17

After changing to 1.8 (with sudo update-alternatives --config java) issue was fixed.

更改为 1.8(使用sudo update-alternatives --config java)后问题已修复。

回答by Mark Shen

I have had the same kind of problem these days. I found it might be caused by the version of gradle. After changing the version to 2.1.0, the problem's gone.

这些天我遇到了同样的问题。我发现这可能是由 gradle 的版本引起的。把版本改成2.1.0后,问题就解决了。

dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
    }

I'm not sure it works for you.

我不确定它对你有用。

回答by Vlad Dogadaev

Add this to your app module's build.gradlefile:

将此添加到您的应用程序模块的build.gradle文件中:

lintOptions {
    checkReleaseBuilds false
}

回答by cesards

Android compiles by default with Java 7 but your project might be using some Java 8 features. If you recently switched from Oracle JDK to Open JDK, make sure you are using Java 8. In your terminal, if you run java -version, the output should be something like:

默认情况下,Android 使用 Java 7 进行编译,但您的项目可能会使用某些 Java 8 功能。如果您最近从 Oracle JDK 切换到 Open JDK,请确保您使用的是 Java 8。在您的终端中,如果您运行java -version,输出应该类似于:

openjdk version "1.8.0_222"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.222-b10, mixed mode)

回答by ebarault

see this other issue: while this is stated in Retrolambda documentation you should not specify JAVA version to 1.8 while using Retrolambda. Therefore setting Hyman support to true should not be required anymore. This worked for me.

请参阅另一个问题:虽然这在 Retrolambda 文档中有所说明,但在使用 Retrolambda 时不应将 JAVA 版本指定为 1.8。因此,不再需要将 Hyman support 设置为 true。这对我有用。

回答by Kishan Rabadiya

Just Delete your project under contains .gradle folder and restart android studio. it tested by and approve by google developer pages. It 100% working.

只需删除包含 .gradle 文件夹下的项目并重新启动 android studio。它由谷歌开发者页面测试和批准。它 100% 工作。