Gradle build fails on enabling data binding

Refresh

April 2019

Views

352 time

1

i am facing a strange issue. I have decided to enable databinding in my project and in order to do so i followed the developer.android guidelines. So i added the dataBinding tag in my gradle file and gradle sync fails and shows the following error.

Error:java.lang.NullPointerException
Error:Execution failed for task ':app:mergeDebugResources'.
Error: java.lang.NullPointerException

and no other information is there so that i can track down the problem. My gradle file is below:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
    applicationId '***.********.***'
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 76
    versionName '4.8.3'
    testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    // Enabling multidex support.
    multiDexEnabled true
    vectorDrawables.useSupportLibrary = true

}
//todo useLibrary is added agains LinkedInActivity which uses legacy http connection,
//should change it to different implementation
useLibrary 'org.apache.http.legacy'
dexOptions {
    jumboMode true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
    }
}

packagingOptions {
    exclude 'build.xml'
    exclude 'lib/getLibs.ps1'
    exclude 'lib/getLibs.sh'
    exclude 'lib/gson-2.2.2.jar'
}

dataBinding {
    enabled = true
}
lintOptions {
    disable 'MissingTranslation'
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':library_fab')
implementation project(':library')
implementation project(':barcodeScannerLib')
implementation project(':cropper')
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
}
compile 
('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:[email protected]') {
    transitive = true
}

implementation project(':libraryDatePicker')
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.code.gson:gson:2.3.1'
compile 'de.greenrobot:greendao:1.3.7'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-analytics:8.3.0'
compile 'com.facebook.android:facebook-android-sdk:4.8.0'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:cardview-v7:26.0.1'
compile 'com.android.support:recyclerview-v7:26.0.1'
compile 'com.android.support:palette-v7:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'com.github.amlcurran.showcaseview:library:5.4.3'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:exifinterface:26.0.1'
implementation project(':librarySweetAlertDialog')
}
apply plugin: 'com.google.gms.google-services'


configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == 'com.android.support') {
        if (!requested.name.startsWith("multidex")) {
            details.useVersion '25.4.0'
        }
    }
}
}

1 answers

0

The problem with Databinding (and Dagger as well) is that, if there's an error, a lot of files are not generated, giving lots of errors. So much in fact, that the default output of javac is not enough to see the error message at the bottom.

Most of the time, it helps to increase the maximum number of error output lines, by adding this to your build.gradle

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xmaxerrs" << "1500"
    }
}