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

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"

        jackOptions {
            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'.

java.lang.NullPointerException (no error message)

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

Piero Tozzi
  • 219
  • 2
  • 3
  • 4
  • 1
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – DimaSan Oct 18 '16 at 12:41

6 Answers6

19

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 -version
java version "10.0.1" 2018-04-17

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

LLL
  • 1,777
  • 1
  • 15
  • 31
  • Downgrading the Java on my machine from Java 10 to Java 8 also fixed this problem. But I downgraded by uninstalling Java 10 by following https://www.howtogeek.com/230145/how-to-uninstall-java-on-mac-os-x/ – Michael Osofsky Sep 10 '18 at 21:41
  • Thanks, lol after 3 hours installing, uninstalling stuff it should be done this simple move ;D – Ernestyno Sep 22 '18 at 20:55
  • That's really oddly in my Android Studio, everything is normal when I using gradle tool build tasks, and in terminal `./gradlew build` will output: NullPointerException(no messages), no any key logs. My macOS Java version: java 12.0.1 2019-04-16, after I removed `compileOptions` block anything is be ok. – Codios Dec 27 '19 at 03:21
4

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.

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

I'm not sure it works for you.

Mark Shen
  • 346
  • 1
  • 5
  • After changing the version from 2.2.0 to 2.1.0 it shows me Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/org.jgrapht/jgrapht-ext/pom.xml File1: C:\Users\Piero\AndroidStudioProjects\IoTforEmergencyandNavigation\app\lib\jgrapht-ext-1.0.0.jar File2: C:\Users\Piero\AndroidStudioProjects\IoTforEmergencyandNavigation\app\lib\jgrapht-ext-1.0.0-uber.jar – Piero Tozzi Oct 28 '16 at 19:52
  • This helped me I thank you so much :), I have been trying for 3 days to configure OpenCV with Android Studio. This is the only thing that worked for me thank you so much I really appreciate it :) – cuber Dec 28 '16 at 20:26
  • Where does this go? – gaharrington Jun 18 '17 at 14:30
  • 1
    In answer to the question that @gaharrington asked, this `classpath` line is part of the top-level build.gradle file. However, gradle 2.1.0 is really old by now, so this solution is probably not helpful for most people anymore. – Matt Dec 11 '20 at 18:12
2

Add this to your app module's build.gradle file:

lintOptions {
    checkReleaseBuilds false
}
Vlad Dogadaev
  • 97
  • 2
  • 10
0

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 jack support to true should not be required anymore. This worked for me.

Community
  • 1
  • 1
ebarault
  • 126
  • 5
0

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:

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)
cesards
  • 15,882
  • 11
  • 70
  • 65
-6

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