Proguard minifyEnabled true for debug build, not working on pre-Lollipop

﹥>﹥吖頭↗ 提交于 2019-12-01 16:30:39
Fabio

If you want to try to reduce the method count, or at least you want to understand the difference from release to debug, I suggest you try looking at the dex count available in AS 2.2 preview 5, they had a youtube video (maybe from google IO) that made it pretty easy to count your methods.

This is only for counting methods, if you still use the same buildToolsVersion "23.0.3" you should get the exact same apk file in both versions of AS (apart from the fact that AS 2.2 ships with its own version of JDK, which is not supposed to get in your way).

Disclaimer: I have never used that tool apart from playing with it, so I wouldn't know what to recommend after you actually find a culprit there.

EDIT: here's the video https://youtu.be/csaXml4xtN8?t=331 for the "Apk Analyzer", that lives inside the "Build" menu. Don't try reviews earlier than 2.2 preview 3 or later, they previewd some things that were not released until later.

EDIT 2: also why are you only using shrinkResources on release? That's the line that is suppposed to eliminate unneded methods: "minifyEnabled" vs "shrinkResources" - what's the difference? and how to get the saved space?

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'
                }
}

Enable multidex enabled true and allow support to your application as a multidex application.Few steps to be followed are:

 defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 3
        versionName "1.0.1"
        **multiDexEnabled true**
    }

add this dependency to dependency list

compile 'com.android.support:multidex:1.0.0'

extend your application level class with MultiDexApplication

write this method in your application class

protected void attachBaseContext(Context base)
    {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

keep minifyEnabled false no matter debug or release build

update

dexOptions {
        jumboMode = true
        javaMaxHeapSize "4g" //specify the heap size for the dex process
        preDexLibraries = false
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!