Proguard minifyEnabled对调试版本为true,不适用于棒棒糖之前的版本 [英] Proguard minifyEnabled true for debug build, not working on pre-Lollipop

查看:107
本文介绍了Proguard minifyEnabled对调试版本为true,不适用于棒棒糖之前的版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的方法数量超过了64k的限制,因此我正在使用Proguard来减少它.

The methods count of my app is higher than the 64k limit, so I'm using Proguard to reduce it.

对于发行版本,一切都很好.
另一方面,调试构建仅对Lollipop +设备成功.在棒棒糖之前的设备上启动时,我总是会听到臭名昭著的错误:

Everything works fine for release builds.
Debug builds, on the other hand, are successful only for Lollipop+ devices. When launching on pre-Lollipop devices I always have the infamous error:

com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

这是我在应用程序级别gradle文件中所拥有的:

This is what I have in the app level gradle file:

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

我尝试在调试版本中删除minifyEnabled true,然后该版本在Lollipop +上也失败,因此proguard正常工作!但不在棒棒糖之前.

I've tried removing minifyEnabled true in the debug build, and then the build fails also on Lollipop+, therefore proguard is working! but not on pre-Lollipop.

据我所知,minifyEnabled不应依赖于平台,所以也许构建过程会在棒棒糖之前的设备上跳过它(因为我不知道是什么原因).

For what i know minifyEnabled should not be platform dependent, so maybe the build process skips it (for I don't know what reason) on pre-Lollipop devices.

有人知道该问题的解决方案吗?

Anyone knows a solution to this issue?

ps.我知道有可能使用multidex,但是我将其作为最后的选择.

ps. I'm aware of the multidex possibility, but I'm leaving it as my last resort.

这是应用程序级别gradle文件的完整代码:

This is the full code of the app level gradle file:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'me.tatarka.retrolambda'

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.2.5'
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.5.5'
    }
}

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "com.pierfrancescosoffritti.shuffly"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 30
        versionName "0.13"
    }
    buildTypes {
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

def dbflow_version = "3.1.1"

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    apt 'com.jakewharton:butterknife-compiler:8.2.1'
    apt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"

    compile 'com.android.support:support-v4:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:recyclerview-v7:24.1.1'
    compile 'com.android.support:cardview-v7:24.1.1'
    compile 'com.android.support:palette-v7:24.1.1'
    compile 'com.jakewharton:butterknife:8.2.1'
    compile 'com.github.PierfrancescoSoffritti:AndroidUtils:0.5'
    compile 'com.github.PierfrancescoSoffritti:SlidingDrawer:0.10'
    compile 'com.github.PierfrancescoSoffritti:WebBasedOAuth:0.7'
    compile 'com.github.PierfrancescoSoffritti:ShrinkingImageLayout:0.4'
    compile 'com.github.PierfrancescoSoffritti:ExpandableLayout:0.1'
    compile 'com.google.apis:google-api-services-youtube:v3-rev177-1.22.0'
    compile 'com.google.api-client:google-api-client-android:1.20.0'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.1.8'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.Commit451:ElasticDragDismissLayout:1.0.4'
    compile 'com.google.firebase:firebase-core:9.2.1'
    compile 'com.google.firebase:firebase-crash:9.2.1'
    compile 'com.google.firebase:firebase-ads:9.2.1'
    compile 'com.artemzin.rxjava:proguard-rules:1.1.8.0'
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.getkeepsafe.dexcount'

项目级gradle文件:

project level gradle file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.5.5'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

保护规则:

# retrolambda
-dontwarn java.lang.invoke.*

# picasso
-dontwarn com.squareup.okhttp.**

# adMob
-keep public class com.google.android.gms.ads.** {
   public *;
}
-keep public class com.google.ads.** {
   public *;
}

# GoogleApiClient
# Needed to keep generic types and @Key annotations accessed via reflection
-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault
-keepclassmembers class * {
  @com.google.api.client.util.Key <fields>;
}
# Needed by google-http-client-android when linking against an older platform version
-dontwarn com.google.api.client.extensions.android.**
# Needed by google-api-client-android when linking against an older platform version
-dontwarn com.google.api.client.googleapis.extensions.android.**
# Needed by google-play-services when linking against an older platform version
-dontwarn com.google.android.gms.**
# com.google.client.util.IOUtils references java.nio.file.Files when on Java 7+
-dontnote java.nio.file.Files, java.nio.file.Path
# Suppress notes on LicensingServices
-dontnote **.ILicensingService
# Suppress warnings on sun.misc.Unsafe
-dontnote sun.misc.Unsafe
-dontwarn sun.misc.Unsafe

# DBFlow
-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; }

推荐答案

在应用程序级别gradle文件中用此代码替换您的构建类型代码. 当您在最终发行版之前在设备上调试或运行代码时,请选择构建的变体调试;当要构建签名的apk进行发布时,请选择构建的变体发行版

Replace your build Types code with this code in app level gradle file. when you are debugging or running code on your device before final release then select built variant debug and when you are going to built signed apk for release then select built variant release

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

这篇关于Proguard minifyEnabled对调试版本为true,不适用于棒棒糖之前的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆