如何减小 apk 大小(应用程序大小太大)

Sp4*_*4Rx 2 android proguard apk

检查下面我的gradle配置。

    android {
    signingConfigs {
        config {
            keyAlias 'xxx'
            keyPassword 'xxx'
            storeFile file('/home/xxx/AndroidStudioProjects/key/key.jks')
            storePassword 'xxx'
        }
    }
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "app.examinations.com"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner     "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            debuggable false
            signingConfig signingConfigs.config
        }
        debug {
            signingConfig signingConfigs.config
        }
    }
}
repositories {

    maven { url "https://jitpack.io" }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    //Gson Dependency
    compile 'com.google.code.gson:gson:2.8.0'
    //Design Layout
    compile 'com.android.support:design:25.3.1'
    //chart
    compile 'com.diogobernardino:williamchart:2.5.0'
    //view
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    //fab
    compile 'com.github.clans:fab:1.6.4'
    //expandable view
    compile 'com.github.aakira:expandable-layout:1.6.0@aar'
    //tables
    compile 'de.codecrafters.tableview:tableview:2.6.0'
    //Circular ImageView
    compile 'com.mikhaellopez:circularimageview:3.0.2'
    //Download Images with Picasso
    compile 'com.squareup.picasso:picasso:2.5.2'
    //Google Services
    compile 'com.google.firebase:firebase-messaging:11.0.2'
    compile 'com.google.android.gms:play-services-auth:11.0.2'
    compile 'com.google.firebase:firebase-core:11.0.2'
    //Crop Image
    compile 'com.github.yalantis:ucrop:2.2.1'
    //Pdf Viewer
    compile 'com.github.barteksc:android-pdf-viewer:2.7.0-beta'
    //Fab reveal layout
    compile 'konifar:fab-transformation:1.0.0'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

我已经使用了 proguard 和资源收缩,它仍然是 25mb(大约)。

这是混淆器配置

-keepattributes SourceFile,LineNumberTable
-keep class com.parse.*{ *; }
-dontwarn com.parse.**
-dontwarn okio.**
-dontwarn com.squareup.picasso.**
-keepclasseswithmembernames class * {
    native <methods>;
}

-assumenosideeffects class android.util.Log { *; }
Run Code Online (Sandbox Code Playgroud)

检查此Apk 分析器图像

伊姆古尔

查询

1)这个lib文件夹包含我所有的库吗?以及为什么它太大了?

2)有没有办法只使用我使用proguard从库中使用的类?或者我应该通过使用更少的库来优化大小?

apm*_*991 5

您的问题是您正在使用许多库,其中最糟糕的是:

"com.github.barteksc:android-pdf-viewer:2.7.0-beta" 
Run Code Online (Sandbox Code Playgroud)

像这样的库将很难缩小,虽然其他答案中有很多关于如何减小 APK 大小的方法,但这个库是您正在寻找的主要方法。