android design library gradle null pointer exception

无人久伴 提交于 2019-12-23 08:35:08

问题


I'm trying to add android.support.design library to my project: All the interesting things in my gradle file:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:design:22.2.0'
    compile 'com.android.support:support-annotations:22.0.0'
    compile 'com.android.support:support-v13:22.1.1'
    compile 'com.android.support:recyclerview-v7:22.1.1'
    compile 'com.android.support:cardview-v7:22.1.0'
}

I'm getting

Error:Android Gradle Build Target: java.lang.NullPointerException

When removing com.android.support:design:22.2.0 (and adding back v4 and AppCompat), build is successful.

Another similar issue didn't help me

Notice that i'm building using Intellij 14


回答1:


I ran the app using android studio and not IntelliJ 14 and got a different error:

`Error:(1) Attribute "insetForeground" has already been defined`

So if someone is running IntelliJ 14, until next update of Intellij 14 I guess It's safer to use android studio 1.3.+ (or at least check for errors using android studio.

If one get the same error.

  • go to attr.xml and remove declare-styleable name="ScrimInsetsView"

  • using ctrl-shift-f search for insetF and remove app:insetForeground attribute from all the layout that contains such attribute.

Everything should work OK now




回答2:


I had exactly the same issue. I guess it comes from an combination of mismatching parameters in grade and your xml resources.. Maybe this will help (for me it did):

buildscript {
    repositories {
        jcenter()
    }  
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.1'
    }
}
apply plugin: 'com.android.application'

...

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:design:23.0.0'
    compile 'com.android.support:cardview-v7:21.0.3'
    compile 'com.android.support:recyclerview-v7:21.0.3'
}

Give the build.grade the 1.1.1, too (just in case)

// 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:1.1.1'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}

Hopefully the next sync, clean and rebuild will pass (or fire a meaningful error message like 'color-res blabla not found').

Btw: From time to time my IntelliJ is setting itself to other Java-configs (e.g. Java8 with lambdas) - so "just in case": Don't forget to check if your project SDK is set up correctly (File > Project-structure > project > choose the SDK).



来源:https://stackoverflow.com/questions/30621242/android-design-library-gradle-null-pointer-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!