2016-08-01 5 views
10

내 앱의 메소드 수가 64k 제한보다 높으므로 Proguard를 사용하여이를 줄입니다.Proguard minifyEnabled 디버그 빌드에서 true이고, Lollipop 이전 버전에서는 작동하지 않습니다.

모든 것이 릴리스 빌드에 잘 작동합니다.
디버그 빌드는 Lollipop + 기기에서만 성공합니다.

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을 제거 시도했다 :

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

이 내가 응용 프로그램 수준 Gradle을 파일에있는 것입니다 : 사전 롤리팝 장치에 시작할 때 나는 항상 악명 높은 오류가 빌드를 디버그 한 다음 Lollipop +에서도 빌드가 실패합니다. 따라서 proguard가 작동합니다! Lollipop 사전에는 없습니다.

minifyEnabled은 플랫폼에 종속적이어서는 안되며, 빌드 프로세스는 사전 Lollipop 장치에서 (내가 어떤 이유인지 알지 못해) 건너 뜁니다.

누구든지이 문제에 대한 해결책을 알고 있습니까?

ps. 나는 multidex 가능성을 알고 있지만, 나는 그것을 최후의 수단으로 남겨두고있다.

편집 :

이 응용 프로그램 수준 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' 

프로젝트 수준 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 
} 

난독 규칙 :

# 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 { *; } 
+0

를 구축 변형 버전을 선택 디버그에 포함됩니까? LeakCanary처럼? – EpicPandaForce

+0

아니요, 또한 https://github.com/KeepSafe/dexcount-gradle-plugin을 사용하여 디버그 빌드의 메소드 개수를 확인하고 있습니다. 약 30k입니다. (프로 가드로 미니 피팅) –

+0

gradle.build 파일의 전체 코드를 보여주십시오. – Divers

답변

1

당신이 Nt는 메소드 수를 줄이거 나 적어도 릴리스의 차이점을 디버그로 이해하고 싶습니다. 2.2 미리보기 5에서 사용할 수있는 덱스 트 수를 살펴 보시길 권합니다. YouTube 비디오에서 (어쩌면 Google IO에서) 그것은 당신의 방법을 세는 것을 아주 쉽게 만들었습니다.

buildToolsVersion "23.0.3"을 여전히 사용하는 경우 이것은 두 가지 버전의 AS에서 정확히 동일한 apk 파일을 가져야합니다. AS 2.2는 자체 버전의 JDK와 함께 제공됩니다. 당신의 길을 가야한다).

면책 조항 : 나는 그 도구를 가지고 노는 것과 별개로 도구를 사용한 적이 없으므로 실제로 범인을 찾은 후에 추천 할 항목을 모르겠다.

편집 : 여기에 "빌드"메뉴 내에있는 "Apk Analyzer"에 대한 비디오 https://youtu.be/csaXml4xtN8?t=331이 있습니다. 2.2 미리보기 3 이상이 아닌 리뷰를 시도하지 마십시오. 나중에 미리 릴리스되지 않은 내용을 미리 봅니다.

EDIT 2 : 또한 출시시에만 shrinkResources만을 사용하고 계십니까? 이는 부적절한 메소드를 제거하기 위해 제안 된 라인입니다. "minifyEnabled" vs "shrinkResources" - what's the difference? and how to get the saved space?

+0

이미 https://github.com/KeepSafe/dexcount-gradle-plugin을 사용하여 메소드를 계산하고 있습니다. 방법 수는 프로 가드에 의해 축소 된 후 30k에 있습니다. 그럼 괜찮아. –

+0

흠, 그런데 예술에 대해 뭔가 읽으려고했는데, 키트 캣에서 옵션으로 사용하거나 롤리팝을 안정적으로 도입하지 않았습니까? 하지만 여전히 릴리스와 동일한 정보를 사용하면 디버그에서 동일한 오류가 발생합니까? 이것들은 디폴트 변형이므로 'debuggable true'와 다른 숨겨진 구성을 가질 수 있습니다. – Fabio

+0

그래, 이상합니다. 나는 AS를 사용하지 않고 apk를 빌드하고 설치하여이 문제를 재현하고 재현해야합니다. 적어도 실행중인 경우 즉시 실행을 중지해야합니다. 또한 두 번째 스크립트/gradle 플러그인을 사용하여 디버그 빌드의 메소드 수를 두 번 확인합니다. 오류 메시지는 65k 메소드 수를 지정하는 것과 매우 비슷하기 때문에 확실합니다. – Fabio

-1

multidex가 true로 설정되어 있고 응용 프로그램을 multidex 어플리케이션으로 지원할 수 있습니다.따라야 할 몇 가지 단계는 다음과 같습니다

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

종속성 목록에이 종속성을 추가

컴파일 'com.android.support:multidex:1.0.0'

MultiDexApplication

와 응용 프로그램 수준 클래스를 확장

응용 프로그램 클래스에이 방법을 쓰기

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

킵 거짓없이 디버그를 minifyEnabled하거나 응용 프로그램 수준 Gradle을 파일에이 코드를 사용하여 빌드 유형 코드를 바꿉니다 업데이 트를

dexOptions { 
     jumboMode = true 
     javaMaxHeapSize "4g" //specify the heap size for the dex process 
     preDexLibraries = false 
    } 
+1

내가 말했듯이 : "ps. 나는 멀티 덱스 가능성을 알고 있지만, 나는 그것을 최후의 수단으로 남겨두고있다." –

0

를 구축 놓습니다. 디버깅 또는 최종 릴리스하기 전에 장치에서 코드를 실행하는 경우 다음 내장 변형 디버그를 선택하고 릴리스 구축 서명 APK에 갈 때 당신은 전용 의존성이없는

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