Proguard 可以保存到 multidex 应用程序吗?
May Proguard save going to multidex app ?
我有一个带有几个库的应用程序,达到了 65536 方法计数的红线。
- 我成功地将应用设置为
multidex
APK。
- 为了优化大小,我决定使用 Proguard,因为我只使用了
Guava
和 common.java.lang
的一些功能,而这些库带来了他们的整个家庭。
- Proguard 作业完成后,我的应用程序引用了 ~ 45 Kmethods
- 我经常看到 multidex 应用程序有时会崩溃
- 而且由于 second-dex 运行时加载,这需要时间。
4和5是真的吗?
然后我只是尝试不使用 mutidex
,因为我的最终方法计数是 < 56Kmethods with prodGuard,但它失败了,好像它有更多!
为此,我只是将gradle参数multiDexEnabled
设置为false
还有什么要check/do的吗?
这是我的一部分 Gradle :
android {
compileSdkVersion ANDROID_BUILD_SDK_VERSION
buildToolsVersion ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
applicationId "XXXX"
targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION
minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION
versionCode ANDROID_BUILD_VERSION_CODE
versionName ANDROID_BUILD_APP_VERSION_NAME
// Enabling multidex support.
multiDexEnabled false
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
debuggable false
ext.enableCrashlytics = true
renderscriptOptimLevel 3
signingConfig android.signingConfigs.release
zipAlignEnabled true
minifyEnabled true
// shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', 'proguard-rules-new.pro', 'proguard-rules-eventbus.pro', 'proguard-rules-firebase.pro', 'proguard-rules-fabric.pro', 'proguard-rules-leakcanary.pro'
}
debug {
debuggable true
renderscriptOptimLevel 3
applicationIdSuffix ".debug"
versionNameSuffix "debug"
}
}
- I often read that multidex app may crash time to time
来自 android 开发人员文档页面 (http://developer.android.com/tools/building/multidex.html#limitations):
Applications using a multidex configuration that make very large
memory allocation requests may crash during run time due to a Dalvik
linearAlloc limit (Issue 78035). The allocation limit was increased in
Android 4.0 (API level 14), but apps may still run into this limit on
Android versions prior to Android 5.0 (API level 21)
ART 内置了对 multi-dex apks 的支持,因此 multi-dexing 不会在 lollipop 及更高版本中造成任何问题。您可能会在某些设备 运行ning kitkat 及以下设备上遇到问题,尽管这种情况应该很少见,除非您有非常高的方法数或内存要求。
- And that because of second-dex runtime loading, this take time.
是的,multidex 确实会显着降低应用程序的首次启动时间。 (在 yelp 的情况下高达 200%,当他们超过限制的 20k 方法时)甚至冷启动时间也会增加。
因此,如果可以避免多重索引,强烈建议您这样做。
即使您超出限制,您仍应尽量减少方法计数,因为越来越多的方法会减慢棒棒糖之前设备上的应用程序启动时间。
在你的情况下,如果你的构建成功,但如果你看到 运行 次崩溃(尤其是 "No Class def. found"),那么可能是你没有正确配置 proguard,它可能会剥离一些必需的组件。
来自 yelp 的 Timothy Meller 对此问题进行了详细的讨论,其中他还分享了一些 multi-dex 优化和 proguard 配置的重要性:
https://www.youtube.com/watch?v=skmOBriQ28E
如果您想更好地了解 android
上的多重索引,我建议您观看此视频
我有一个带有几个库的应用程序,达到了 65536 方法计数的红线。
- 我成功地将应用设置为
multidex
APK。 - 为了优化大小,我决定使用 Proguard,因为我只使用了
Guava
和common.java.lang
的一些功能,而这些库带来了他们的整个家庭。 - Proguard 作业完成后,我的应用程序引用了 ~ 45 Kmethods
- 我经常看到 multidex 应用程序有时会崩溃
- 而且由于 second-dex 运行时加载,这需要时间。
4和5是真的吗?
然后我只是尝试不使用 mutidex
,因为我的最终方法计数是 < 56Kmethods with prodGuard,但它失败了,好像它有更多!
为此,我只是将gradle参数multiDexEnabled
设置为false
还有什么要check/do的吗?
这是我的一部分 Gradle :
android {
compileSdkVersion ANDROID_BUILD_SDK_VERSION
buildToolsVersion ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
applicationId "XXXX"
targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION
minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION
versionCode ANDROID_BUILD_VERSION_CODE
versionName ANDROID_BUILD_APP_VERSION_NAME
// Enabling multidex support.
multiDexEnabled false
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
debuggable false
ext.enableCrashlytics = true
renderscriptOptimLevel 3
signingConfig android.signingConfigs.release
zipAlignEnabled true
minifyEnabled true
// shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', 'proguard-rules-new.pro', 'proguard-rules-eventbus.pro', 'proguard-rules-firebase.pro', 'proguard-rules-fabric.pro', 'proguard-rules-leakcanary.pro'
}
debug {
debuggable true
renderscriptOptimLevel 3
applicationIdSuffix ".debug"
versionNameSuffix "debug"
}
}
- I often read that multidex app may crash time to time
来自 android 开发人员文档页面 (http://developer.android.com/tools/building/multidex.html#limitations):
Applications using a multidex configuration that make very large memory allocation requests may crash during run time due to a Dalvik linearAlloc limit (Issue 78035). The allocation limit was increased in Android 4.0 (API level 14), but apps may still run into this limit on Android versions prior to Android 5.0 (API level 21)
ART 内置了对 multi-dex apks 的支持,因此 multi-dexing 不会在 lollipop 及更高版本中造成任何问题。您可能会在某些设备 运行ning kitkat 及以下设备上遇到问题,尽管这种情况应该很少见,除非您有非常高的方法数或内存要求。
- And that because of second-dex runtime loading, this take time.
是的,multidex 确实会显着降低应用程序的首次启动时间。 (在 yelp 的情况下高达 200%,当他们超过限制的 20k 方法时)甚至冷启动时间也会增加。
因此,如果可以避免多重索引,强烈建议您这样做。
即使您超出限制,您仍应尽量减少方法计数,因为越来越多的方法会减慢棒棒糖之前设备上的应用程序启动时间。
在你的情况下,如果你的构建成功,但如果你看到 运行 次崩溃(尤其是 "No Class def. found"),那么可能是你没有正确配置 proguard,它可能会剥离一些必需的组件。
来自 yelp 的 Timothy Meller 对此问题进行了详细的讨论,其中他还分享了一些 multi-dex 优化和 proguard 配置的重要性:
https://www.youtube.com/watch?v=skmOBriQ28E
如果您想更好地了解 android
上的多重索引,我建议您观看此视频