Materialdrawer: Problem with Instant App

Created on 18 Nov 2018  ·  3Comments  ·  Source: mikepenz/MaterialDrawer

About this issue

  • First, thanks for creating a beautiful library
  • I created a DrawerItem like OverflowMenuDrawerItem in the example, it works perfectly in the installed app but bindViewHelper(viewHolder) cause NullPointerException in instant app.
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(android.content.res.ColorStateList)' on a null object reference
  • It crashed in viewHolder.name.setTextColor(selectedTextColor); in BaseDescribeableDrawerItem when call bindViewHelper(viewHolder). When i try cath it, instant app can start normally (but draweritem doesn' have name and description)
  • My class using the same layout as the example
    myclass

Details

  • Kotlin language
  • Material Drawer 6.1.1
  • Support library version 1.0.0 (AndroidX)
  • Gradle build tools version 28.0.3
  • Android Studio version 3.2.1 (Stable)
question

All 3 comments

@sonhvp sorry for the late answer.

I am not sure how this could be an issue of the library :/.
The library uses normal layouts, and accesses the views of the layout via their identifier. as it is supposed to be.

could it be some issue with the setup of the instant app? is the drawer not in the right module, and not shipped?

or your item being in the wrong module missing the layout? or such?

After tested many times. I don't think the library is the reason cause crash. As you mentioned, the library uses normal layouts, and accesses the views of the layout via their identifier. I checked and tested so many times but can't understand why. I think the instant app feature has something wrong. If you want to see the issue, you can have a look at my test repository: https://github.com/sonhvp/test_project.
Thanks for your support.

@sonhvp so I believe I figured out what is going on here.

So the id's of the materialDrawer are in the com.mikepenz.materialdrawer.R class. Wheras your id's are in the com.sonhvp.test class. So when you then use your own xml file, the id's are in your namespace, but the BaseViewHolder tries to find the ids in the materialdrawer namespace. As such it will not be able to find the views and they stay null.

To solve the problem just add:

        init {
            this.icon = view.findViewById(R.id.material_drawer_icon)
            this.name = view.findViewById(R.id.material_drawer_name)
            this.description = view.findViewById(R.id.material_drawer_description)
        }

to your ViewHolder in the OverflowMenuDrawerItem (ensure it is the R of your package)


If I am not wrong it works for the app because the R fields for identifiers are there still merged, and same identifiers are just merged and will be the same id. Whereas for instantapps this does not happen. (at least this is my assumption)

In addition I believe google's plan is to have the same for normal modules at some point in the future too. basically namespacing all identifiers and layouts and prevent them being overwritten from a different module.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HanderWei picture HanderWei  ·  3Comments

AlexMercier picture AlexMercier  ·  3Comments

Erwinstein picture Erwinstein  ·  3Comments

wayne1203 picture wayne1203  ·  3Comments

armoun picture armoun  ·  3Comments