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 witharm64-v8aandarmeabi-v7a):
This can cut the SDK’s native library size by 50% or more if you were including all ABIs.android { defaultConfig { ndk { abiFilters 'armeabi-v7a', 'arm64-v8a' } } } - 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.opentokclasses are gone and only your target ABIs appear in thelibfolder.
内容的提问来源于stack exchange,提问作者vickyVick
相关产品推荐
相关产品推荐

