Executar código DEX incorporado diretamente no APK
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Em dispositivos com o Android 10 (nível 29 da API) e mais recentes, você pode instruir a plataforma a executar
o código DEX incorporado diretamente no arquivo APK do app. Essa opção
evita ataques caso um invasor consiga adulterar o código compilado
localmente no dispositivo.
Se você estiver usando o sistema de build do Gradle,
faça o seguinte para ativar esse recurso:
Defina o atributo android::useEmbeddedDex como
true no
elemento
<application> do arquivo de manifesto do app.
Defina useLegacyPackaging como false no
arquivo build.gradle.kts do módulo ou no arquivo
build.gradle se você estiver usando o Groovy.
Kotlin
packagingOptions{dex{useLegacyPackaging=false}}
Groovy
packagingOptions{dex{useLegacyPackagingfalse}}
No sistema de build do Bazel, defina o
atributo android:useEmbeddedDex como true no
elemento <application> do
arquivo de manifesto do app e deixe os arquivos DEX descompactados:
O conteúdo e os exemplos de código nesta página estão sujeitos às licenças descritas na Licença de conteúdo. Java e OpenJDK são marcas registradas da Oracle e/ou suas afiliadas.
Última atualização 2025-08-21 UTC.
[null,null,["Última atualização 2025-08-21 UTC."],[],[],null,["# Run embedded DEX code directly from APK\n\nOn devices running Android 10 (API level 29) and higher you can tell the platform to run\nembedded DEX code directly from your app's APK file. This option can help\nprevent an attack if an attacker ever managed to tamper with the locally\ncompiled code on the device.\n| **Note:** Enabling this feature could possibly affect your app's performance because ART must use the [JIT compiler](https://source.android.com/devices/tech/dalvik/jit-compiler) when the app is started (instead of reading native code that was compiled ahead of time). We recommend testing your app's performance before you decide whether or not to enable this feature in your published apps.\n\nIf you're using the Gradle build system, to enable this feature do the\nfollowing:\n\n- Set the `android::useEmbeddedDex` attribute to\n `true` in the\n [\u003capplication\u003e](/guide/topics/manifest/application-element)\n element of your app's manifest file.\n\n- Set `useLegacyPackaging` to `false` in the\n module-level `build.gradle.kts` file (`build.gradle`\n file if you're using Groovy).\n\n **Note:** Don't set the `useLegacyPackaging` option if you're using a version of AGP lower than 4.2. \n\n ### Kotlin\n\n ```kotlin\n packagingOptions {\n dex {\n useLegacyPackaging = false\n }\n }\n \n ```\n\n ### Groovy\n\n ```groovy\n packagingOptions {\n dex {\n useLegacyPackaging false\n }\n }\n \n ```\n\nIf you're using the Bazel build system, to enable this feature set the\n`android:useEmbeddedDex` attribute to `true` in the `\u003capplication\u003e` element of\nyour app's manifest file and leave DEX files uncompressed: \n\n```\nandroid_binary(\n ...\n nocompress_extensions = [\".dex\"],\n)\n```\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Tapjacking](/topic/security/risks/tapjacking)\n- [android:exported](/topic/security/risks/android-exported)\n- [# Key management {:#key-management}](/topic/security/data)"]]