You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TokBox(OpenTok) Android SDK体积过大问题求助

Great question—stripping out unused OpenTok SDK features with ProGuard is absolutely feasible, and it can slash that bulky footprint down quite a bit. Let’s break down the exact rules you need, plus some extra tips to maximize savings:

Targeted ProGuard Rules for OpenTok Android SDK

Add these rules to your proguard-rules.pro file to retain only core video call functionality and remove unused features like screen sharing, picture-in-picture, and custom audio drivers:

# Keep core OpenTok video call classes (essential for basic video chats)
-keep class com.opentok.** {
    public *;
}

# Strip screen sharing components
-assumenosideeffects class com.opentok.screenshare.** { *; }
-assumenosideeffects class com.opentok.android.ScreenCapturePublisher { *; }

# Remove picture-in-picture features
-assumenosideeffects class com.opentok.android.PictureInPictureRenderer { *; }
-assumenosideeffects class com.opentok.android.PictureInPictureParams { *; }

# Eliminate custom audio driver modules
-assumenosideeffects class com.opentok.audio.** { *; }
-assumenosideeffects class com.opentok.android.AudioDeviceManager { *; }
-assumenosideeffects class com.opentok.android.BaseAudioDevice { *; }

# Optional: Uncomment below if you don't use text chat features
# -assumenosideeffects class com.opentok.chat.** { *; }

These rules tell ProGuard to safely discard classes tied to unused features (marked with assumenosideeffects, meaning they don’t impact core functionality) while preserving all critical video call logic.

Extra Optimization Tips to Shrink Further
  • Filter CPU Architectures: OpenTok includes native libraries for multiple ABIs. In your app-level build.gradle, only keep the architectures your target devices use (most modern phones work with arm64-v8a and armeabi-v7a):
    android {
        defaultConfig {
            ndk {
                abiFilters 'armeabi-v7a', 'arm64-v8a'
            }
        }
    }
    
    This can cut the SDK’s native library size by 50% or more if you were including all ABIs.
  • Use Modular SDKs: Check if you’re using the full OpenTok SDK or a lighter core module. Some versions split features into separate packages (e.g., core video + optional screen sharing add-ons)—switching to the core module removes the need for ProGuard stripping entirely.
  • Validate the Result: After applying changes, use Android Studio’s Analyze > Analyze APK tool to inspect your final bundle. Verify that unused com.opentok classes are gone and only your target ABIs appear in the lib folder.

内容的提问来源于stack exchange,提问作者vickyVick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 16:02:41