简体   繁体   中英

app:layout_behavior XML crash if productFlavors used

Let FAB button be:

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_anchor="@id/appbar"
    app:layout_anchorGravity="bottom|left|end"
    app:srcCompat="@drawable/ic_arrow_drop_down"
    app:layout_behavior=".ScrollingFABBehavior"
    />

...where ScrollingFABBehavior is

public class ScrollingFABBehavior extends CoordinatorLayout.Behavior<FloatingActionButton> {

It works perfectly in main flavor (com.xxx.flavor1), but second flavor gives me crash:

Caused by: android.view.InflateException: Binary XML file line #108 in com.xxx.flavor2:layout/main: Could not inflate Behavior subclass com.xxx.flavor2.ScrollingFABBehavior

If I set the behavior programmatically, it works perfectly both in first and second flavors. Thus looks like flavor system is broken in XML processing. Don't you know how to fix it right in XML?

ps Exactly the same crash if set behavior for AppBarLayout.

Yes you are right, there is something wrong with library, when you add your custom behaviour, proguard is not able to link it, and prunes it (when you use it via xml). If you want yo use it via xml then you will have to force proguard to not prune this file, This issue has earlier been reported too. check the below link. https://stackoverflow.com/a/30846201/3497972

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