2017-12-14 9 views
1

私はmultidexで奇妙な問題に直面しています。私は長い間、アプリケーションを多変量化していましたが、最近はもう構築できません。それはプロジェクトでKotlinを設定した後に始まりました。64Kメソッド制限を超えているMultidexアプリ

Androidスタジオの[実行]オプションは、で動作します。アプリがデバイスで正常に動作します。しかし、私はオプション「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を追加する前に、正常に働いていました。私はKotlinを追加する直前にコミットをチェックアウトし、apkをビルドし、3つの.dexファイルがあることを確認します。

いくつかの重要な詳細:

  • のGradleプラグインとのGradle 4.1、3.0.1
  • ビルド・ツールのバージョン26.0.2
  • Kotlinバージョン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を継承しています。 Multidexは、Kotlinを追加する前に動作していたので、正しく構成されています。 – Alvaro

答えて

2

それは私がHAPI-FHIRを含めた方法に問題であることが判明

はここで完全build.gradleスクリプトです。これは、数多くの依存関係を持つ本当に大きなライブラリです。おそらく、主なdexfileを崩壊させていたでしょう。最後に

は、私は交換することによってそれを解決:と

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

// 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の実行時の依存関係であり、@jarを使用している場合、それらの依存関係がダウンロードされません、彼らは明示的に宣言する必要があります。

注:この特定の構成は、HAPIに必要なランタイム依存性があり、必要に応じて手動で追加する必要があるため、私の使用例でのみ有効です。

関連する問題