Mobile Development 20 min read

APK Size Reduction Techniques for the iQIYI Android Client

The article outlines a comprehensive set of APK‑slimming techniques for the iQIYI Android client—including pluginization, 7‑ZIP recompression, apksigner signing, duplicate‑resource removal, PNG/WebP conversion, library trimming, code obfuscation, R‑class elimination, language‑config pruning and native‑ABI reduction—that together cut the package from 54.2 MB to 28.2 MB.

iQIYI Technical Product Team
iQIYI Technical Product Team
iQIYI Technical Product Team
APK Size Reduction Techniques for the iQIYI Android Client

This article presents a comprehensive guide on reducing the size of the iQIYI Android application (APK) while maintaining user experience. It begins with an overview of why APK slimming is important: large APKs consume more mobile data, memory, and lead to slower installation and loading, especially on low‑end devices.

APK Composition

The APK is a compressed archive containing several directories such as res , lib , assets , META-INF , classes.dex , resources.arsc and AndroidManifest.xml . A table in the original text describes the purpose of each folder.

Overall Optimization Strategies

1. Pluginization : Independent modules (e.g., games, comics, ticketing) are packaged as plugins and downloaded on demand, reducing the base APK size.

2. 7‑ZIP Re‑compression : Re‑compressing the APK with 7‑ZIP significantly shrinks the .arsc file and other resources, typically saving a few megabytes.

3. Signature Method : Using the newer apksigner tool (available from Android 7.0) reduces APK size by about 5% compared with the older jarsigner approach.

Comparative images in the source illustrate the size differences among unsigned, jarsigner ‑signed, and apksigner ‑signed APKs.

Resource‑Level Optimizations

2.1 Remove Duplicate Resources : Scan files by MD5 to delete identical images with different names.

2.2 Remove Unused Resources : Use Android Lint or a custom scanning tool (e.g., ScanUnusedResouce ) to find resources that are never referenced. Ensure that reflection or resource concatenation does not rely on those assets before deletion.

2.3 PNG Compression : Apply tools such as pngcrush , pngquant , or zopflipng , or online services like TinyPNG, to compress PNG files without quality loss.

2.4 WebP Conversion : Convert non‑transparent images to WebP (lossy or lossless) using Android Studio’s “Convert to WebP” or the cwebp command‑line tool. Note the compatibility matrix: Android 4.2+ supports both lossless and lossy WebP, while 4.0/4.1 only support lossy WebP without alpha.

2.5 Library Resource Trimming : Replace large unused images in third‑party libraries with 1×1 transparent placeholders.

2.6 Large Background Images : Use solid‑color placeholders at startup and download high‑resolution backgrounds later.

2.7 Lottie Animations : Replace heavy frame‑by‑frame animations with JSON‑based Lottie animations (e.g., lottie‑android ).

2.8 Other Resource Strategies : Prefer vector drawables or shape XML, use .9 PNGs, and avoid unnecessary image assets.

Code‑Level Optimizations

3.1 Code Obfuscation : Enable minifyEnabled true and shrinkResources true in Gradle to run ProGuard/R8, which removes dead code and shrinks resources.

Example Gradle configuration:

android {
    // Other settings
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

3.2 Unused Code Scanning : Use SonarQube or similar tools to detect dead classes and duplicated code, taking care not to delete code accessed via reflection from plugins.

3.3 Removing the R Class : Replace resource accesses with hard‑coded constants and delete the generated R.class . Open‑source ThinRPlugin can automate this.

3.4 Annotation Instead of Enum : Replace enums with @IntDef annotated integer constants to reduce class file size. Example enum and its annotation‑based replacement are shown below.

public enum MarkViewType3 {
    SIMPLE_TEXT_MARK,
    DO_LIKE_MARK,
    BOTTOM_BANNER1,
    BOTTOM_BANNER2,
    TL_GREY_BACKGROUND_RANK,
    SERVICENAVIRIGHTMARK,
    BOTTOM_COMPOUND_TEXT_BANNER;
}

Annotation version (simplified):

public class MarkViewType1 {
    public static final int SIMPLE_TEXT_MARK = 0;
    public static final int DO_LIKE_MARK = 1;
    // ... other constants ...
    @IntDef({SIMPLE_TEXT_MARK, DO_LIKE_MARK, BOTTOM_BANNER1, BOTTOM_BANNER2, TL_GREY_BACKGROUND_RANK, SERVICENAVIRIGHTMARK, BOTTOM_COMPOUND_TEXT_BANNER})
    @Retention(RetentionPolicy.SOURCE)
    public @interface MarkViewType1Anno {}
}

3.5 R File Elimination Impact : Removing the R class reduces dex size and memory usage, especially when many resources are present.

.arsc File Optimization

Configure resConfigs in Gradle to keep only required language resources, e.g., zh, zh_CN, zh_HK, zh_MO, zh_TW, en, which can shave off ~100 KB.

Native Library Optimization

Limit native lib directories to the primary ABI (armeabi) and use pluginization for large RN (React Native) libraries, saving over 1 MB.

Results

By applying all the above techniques, the iQIYI Android APK size decreased from 54.2 MB to 28.2 MB – a reduction of more than 20 MB.

Challenges Encountered

• WebP conversion must be applied consistently to all related assets to avoid missing resources at runtime. • Signing order matters: apksigner requires a prior zipalign , whereas jarsigner signs first and then aligns.

Conclusion

APK slimming is an ongoing effort that combines pluginization, resource compression, code obfuscation, and careful build‑tool configuration. Continuous monitoring and adoption of new tools (e.g., vector drawables, Lottie) will further keep the app lightweight and performant.

mobile developmentAndroidGradlecode obfuscationAPK optimizationresource shrinking
iQIYI Technical Product Team
Written by

iQIYI Technical Product Team

The technical product team of iQIYI

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.