Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The number of method references in a .dex file cannot exceed 64K. with versions > 8 #325

Closed
almothafar opened this issue Mar 3, 2020 · 5 comments

Comments

@almothafar
Copy link

Bug report

Current behavior:

When I upgraded to 8.1.0 from 7.0.2, building a bundle for android is failing with error about" The number of method references in a .dex file cannot exceed 64K.", I tried 8.1.1, 8.0.0 and 8.0.1 and the issue is the same, for 7.0.2 there are no issues, so I'm not sure what changed, and why I'm facing this.

Expected behavior:

Steps to reproduce:
Having an ionic project with the following packages (in package.json):

{
  "name": "com.example",
  "version": "0.0.0",
  "description": "Some description",
  "scripts": {
    "ng": "ng",
    "start": "ionic serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~9.0.4",
    "@angular/common": "~9.0.4",
    "@angular/core": "~9.0.4",
    "@angular/fire": "^5.4.2",
    "@angular/forms": "~9.0.4",
    "@angular/platform-browser": "~9.0.4",
    "@angular/platform-browser-dynamic": "~9.0.4",
    "@angular/router": "~9.0.4",
    "@ionic-native/app-version": "^5.22.0",
    "@ionic-native/barcode-scanner": "^5.22.0",
    "@ionic-native/core": "^5.22.0",
    "@ionic-native/device": "^5.22.0",
    "@ionic-native/file": "^5.22.0",
    "@ionic-native/file-opener": "^5.22.0",
    "@ionic-native/firebase-x": "^5.22.0",
    "@ionic-native/geolocation": "^5.22.0",
    "@ionic-native/in-app-browser": "^5.22.0",
    "@ionic-native/ionic-webview": "^5.22.0",
    "@ionic-native/keyboard": "^5.22.0",
    "@ionic-native/local-notifications": "^5.22.0",
    "@ionic-native/network": "^5.22.0",
    "@ionic-native/social-sharing": "^5.22.0",
    "@ionic-native/splash-screen": "^5.22.0",
    "@ionic-native/status-bar": "^5.22.0",
    "@ionic-native/toast": "^5.22.0",
    "@ionic/angular": "^5.0.4",
    "@ionic/storage": "^2.2.0",
    "@progress/kendo-angular-charts": "^4.1.3",
    "@progress/kendo-angular-common": "^1.2.2",
    "@progress/kendo-angular-intl": "^2.0.1",
    "@progress/kendo-angular-l10n": "^2.0.1",
    "@progress/kendo-angular-popup": "^3.0.5",
    "@progress/kendo-drawing": "^1.13.7",
    "@progress/kendo-theme-material": "latest",
    "cordova-android": "8.1.0",
    "cordova-ios": "5.1.1",
    "cordova-plugin-app-version": "0.1.9",
    "cordova-plugin-badge": "0.8.8",
    "cordova-plugin-device": "2.0.3",
    "cordova-plugin-file": "6.0.2",
    "cordova-plugin-file-opener2": "3.0.0",
    "cordova-plugin-firebasex": "^8.1.1",
    "cordova-plugin-geolocation": "4.0.2",
    "cordova-plugin-inappbrowser": "3.2.0",
    "cordova-plugin-ionic-keyboard": "2.2.0",
    "cordova-plugin-ionic-webview": "4.1.3",
    "cordova-plugin-local-notification": "0.9.0-beta.2",
    "cordova-plugin-network-information": "2.0.2",
    "cordova-plugin-splashscreen": "5.0.3",
    "cordova-plugin-statusbar": "2.4.3",
    "cordova-plugin-whitelist": "1.3.4",
    "cordova-plugin-x-toast": "2.7.2",
    "cordova-sqlite-storage": "4.0.0",
    "firebase": "^7.9.3",
    "hammerjs": "^2.0.8",
    "mapbox-gl": "^1.8.1",
    "ng2-pdf-viewer": "~6.1.1",
    "ngx-mapbox-gl": "^4.4.2",
    "phonegap-plugin-barcodescanner": "8.1.0",
    "rxjs": "~6.5.4",
    "tslib": "^1.11.1",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.4",
    "@angular-devkit/core": "^9.0.4",
    "@angular-devkit/schematics": "^9.0.4",
    "@angular/cli": "~9.0.4",
    "@angular/compiler": "~9.0.4",
    "@angular/compiler-cli": "~9.0.4",
    "@angular/language-service": "~9.0.4",
    "@angular/platform-server": "~9.0.4",
    "@ionic/angular-toolkit": "^2.2.0",
    "@ionic/lab": "^3.1.0",
    "@types/google.analytics": "0.0.40",
    "@types/jasmine": "~3.5.7",
    "@types/mapbox-gl": "^1.8.0",
    "@types/uuid": "^3.4.7",
    "codelyzer": "^5.2.1",
    "husky": "^4.2.3",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.1",
    "karma-jasmine": "~3.1.1",
    "karma-jasmine-html-reporter": "^1.5.2",
    "tslint": "^6.0.0",
    "typescript": "~3.7.5"
  },
  "husky": {
    "hooks": {
      "pre-push": "ng lint"
    }
  },
  "cordova": {
    "platforms": [
      "android",
      "ios"
    ],
    "plugins": {
      "cordova-plugin-app-version": {},
      "cordova-plugin-badge": {},
      "cordova-plugin-device": {},
      "cordova-plugin-file": {},
      "cordova-plugin-file-opener2": {
        "ANDROID_SUPPORT_V4_VERSION": "28.+"
      },
      "cordova-plugin-geolocation": {},
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "28.+"
      },
      "cordova-plugin-local-notification": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-x-toast": {},
      "cordova-sqlite-storage": {},
      "phonegap-plugin-barcodescanner": {
        "ANDROID_SUPPORT_V4_VERSION": "28.+"
      },
      "cordova-plugin-x-socialsharing": {},
      "cordova-plugin-firebasex": {}
    }
  }
}

And config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example" version="1.11.1" xmlns="http://www.w3.org/ns/widgets">
    <name>Example</name>
    <description>Description   </description>
    <author email="info@capella.io" href="https://capella.io/">Capella Solutions</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <preference name="ScrollEnabled" value="false" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="10000" />
    <preference name="KeyboardResize" value="true" />
    <preference name="KeyboardResizeMode" value="native" />
    <preference name="WKSuspendInBackground" value="false" />
    <platform name="android">
        <preference name="android-minSdkVersion" value="19" />
        <preference name="android-targetSdkVersion" value="29" />
        <config-file parent="/manifest/application/" target="app/src/main/AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
            <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_notification" />
        </config-file>
        <allow-intent href="market:*" />
        <resource-file src="resources/android/icon/drawable-mdpi-icon.png" target="app/src/main/res/drawable-mdpi/ic_launcher.png" />
        <resource-file src="resources/android/icon/drawable-hdpi-icon.png" target="app/src/main/res/drawable-hdpi/ic_launcher.png" />
        <resource-file src="resources/android/icon/drawable-xhdpi-icon.png" target="app/src/main/res/drawable-xhdpi/ic_launcher.png" />
        <resource-file src="resources/android/icon/drawable-xxhdpi-icon.png" target="app/src/main/res/drawable-xxhdpi/ic_launcher.png" />
        <resource-file src="resources/android/icon/drawable-xxxhdpi-icon.png" target="app/src/main/res/drawable-xxxhdpi/ic_launcher.png" />
        <resource-file src="resources/android/ic_notification/drawable-mdpi/ic_notification.png" target="app/src/main/res/drawable-mdpi/ic_notification.png" />
        <resource-file src="resources/android/ic_notification/drawable-hdpi/ic_notification.png" target="app/src/main/res/drawable-hdpi/ic_notification.png" />
        <resource-file src="resources/android/ic_notification/drawable-xhdpi/ic_notification.png" target="app/src/main/res/drawable-xhdpi/ic_notification.png" />
        <resource-file src="resources/android/ic_notification/drawable-xxhdpi/ic_notification.png" target="app/src/main/res/drawable-xxhdpi/ic_notification.png" />
        <resource-file src="resources/android/ic_notification/drawable-xxxhdpi/ic_notification.png" target="app/src/main/res/drawable-xxxhdpi/ic_notification.png" />
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
        <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />
        <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <icon height="57" src="resources/ios/icon/icon.png" width="57" />
        <icon height="114" src="resources/ios/icon/icon@2x.png" width="114" />
        <icon height="40" src="resources/ios/icon/icon-40.png" width="40" />
        <icon height="80" src="resources/ios/icon/icon-40@2x.png" width="80" />
        <icon height="120" src="resources/ios/icon/icon-40@3x.png" width="120" />
        <icon height="50" src="resources/ios/icon/icon-50.png" width="50" />
        <icon height="100" src="resources/ios/icon/icon-50@2x.png" width="100" />
        <icon height="60" src="resources/ios/icon/icon-60.png" width="60" />
        <icon height="120" src="resources/ios/icon/icon-60@2x.png" width="120" />
        <icon height="180" src="resources/ios/icon/icon-60@3x.png" width="180" />
        <icon height="72" src="resources/ios/icon/icon-72.png" width="72" />
        <icon height="144" src="resources/ios/icon/icon-72@2x.png" width="144" />
        <icon height="76" src="resources/ios/icon/icon-76.png" width="76" />
        <icon height="152" src="resources/ios/icon/icon-76@2x.png" width="152" />
        <icon height="167" src="resources/ios/icon/icon-83.5@2x.png" width="167" />
        <icon height="29" src="resources/ios/icon/icon-small.png" width="29" />
        <icon height="58" src="resources/ios/icon/icon-small@2x.png" width="58" />
        <icon height="87" src="resources/ios/icon/icon-small@3x.png" width="87" />
        <icon height="1024" src="resources/ios/icon/icon-1024.png" width="1024" />
        <splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
        <splash height="1334" src="resources/ios/splash/Default-667h.png" width="750" />
        <splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242" />
        <splash height="1242" src="resources/ios/splash/Default-Landscape-736h.png" width="2208" />
        <splash height="1536" src="resources/ios/splash/Default-Landscape@2x~ipad.png" width="2048" />
        <splash height="2048" src="resources/ios/splash/Default-Landscape@~ipadpro.png" width="2732" />
        <splash height="768" src="resources/ios/splash/Default-Landscape~ipad.png" width="1024" />
        <splash height="2048" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" />
        <splash height="2732" src="resources/ios/splash/Default-Portrait@~ipadpro.png" width="2048" />
        <splash height="1024" src="resources/ios/splash/Default-Portrait~ipad.png" width="768" />
        <splash height="960" src="resources/ios/splash/Default@2x~iphone.png" width="640" />
        <splash height="480" src="resources/ios/splash/Default~iphone.png" width="320" />
        <splash height="2732" src="resources/ios/splash/Default@2x~universal~anyany.png" width="2732" />
        <edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
            <string>To scan barcodes</string>
        </edit-config>
        <edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
            <string>We use your location to get the nearest well for you</string>
        </edit-config>
        <edit-config file="*-Info.plist" mode="merge" target="NSLocationAlwaysUsageDescription">
            <string>We use your location to get the nearest well for you</string>
        </edit-config>
    </platform>
    <engine name="android" spec="8.1.0" />
    <engine name="ios" spec="5.1.1" />
</widget>

And finally tried to build bundle using the following command:

ionic cordova build android --no-interactive --confirm --prod --aot --minifyjs --minifycss --optimizejs --release --buildConfig=build.json -- -d

Environment information

  • Cordova CLI version
    • 9.0.0 (cordova-lib@9.0.1)
  • Cordova platform version
> cordova platform ls
Installed platforms:
  android 8.0.0
Available platforms:
  browser ^6.0.0
  electron ^1.0.0
  ios ^5.0.0
  osx ^5.0.0
  windows ^7.0.0
  • Plugins & versions installed in project (including this plugin)
> cordova plugin ls
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-badge 0.8.8 "Badge"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-file-opener2 2.2.1 "File Opener2"
cordova-plugin-geolocation 4.0.2 "Geolocation"
cordova-plugin-inappbrowser 3.1.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 4.1.1 "cordova-plugin-ionic-webview"
cordova-plugin-local-notification 0.9.0-beta.2 "LocalNotification"
cordova-plugin-network-information 2.0.2 "Network Information"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-plugin-whitelist 1.3.4 "Whitelist"
cordova-plugin-x-toast 2.7.2 "Toast"
cordova-sqlite-storage 3.2.1 "Cordova sqlite storage plugin - cordova-sqlite-storage plugin version"
phonegap-plugin-barcodescanner 8.1.0 "BarcodeScanner"
  • Dev machine OS and version, e.g.
    • Windows 10
      image

Android build issue:

  • Node JS version
    • v12.16.0
  • Gradle version
    • 5.6.4 buildOutputCleanup vcs-1
  • Target Android SDK version
    • android-28
  • Android SDK details
Warning: File /home/ionic/.android/repositories.cfg could not be loaded.
Installed packages:=====================] 100% Computing updates...             
  Path                 | Version | Description                    | Location
  -------              | ------- | -------                        | -------
  build-tools;29.0.2   | 29.0.2  | Android SDK Build-Tools 29.0.2 | build-tools/29.0.2/
  platform-tools       | 29.0.6  | Android SDK Platform-Tools     | platform-tools/
  platforms;android-28 | 6       | Android SDK Platform 28        | platforms/android-28/
  tools                | 26.1.1  | Android SDK Tools 26.1.1       | tools/

Console output

> Task :app:transformDexArchiveWithExternalLibsDexMergerForRelease FAILED
D8: Cannot fit requested classes in a single dex file (# methods: 122286 > 65536)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForRelease'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
  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

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Other Information
After I tried to search in issues, I found nothing, but when I did write this one, I found a similar one:
#277

But my consideration is about, why this issue is happening with the new version, why methods went to 122286 and it is less that than 65536 in the older version? It does not make sense that the new version of this plugin doubled the methods number, so I feel it is something else.

@kelpie278
Copy link

Hi @almothafar,

You can enable multidex, or just change the minSDK

@dpa99c
Copy link
Owner

dpa99c commented Mar 3, 2020

@almothafar v8 of this plugin adds support for various Firebase authentication methods, Firestore and Inapp Messaging.
These and their associated dependencies, in combination with other plugins in your Cordova project, are enough to push the number of methods over the 64k limit.

The solution is to enable multidex or increase the min SDK as suggested by @kelpie278.

Closing as this is not a specific issue that requires fixing within the plugin code.

@dpa99c dpa99c closed this as completed Mar 3, 2020
@almothafar
Copy link
Author

almothafar commented Mar 3, 2020

@kelpie278 thanks, what the minSdkVersion value should be? currently is 19 as you see.

Edit: I went to 22 and it seems to solve the issue.

@joel-caton
Copy link

I had the same issue last night with Android... Changed the min version, reinstalled plugin and then platform and it worked. I'm using v24 right now.. Got some other changes to make so will be using min v26 going forward.

@NicolaasZA
Copy link

NicolaasZA commented Mar 19, 2020

I pushed my minSdk to 21, worked for me.

Edit: For the folks not yet comfortably acquainted with where to change this, head over to config.xml in the root of your project. You will probably need to recreate (remove, add) your relevant platforms.
Screenshot 2020-03-19 at 09 54 21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants