Gradle构建在启用数据绑定时失败

时间:2018-01-29 09:42:57

标签: android nullpointerexception android-gradle

我面临一个奇怪的问题。我决定在我的项目中启用数据绑定,为了这样做,我遵循了developer.android guidelines。所以我在gradle文件中添加了dataBinding标记,并且gradle sync失败并显示以下错误。

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

并且没有其他信息,以便我可以追踪问题。我的gradle文件如下:

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:0.10.6@aar') {
    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 个答案:

答案 0 :(得分:0)

数据绑定(以及Dagger)的问题在于,如果出现错误,则不会生成大量文件,从而产生大量错误。事实上,javac的默认输出不足以在底部看到错误消息。

大多数情况下,通过将其添加到build.gradle

,有助于增加错误输出行的最大数量
gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xmaxerrs" << "1500"
    }
}