R8 & Proguard Obfuscation

In most scenarios, app packages can be compressed through obfuscation. Here is an introduction to how to configure obfuscation rules.

Hikage itself does not require additional obfuscation rules. Since View objects created by Hikage do not need to be declared in XML, their class names can also be obfuscated.

Keep Custom Constructors

If a custom View is not declared in XML, R8 may remove constructors that it cannot discover directly. To let Hikage continue creating custom Views through the (Context) or (Context, AttributeSet) constructors, add the following rule.

This rule keeps only the constructors and still allows class names to be obfuscated.

-keep,allowobfuscation class * extends android.view.View {
    <init>(...);
}

Tips

If you are using layout component functions (Hikage Performer) generated by hikage-gradle-plugin or hikage-compiler, the above rule is no longer necessary.

If you provide a custom ViewGroup.LayoutParams and it is only created through Hikage's LayoutParams DSL, you also need to keep its constructors.

-keep,allowobfuscation class * extends android.view.ViewGroup$LayoutParams {
    <init>(...);
}

XML Attribute Set String References

HikageAttribute string resource references follow the same form as XML.

HikageAttribute {
    app {
        set("dataSets", "@array/simple_string_data")
    }
}

This form resolves resources by name at runtime. R8 code obfuscation does not affect it, but if you have isShrinkResources = true configured and the target resource is only referenced through this string, the resource shrinker may consider it unused and remove it.

You can solve this problem by using direct resource ID references.

HikageAttribute {
    app {
        set("dataSets", R.array.simple_string_data)
    }
}

If you must keep the XML-style string reference, add a resource keep file in the app module, for example res/raw/my_res_keep.xml.

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@array/simple_string_data" />

The same applies to custom attrs.xml enum, flag, and reference values that are only reached through dynamic strings. Use resource IDs where possible, or keep the corresponding resources with tools:keep.

Notice

If you do not include the hikage-runtime-attribute module because you do not need this feature, you need to configure the following rule to avoid warnings from R8 about missing classes or errors during compilation.

-dontwarn com.highcapable.hikage.runtime.attribute.**