发送一个 Android Codename One Build with a native library 我收到 DexIndexOverflowException

Sending An Android Codename One Build with a native library I'm getting DexIndexOverflowException

我正在将本机第 3 方库集成到代号一中,但在构建日志底部的构建过程中出现以下错误:

       [dx] Merged dex A (1099 defs/2414.7KiB) with dex B (1 defs/0.4KiB). Result is 1100 defs/3068.7KiB. Took 0.9s
       [dx] Result compacted from 4131.2KiB to 2416.3KiB to save 1714.8KiB
       [dx] Merged dex A (1100 defs/3068.7KiB) with dex B (4 defs/3.5KiB). Result is 1104 defs/2416.3KiB. Took 0.8s
       [dx] Result compacted from 7298.5KiB to 5991.1KiB to save 1307.4KiB
       [dx] Merged dex A (1104 defs/2416.3KiB) with dex B (4118 defs/3577.8KiB). Result is 5222 defs/5991.1KiB. Took 0.9s
       [dx] 
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
       [dx]     at com.android.dx.merge.DexMerger.updateIndex(DexMerger.java:502)
       [dx]     at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:283)
       [dx]     at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
       [dx]     at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
       [dx]     at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
       [dx]     at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
       [dx]     at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
       [dx]     at com.android.dx.command.dexer.Main.run(Main.java:277)
       [dx]     at com.android.dx.command.dexer.Main.main(Main.java:245)
       [dx]     at com.android.dx.command.Main.main(Main.java:106)
       [dx] 

BUILD FAILED
/home/ec2-user/android-sdk/tools/ant/build.xml:888: The following error occurred while executing this line:
/home/ec2-user/android-sdk/tools/ant/build.xml:890: The following error occurred while executing this line:
/home/ec2-user/android-sdk/tools/ant/build.xml:902: The following error occurred while executing this line:
/home/ec2-user/android-sdk/tools/ant/build.xml:283: null returned: 2

A​​ndroid DEX APK 格式有一个 64k 的方法计数限制,一旦您开始使用多个大型库就很容易超过这个限制。不幸的是,使用 Ant 解决它是不可能的,因此您需要切换到新的 Gradle based build system(这将是 Codename One 3.3 的默认设置,目前定于 2016 年 1 月发布)。

在 3.3 之前,您可以只定义构建提示 android.gradle=true

然后您需要定义构建提示 android.multidex=true 来解决该特定错误。