Pie*_*tti 11 android android-studio android-proguard
我的应用程序的方法计数高于64k限制,所以我使用Proguard来减少它.
一切都适用于发布版本.
另一方面,调试版本仅适用于Lollipop +设备.在Lollipop之前的设备上启动时,我总是有臭名昭着的错误:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
这是我在app level gradle文件中的内容:
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'
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试minifyEnabled true在调试版本中删除,然后在Lollipop +上构建失败,因此proguard正在工作!但不是在棒棒糖前.
因为我知道minifyEnabled不应该依赖于平台,所以也许构建过程会在Lollipop之前的设备上跳过它(因为我不知道是什么原因).
有人知道这个问题的解决方案吗?
PS.我知道multidex的可能性,但我将它作为我的最后手段.
编辑:
这是app level gradle文件的完整代码:
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'
Run Code Online (Sandbox Code Playgroud)
项目级gradle文件:
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
}
Run Code Online (Sandbox Code Playgroud)
程序规则:
# 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 { *; }
Run Code Online (Sandbox Code Playgroud)
如果你想尝试减少方法计数,或者至少你想了解从发布到调试的区别,我建议你尝试查看 AS 2.2 预览版 5 中可用的 dex 计数,他们有一个 YouTube 视频(可能来自 google) IO),这使得计算方法变得非常容易。
这仅适用于计数方法,如果您仍然使用相同的方法,buildToolsVersion "23.0.3"您应该在两个版本的 AS 中获得完全相同的 apk 文件(除了 AS 2.2 附带其自己的 JDK 版本这一事实之外,该版本不应该进入您的方式)。
免责声明:除了玩玩之外,我从未使用过该工具,所以当你真正找到罪魁祸首后,我不知道该推荐什么。
编辑:这是“Apk 分析器”的视频https://youtu.be/csaXml4xtN8?t=331,位于“Build”菜单内。不要尝试早于 2.2 预览版 3 或更高版本的评论,他们预览了一些直到后来才发布的东西。
编辑2:另外为什么你只shrinkResources在发布时使用?这就是应该消除不需要的方法的行:“minifyEnabled”与“shrinkResources” - 有什么区别?以及如何获得节省的空间?
| 归档时间: |
|
| 查看次数: |
7669 次 |
| 最近记录: |