Uruchamianie umieszczonego kodu DEX bezpośrednio z pliku APK
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Na urządzeniach z Androidem 10 (poziom interfejsu API 29) lub nowszym możesz nakazać platformie uruchamianie osadzonego kodu DEX bezpośrednio z pliku APK aplikacji. Ta opcja może pomóc zapobiec atakowi, jeśli atakującemu uda się zmodyfikować lokalnie skompilowany kod na urządzeniu.
Jeśli używasz systemu kompilacji Gradle, aby włączyć tę funkcję, wykonaj te czynności:
Ustaw atrybut android::useEmbeddedDex na wartość true w elemencie <application> w pliku manifestu aplikacji.
W pliku build.gradle.kts na poziomie modułu ustaw wartość useLegacyPackaging na false (jeśli używasz Groovy, w pliku build.gradle).
Kotlin
packagingOptions{dex{useLegacyPackaging=false}}
Groovy
packagingOptions{dex{useLegacyPackagingfalse}}
Jeśli używasz systemu kompilacji Bazel, aby włączyć tę funkcję, ustaw atrybut android:useEmbeddedDex na true w elemencie <application> pliku manifestu aplikacji i pozostaw pliki DEX nieskompresowane:
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-27 UTC.
[null,null,["Ostatnia aktualizacja: 2025-08-27 UTC."],[],[],null,["On 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- 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)"]]