android design library gradle null pointer excepti

2019-06-17 05:11发布

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.

library version

Another similar issue didn't help me

Notice that i'm building using Intellij 14

2条回答
倾城 Initia
2楼-- · 2019-06-17 05:38

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

查看更多
Explosion°爆炸
3楼-- · 2019-06-17 05:55

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).

查看更多
登录 后发表回答