2017-12-14 10 views
1

저는 multidex에서 이상한 문제에 직면하고 있습니다. 나는 여러 해 동안 내 응용 프로그램을 여러 번 사용했지만 최근에는 더 이상 만들 수 없습니다. 그것은 프로젝트에서 Kotlin을 구성한 후에 시작되었습니다.Multidex 앱이 여전히 64K의 메소드 한도를 초과합니다

Android Studio의 '실행'옵션이 작동합니다. : 내 기기에서 앱이 성공적으로 실행됩니다. 나는 "APK 빌드"옵션을 시도하거나 gradlew assembleDebug를 실행하는 경우, 빌드는 보통의 예외와 함께 실패

Error:The number of method references in a .dex file cannot exceed 64K. 
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html 
Error:com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 

그러나 multidex가 코 틀린를 추가하기 전에 제대로했다. 나는 Kotlin을 추가하기 직전에 커밋을 체크 아웃 할 수 있으며 apk를 빌드하고 3 개의 .dex 파일이 있는지 확인합니다. 메소드 수는 총 100,000 개 이상입니다.

몇 가지 주요 사항 :

  • Gradle을 플러그인을 Gradle을 4.1, 3.0.1
  • 빌드 - 도구 버전 26.0.2
  • 코 틀린 버전 proguarding 후 1.2.0

, 응용 프로그램 multidex 필요하지 않지만 정말 디버그 컴파일 proguard 싶지 않아 게다가,이 해야합니다.

buildscript { 
    repositories { 
     mavenCentral() 
    } 
} 
apply plugin: 'com.android.application' 
apply plugin: 'kotlin-android' 
apply plugin: 'idea' 



repositories { 
    mavenCentral() 
    jcenter() 
    maven { url "https://maven.google.com" } 
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } 
    maven { url 'https://jitpack.io' } 
} 

idea { 
    module { 
     downloadJavadoc = true 
     downloadSources = true 
    } 
} 

// read keystore for app signing 
def keystorePropertiesFile = rootProject.file("keystore.properties") 
def keystoreProperties = null 
if (keystorePropertiesFile.exists()) { 
    keystoreProperties = new Properties() 
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) 
} 


def getDate() { 
    def date = new Date() 
    def formattedDate = date.format('yyyy.MM.dd') 
    return formattedDate 
} 

def getCustomProguardFiles() { 
    return fileTree(dir: "proguard", include: ["*.pro"]).asList().toArray() 
} 

android { 
    compileSdkVersion 25 
    buildToolsVersion '26.0.2' 
    defaultConfig { 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     applicationId "my.app.id" 
     multiDexEnabled true 

     manifestPlaceholders = [ 
       'appAuthRedirectScheme': 'my.app.id' 
     ] 

     //TODO do not put this into release 
     resValue "string", "google_client_id", google_appId + ".apps.googleusercontent.com" 
     resValue "string", "google_auth_redirect_uri", "com.googleusercontent.apps." + google_appId + ":/oauth2redirect" 
    } 

    dexOptions { 

    } 

    dexOptions { 
     javaMaxHeapSize "2g" 
    } 

    packagingOptions { 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
    } 

    signingConfigs { 
     release { 
      keyAlias keystoreProperties != null ? keystoreProperties['keyAlias'] : null 
      keyPassword keystoreProperties != null ? keystoreProperties['keyPassword'] : null 
      storeFile keystoreProperties != null ? file(keystoreProperties['storeFile']) : null 
      storePassword keystoreProperties != null ? keystoreProperties['storePassword'] : null 
     } 
    } 


    lintOptions { 
     abortOnError false 
     checkReleaseBuilds false 
    } 
    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt') 
      proguardFiles getCustomProguardFiles() 
      testProguardFiles getDefaultProguardFile('proguard-android.txt') 
      testProguardFiles getCustomProguardFiles() 
      signingConfig signingConfigs.release 
     } 
     debug { 
      debuggable true 
      minifyEnabled false 
     } 
    } 

    flavorDimensions "buildType" 

    productFlavors { 
     develop { 
      applicationIdSuffix "" 
      dimension "buildType" 
     } 
     product { 
      dimension "buildType" 
     } 
     ci { 
      dimension "buildType" 
     } 
    } 

    applicationVariants.all { variant -> 
     variant.outputs.all { 
      outputFileName = "${variant.name}-${variant.versionName}.apk" 
     } 
    } 
    compileOptions.incremental = false 
} 

dependencies { 

    /********** DEBUGGING **********/ 
    // Chrome debug bridge 
    compile 'com.facebook.stetho:stetho:1.5.0' 
    compile 'com.facebook.stetho:stetho-okhttp3:1.5.0' 

    // Memory leak debugging 
    // 1.5.2 held back because of a bug with gradle 3.0 
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1' 
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1' 
    testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1' 
    androidTestCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1' 


    /********** SUPPORT **********/ 
    // Multidex support 
    compile 'com.android.support:multidex:1.0.2' 

    // Support libs 
    compile "com.android.support:appcompat-v7:$libVersions.android.support" 
    compile "com.android.support:cardview-v7:$libVersions.android.support" 
    compile "com.android.support:customtabs:$libVersions.android.support" 
    compile "com.android.support:design:$libVersions.android.support" 
    compile "com.android.support:gridlayout-v7:$libVersions.android.support" 
    compile "com.android.support:palette-v7:$libVersions.android.support" 
    compile "com.android.support:preference-v7:$libVersions.android.support" 
    compile "com.android.support:recyclerview-v7:$libVersions.android.support" 
    compile "com.android.support:support-annotations:$libVersions.android.support" 
    compile "com.android.support:support-v4:$libVersions.android.support" 
    compile "com.android.support:support-v13:$libVersions.android.support" 

    // Testing dependencies 
    // Made explicit to avoid conflicts with other testing libs 
    androidTestCompile "com.android.support:appcompat-v7:$libVersions.android.support" 
    androidTestCompile "com.android.support:design:$libVersions.android.support" 
    androidTestCompile "com.android.support:recyclerview-v7:$libVersions.android.support" 
    androidTestCompile "com.android.support:support-annotations:$libVersions.android.support" 
    androidTestCompile "com.android.support:support-v4:$libVersions.android.support" 


    /********** TESTING **********/ 
    // JUnit 
    testCompile 'junit:junit:4.12' 

    // Mockito 
    testCompile "org.mockito:mockito-core:2.8.47" 

    // Support testing 
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:3.0.0' 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0' 
    androidTestCompile 'com.android.support.test:rules:1.0.0' 
    androidTestCompile 'com.android.support.test:runner:1.0.0' 


    /********** UTILITIES **********/ 
    // HTML parsing 
    compile 'org.jsoup:jsoup:1.10.2' 

    // Event bus 
    compile 'org.greenrobot:eventbus:3.0.0' 

    // FHIR 
    compile 'ca.uhn.hapi.fhir:hapi-fhir-android:3.1.0' 
    compile 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu3:3.1.0' 

    // Jobs 
    compile 'com.evernote:android-job:1.1.11' 

    // JSON serializing-deserializing 
    compile 'com.google.code.gson:gson:2.8.1' 

    // JWT validation 
    compile 'com.nimbusds:nimbus-jose-jwt:4.41.1' 

    // Lang utilities 
    // Used for Levenshtein distance, etc 
    compile 'org.apache.commons:commons-lang3:3.6' 
    compile 'org.apache.commons:commons-text:1.1' 

    // OpenID authentication 
    compile 'net.openid:appauth:0.7.0' 

    // QR code scanning 
    compile 'com.google.zxing:core:3.3.0' 
    compile 'com.journeyapps:zxing-android-embedded:[email protected]' 

    // Play Services (for Firebase InstanceID) 
    compile 'com.google.android.gms:play-services-auth:11.6.0' 

    // Recurrence processing 
    compile 'org.dmfs:lib-recur:0.10' 

    // REST services 
    compile 'com.squareup.retrofit2:retrofit:2.3.0' 
    compile 'com.squareup.retrofit2:converter-scalars:2.1.0' 

    // SQLite ORM 
    compile 'com.j256.ormlite:ormlite-android:5.0' 

    // Time and date handling 
    compile 'com.fatboyindustrial.gson-jodatime-serialisers:gson-jodatime-serialisers:1.6.0' 
    compile 'joda-time:joda-time:2.9.7' 

    // View/resource binding 
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 
    compile 'com.jakewharton:butterknife:8.8.1' 


    /********** VIEWS AND VIEW UTILITIES **********/ 
    // About page with libraries 
    compile('com.mikepenz:aboutlibraries:[email protected]') { 
     transitive = true 
    } 

    // Calendar views 
    compile 'com.roomorama:caldroid:3.0.1' 
    compile 'com.squareup:android-times-square:[email protected]' 

    // Circular progress "pie" view 
    // Used for pill picker 
    compile 'com.github.filippudak.progresspieview:library:1.0.4' 

    // Dialogs with material style 
    compile 'com.github.javiersantos:MaterialStyledDialogs:2.0' 

    // Floating Action Button 
    compile 'com.getbase:floatingactionbutton:1.9.0' 

    // GIF ImageView 
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.3' 

    // Icons 
    compile 'com.mikepenz:community-material-typeface:[email protected]' 
    compile 'com.mikepenz:google-material-typeface:[email protected]' 
    compile 'com.mikepenz:iconics-core:[email protected]' 

    // Image loading 
    compile 'com.squareup.picasso:picasso:2.5.2' 

    // Intro slides 
    compile 'com.heinrichreimersoftware:material-intro:1.5.8' 

    // Material style utilities 
    compile('com.mikepenz:materialize:[email protected]') { 
     transitive = true 
    } 

    // Picker DialogFragments 
    compile 'com.code-troopers.betterpickers:library:3.1.0' 

    // Round image view 
    compile 'com.makeramen:roundedimageview:1.5.0' 

    // Tab strip 
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1' 

    // Sliding left drawer 
    compile('com.mikepenz:materialdrawer:[email protected]') { 
     transitive = true 
    } 

    // Recyclerview adapters 
    compile('com.mikepenz:fastadapter:[email protected]') { 
     transitive = true 
    } 
    compile 'com.mikepenz:fastadapter-commons:[email protected]' 
    compile 'com.mikepenz:fastadapter-extensions:[email protected]' 
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 

    // Schedule step-by-step building 
    compile 'com.stepstone.stepper:material-stepper:3.3.0' 
    compile 'com.wdullaer:materialdatetimepicker:3.2.2' 
    compile 'com.shawnlin:number-picker:2.4.4' 
} 

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

그리고 프로젝트의 build.gradle :

// Top-level build file where you can add configuration options common to all sub-projects/modules. 
buildscript { 
    ext.kotlin_version = '1.2.0' 
    repositories { 
     jcenter() 
     maven { url "https://maven.google.com" } 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:3.0.1' 
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 
     classpath 'com.google.gms:google-services:3.0.0' 
    } 
    ext { 
     libVersions = [ 
       android: [ 
         support: '25.4.0' 
       ] 
     ] 
    } 
} 
+0

매니페스트에 응용 프로그램 클래스 이름이 있습니까? –

+0

@ NongthonbamTonthoi 예, 있습니다. 내 응용 프로그램 클래스도 MultidexApplication을 확장합니다. Kotlin을 추가하기 전에 Multidex가 올바르게 구성되었습니다. – Alvaro

답변

2

그것은 내가 HAPI-FHIR 포함 된 방법에 문제가 밝혀졌다

여기에 전체 build.gradle 스크립트입니다. 수 많은 의존성을 가진 정말 큰 라이브러리이고, 아마도 주된 dexfile을 무너 뜨릴 것입니다. 결국

는 I를 교체하여 해결할 :

// FHIR 
compile 'ca.uhn.hapi.fhir:hapi-fhir-android:3.1.0' 
compile 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu3:3.1.0' 

으로 : 이러한 종속성이 다운로드되지 @jar 사용시

// FHIR 
compile 'ca.uhn.hapi.fhir:hapi-fhir-base:[email protected]' 
compile 'ca.uhn.hapi.fhir:hapi-fhir-utilities:[email protected]' 
compile 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu3:[email protected]' 
compile 'commons-io:commons-io:2.5' 
compile 'org.slf4j:slf4j-api:[email protected]' 

commons-ioslf4j가 HAPI의 런타임 의존성이며, 따라서 명시 적으로 선언해야합니다.

참고 :이 특별한 구성은 HAPI에 더 많은 런타임 종속성이 있으므로 사용 사례에만 유효합니다. 필요할 경우를 대비하여 수동으로 추가해야합니다.