【问题标题】:android proguard in debug builds?调试版本中的android proguard?
【发布时间】:2016-03-17 13:49:08
【问题描述】:

我有一个 android 应用,它支持 android >= 4。 在调试编译中,它有 > 65k 的方法,因此它是 multidex。 在发布时,我使用 proguard,它有 38k 方法,而不是 multidex。 我将如何开发一个应用程序,它在调试模式下可能会崩溃,只是因为它超过 65k 方法?

我觉得我也可以在调试版本中使用 proguard,但没有看到有人这样做 + 使用 proguard 编译会花费更多时间 您将如何处理这种情况?

PS 我的 app.gradle 看起来像这样(依赖部分):

        compile project(':signalr-client-sdk-android')
        compile fileTree(include: ['*.jar'], dir: 'libs')

        compile 'com.android.support:recyclerview-v7:+'
        compile "com.nostra13.universalimageloader:universal-image-loader:${UNIVERSAL_IMAGE_LOADER}"
        compile "de.hdodenhof:circleimageview:${CIRCLE_IMAGE_VER}"
        compile "com.pixplicity.multiviewpager:library:${MULTIVIEW_PAGER_VER}"
        compile "com.michaelpardo:activeandroid:${ACTIVE_ANDROID_VER}"
        compile "com.squareup.okhttp:okhttp:${OKHTTP_VER}"
        compile "com.rockerhieu.emojicon:library:${EMOJI_VERSION}"
        compile "com.facebook.android:facebook-android-sdk:${FACEBOOK_SDK_VER}"
        compile "com.makeramen:roundedimageview:${ROUNDED_IMAGEVIEW_VER}"
        compile 'com.github.orangegangsters:swipy:1.2.0@aar'

        compile "com.google.android.gms:play-services-gcm:${GSM_VER}"
        compile "com.google.android.gms:play-services-analytics:${ANALITICS_VER}"

        compile "com.flurry.android:analytics:${FLURRY_VER}"

        compile 'com.supersonic.sdk:mediationsdk:6.3.6@jar'

        //effects apng tool
        compile project(':android_api')
        compile project(':flingCards')

        compile files('libs/protobuf-java-2.6.1.jar')

我使用所有这些库

【问题讨论】:

  • 发布你的multidex代码,我认为你只在gradle中设置了multidex。
  • 我不想做app multidex!它会表现得不稳定,我的应用程序肯定不应该是 multidex
  • 如果您不想将应用程序设为multidex,请删除一些对应用程序无用的jar文件并使用它。如果您使用的是播放服务,则在 gradle 中使用特定的播放服务依赖项。
  • @SilvansSolanki ,我无法删除任何罐子或库,我都使用它们。关于我知道的游戏服务。请告诉我其他选项,如果有的话
  • 您仅将播放服务用于单个功能,从您的代码中我只能说没有其他方法可以减少项目中的方法 no。您必须为调试创建 multidex 文件,否则您需要使用 proguard 进行所有调试,这不是推荐的解决方案。最好创建 multidex 文件,它不会给您带来任何性能问题。

标签: android android-proguard android-debug


【解决方案1】:

我在调试版本中使用 proguard。通常我的 build.gradle 看起来像这样:

    buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-debug.pro'
    }
}

注意不同的 proguard 文件 (proguard-rules-debug.pro) 用于调试,其中添加了 -dontobfuscate 选项。

用 proguard 编译它所花费的时间大约长 5-10%,这对我来说是可以接受的。我没有使用即时运行,所以我不知道它是如何受此影响的。

【讨论】:

  • 很好的解决方案。谢谢。
【解决方案2】:

您也可以在调试中使用 ProGuard。将此添加到您的buildTypes

    debug {
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        minifyEnabled true
        debuggable true
        zipAlignEnabled true
        jniDebuggable true
    }

在您的应用内build.gradle

【讨论】:

  • 我现在就是这样做的。但是编译需要更多的时间,这是一个问题
  • 所以,我认为你只有几个选择,用 Proguard 减慢编译速度,而不是编译或尝试使用 multidex 不需要这么长时间。没有更多选择。
  • 或者您可以尝试通过更改库来减少库。我看到您有一个“通用图像加载器”和一个“圆形图像视图”库,如果我没记错的话,您可以使用 Glide 更改它们。
  • 我非常喜欢 UIL,无法拒绝它。 Ant 它需要的方法并不多,少于 2k。圆形图像视图只需要 200 个方法
  • @IgorGanapolsky 如果我没记错的话,这个标志在调试版本中默认设置为 true,所以不需要它。但我通常还是添加它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-22
  • 2011-09-29
  • 2011-12-30
  • 2015-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多