Android dex da una excepción BufferOverflowException al construir


Al compilar un proyecto específico de Android, y solo en mi máquina Windows, obtengo un java.nio.BufferOverflowException durante desde dex. El problema ocurre tanto cuando se usa Eclipse como cuando se usa Ant.

La salida cuando se usa Ant es:

...
  [dex] Pre-Dexing C:\MyProject\libs\android-support-v4.jar -> android-support-v4-5f5341d3c1b10a79d7d93f9c1e64421e.jar
  [dex] Converting compiled files and external libraries into C:\MyProject\bin\classes.dex...
   [dx]
   [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
   [dx] java.nio.BufferOverflowException
   [dx]     at java.nio.Buffer.nextPutIndex(Buffer.java:499)
   [dx]     at java.nio.HeapByteBuffer.putShort(HeapByteBuffer.java:296)
   [dx]     at com.android.dex.Dex$Section.writeShort(Dex.java:818)
   [dx]     at com.android.dex.Dex$Section.writeTypeList(Dex.java:870)
   [dx]     at com.android.dx.merge.DexMerger$3.write(DexMerger.java:437)
   [dx]     at com.android.dx.merge.DexMerger$3.write(DexMerger.java:423)
   [dx]     at com.android.dx.merge.DexMerger$IdMerger.mergeUnsorted(DexMerger.java:317)
   [dx]     at com.android.dx.merge.DexMerger.mergeTypeLists(DexMerger.java:423)
   [dx]     at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:163)
   [dx]     at com.android.dx.merge.DexMerger.merge(DexMerger.java:187)
   [dx]     at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
   [dx]     at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
   [dx]     at com.android.dx.command.dexer.Main.run(Main.java:230)
   [dx]     at com.android.dx.command.dexer.Main.main(Main.java:199)
   [dx]     at com.android.dx.command.Main.main(Main.java:103)

BUILD FAILED
C:\Users\Jaap\android-sdks\tools\ant\build.xml:892: The following error occurred while executing this line:
C:\Users\Jaap\android-sdks\tools\ant\build.xml:894: The following error occurred while executing this line:
C:\Users\Jaap\android-sdks\tools\ant\build.xml:906: The following error occurred while executing this line:
C:\Users\Jaap\android-sdks\tools\ant\build.xml:284: null returned: 2

Cuando se usa Eclipse el mensaje es más corto pero similar:

[2013-11-01 14:29:44] APK file is not created for Project: 
[2013-11-01 14:29:46 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
[2013-11-01 14:29:46 - MyProject] Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.

Como dije, no tengo este problema en mi MacBook, a pesar de que ambos están actualizados a las últimas versiones de las herramientas de compilación de Android: 19.0.0.

 172
Author: Flow, 2013-11-01

19 answers

No es necesario volver a degradar las herramientas de compilación a 18.1.11, este problema se solucionó con build tools 19.0.1.

Si no puedes usar 19.0.1 por alguna razón:

Asegúrese de que el valor de android:targetSdkVersion en AndroidManifest.xml coincide con target=android-<value>en el proyecto .propiedades. Si estos dos valores no son los mismos, compilar con build tools versión 19.0.0 terminará en la excepción BufferOverflowException. Fuente

También Hay algunos indicación de los comentarios en este post que usted necesita para apuntar al menos 19 (android-19). Por favor, deje un comentario si esta solución también funciona si su objetivo es

Así es como se ve la solución para mi proyecto. El problema relacionado con el AOSP es #61710.

1 Si realmente necesita degradar, no necesita desinstalar build tools 19.0.0, simplemente instale 18.1.1 y agregue sdk.buildtools=18.1.1 al archivo local.properties.

 229
Author: Flow,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-23 08:55:38

Intenta lo que van dijo:

Haga clic derecho en su projectandroid toolsandroid support library.

Espero que esto ayude:)

 83
Author: Lolo Me,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:34:14

El mismo problema aquí. Revirtió a build tools 18.1.1, reinició Eclipse y eso lo arregló.

 57
Author: Stefano,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-22 10:28:56

Pude construir mi proyecto problemático agregando esta línea adicional:

sdk.build.tools=18.1.1

To a mi proyecto .properties , que está presente en la raíz de la carpeta del proyecto. Todos los demás enfoques parecían fallar para mí.

 50
Author: mrrrk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-18 14:01:25

Haga clic derecho en el proyecto > > Propiedades >> Android > > API Nivel 18 funcionó para mí. Pero antes de hacerlo, hice clic derecho en proyecto > > Herramientas de Android >> Agregue la biblioteca de soporte y reinicie Eclipse. Es posible que tenga que jugar con su nivel de API seleccionado.

 7
Author: learner,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-21 07:20:37

Después de la instalación del nuevo SDK, hay una nueva carpeta, "Dependencias de Android", debajo del archivo de proyecto. Si hace clic con el botón derecho y lo elimina de la ruta de compilación, nuevamente podrá crear su proyecto.

 7
Author: Mahendra Liya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-21 07:22:40

Update

right click your project > android tools > android support library

Limpia tu proyecto y tratar de construir.

 5
Author: Harshid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-03 07:15:48

Tuve el mismo problema después de actualizar a la Revisión 19. Simplemente no se olvide de actualizar ADT, https://dl-ssl.google.com/android/eclipse / . Después de esto, pude construir el proyecto con la última revisión.

 4
Author: van,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-21 07:21:54

Solucioné este problema sin descargar la biblioteca de soporte o revertir las herramientas de compilación a 18.1.1. Simplemente cambié el nivel de API a 16+ y el problema desapareció. Espero que ayude.

 3
Author: Zsolt Boldizsár,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-06 08:31:47

Ninguna de las otras soluciones aquí funcionó para mí después de actualizar a Android Studio 0.4.0 y Gradle 1.9.

Resolví el problema descargando Build Tools 19.0.1 y actualizando la siguiente línea en mi compilación.archivos de gradle:

buildToolsVersion '19.0.0'

A

buildToolsVersion '19.0.1'
 3
Author: Jacob Tabak,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-20 19:32:21

Para los que tienen problemas con IntelliJ IDEA 13, desinstale Build Tools 19.

 2
Author: Adí,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-10 20:23:47

Tuvo el mismo problema con la versión de destino 19 tanto en project.properties como en AndroidManifest.xml con Ant.

Arreglado por:

  • Desinstalado Android SDK Build-Tools 19.0.1
  • Instalado Android SDK Build-Tools 19.0.2

Creo que @Al-Kathiri-Khalid tiene razón. El problema solo se debe a la falta de soporte para el nivel de API en las herramientas de compilación.

 2
Author: kontinuity,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-02 17:10:19

Tuve el mismo problema, aunque mi proyecto no usó la biblioteca de soporte. Añadir libs / android-support-v4.jar to the project solucionó el problema sin necesidad de revertir las herramientas de compilación desde la versión 19.

 1
Author: Jim Vitek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-04 20:01:12

Resolví este problema. Simplemente haga este cambio en el archivo de propiedades del proyecto:

target=android-18
sdk.build.tools=18.1.1

Y en el archivo de manifiesto:

uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="18"
 1
Author: Ravi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-31 22:53:39

Agregue el archivo de biblioteca en el proyecto.. Proyecto - >clic derecho - > Propiedades - > android - > Biblioteca - > clic en Agregar y seleccione el Proyecto de biblioteca y dar aplicar y aceptar.. luego, limpia el proyecto y vuelve a ejecutarlo.. si desea reiniciar el eclipse..

Y también, a veces, necesita actualizar las herramientas de compilación del SDK de Android..

 0
Author: harikrishnan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-13 11:29:05

Lo que funcionó para mí fue esto: Abrí el proyecto.archivo de propiedades de la raíz de mi proyecto y cambiado target=android-8 a target=android-17

 0
Author: Chinciusan Marian,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-10 15:26:05

Java.nio.BufferOverflowException durante dex error Esto significa que no tiene la API de soporte para ese nivel por lo tanto, la compilación falla, hay varias formas de arreglar esto.

Compruebe su archivo de manifiesto utiliza-sdk android:minSdkVersion = "4"y android:targetSdkVersion=" 14 "

Cualquiera de los siguientes solucionará el problema: -

  • Descargue el nivel requerido de API (Esto puede llevar tiempo) y ejecute su aplicación de nuevo
  • Quick dirty fix cambia el objetivo de tu proyecto en project.propiedades para tu nuevo objetivo target=android-4
  • Quick clean fix, cambia la SdkVersion en tu manifiesto y Limpia tu proyecto para agregar los cambios a tu proyecto.propiedades (Mi favorito)
 0
Author: Al-Kathiri Khalid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-20 09:56:08

Eliminé el SDK de Android anterior y Eclipse. Instalé el paquete ADT y funciona...

Esto solucionó el problema de BufferOverflow en Dex que comenzó después de que obtuve API 19. Anteriormente estaba usando Eclipse con Android SDK instalado como un paquete adicional.

 0
Author: vpathak,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-21 07:19:29

Haga clic derecho en Proyecto> > Propiedades > > Android y seleccione Nivel de API mayor que 15

O

Agregue google-play-services_lib a su proyecto haciendo clic derecho en proyecto y seleccionando Proyecto > > Propiedades > > Android > > Agregar

 0
Author: Junaid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-21 19:30:47