简体   繁体   中英

Trouble upgrading to new com.android.support:support-v4:24.2.0 library

I have an an android app that is working correctly on 24.0.0 -- below are my gradle dependencies:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
    compile 'com.android.support:cardview-v7:24.0.0'
    compile 'com.android.support:recyclerview-v7:24.0.0'
    compile 'com.android.support:palette-v7:24.0.0'
    compile files('libs/ksoap2-android-assembly-3.6.1-jar-with-dependencies.jar')
}

But I downloaded the most recent SDK, and am interested in upgrading to 24.2.0. Since I need the support libraries, I added com.android.support:support-v4 to the dependencies as follows:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:support-v4:24.2.0'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.android.support:cardview-v7:24.2.0'
    compile 'com.android.support:recyclerview-v7:24.2.0'
    compile 'com.android.support:palette-v7:24.2.0'
    compile files('libs/ksoap2-android-assembly-3.6.1-jar-with-dependencies.jar')
}

This causes the following exception:

   java.lang.NullPointerException: Attempt to invoke virtual method 
     'android.graphics.drawable.Drawable[] android.widget.TextView.getCompoundDrawables()' 
     on a null object reference
     at android.support.v4.widget.TextViewCompat.getCompoundDrawablesRelative(TextViewCompat.java:285)

Did I miss something in the documentation that I should do outside of including support-v4 when upgrading? This is my reference: https://developer.android.com/topic/libraries/support-library/features.html#v4

Note: Prior to Support Library revision 24.2.0, there was a single v4 support library. That library was divided into multiple modules to improve efficiency. For backwards compatibility, if you list support-v4 in your Gradle script, your APK will include all of the v4 modules.

Thanks for your help!

I get the exact same exception after upgrading to support library revision 24.2.0 and build tools 24.0.2 when trying to inflate a layout that includes a TextInputLayout that does NOT have an EditText inside of it.

If I comment out the TextInputLayout without the EditText inside it, the exception goes away. If this is not possible, I would recommend rolling back to the previous version of the support library until this is resolved.

update your Android Sdk Build-tools to

24.0.2 

and add them as buildtools in module app build.gradle

Try to clean & rebuild your project it helps to clear previous applied dependencies from cache.

update

Try to run this app in Api24 with 7.0 emulator since your target sdk is 24 may be it will help you but as your min sdk is 21 so this also works on that emulators too.
also follow this Android Studio-> File -> Invalidate cache and Restart android studio Invalidate Restart

It can be that you are wrapping something other than a

android.support.design.widget.TextInputEditText

with a

android.support.design.widget.TextInputLayout

I recently hit this problem and found the issue to be the following in the layout file

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="100dp">

        </android.support.design.widget.TextInputEditText>

This was from the default google login example.

Removing this fixed the nullpointer error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM