تصحيح أخطاء مشروعك
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تصحيح أخطاء أعطال الإعلانات المدمجة مع المحتوى
إذا كنت تواجه صعوبة في فهم مخلفة حادث أو شاهد قبر حادث أصلي،
تصحيح أخطاء رمز نظام Android الأساسي الأصلي
مقدمة جيدة.
للحصول على كتالوج كامل بأنواع الأعطال الشائعة وكيفية التحقيق فيها، يُرجى الاطّلاع على
تشخيص الأعطال الأصلية:
يمكن أن تساعد أداة ndk-stack في ترميز الأعطال التي تواجهها.
يمكنك تصحيح الأعطال في "استوديو Android" كما هو موضّح بشكل عام.
مستندات تصحيح أخطاء التطبيق إذا كنت تفضل استخدام
سطر الأوامر، فإن ndk-gdb تتيح لك إرفاق gdb
أو
lldb
من الصدفة.
منح التطبيقات إمكانية الوصول المباشر إلى سجلّ آثار القبور
بدءًا من الإصدار Android 12 (المستوى 31 لواجهة برمجة التطبيقات)، يمكنك الوصول إلى الأعطال الأصلية في تطبيقك.
Tombstone في صورة
المخزن المؤقت للبروتوكول من خلال
ApplicationExitInfo.getTraceInputStream()
. يكون المخزن المؤقت للبروتوكول تسلسليًا باستخدام هذا المخطط.
في السابق، كانت الطريقة الوحيدة للوصول إلى هذه المعلومات هي عبر
Android Debug Bridge (adb).
إليك مثال على كيفية تنفيذ ذلك في تطبيقك:
ActivityManager activityManager: ActivityManager = getSystemService(Context.ACTIVITY_SERVICE);
MutableList<ApplicationExitInfo> exitReasons = activityManager.getHistoricalProcessExitReasons(/* packageName = */ null, /* pid = */ 0, /* maxNum = */ 5);
for (ApplicationExitInfo aei: exitReasons) {
if (aei.getReason() == REASON_CRASH_NATIVE) {
// Get the tombstone input stream.
InputStream trace = aei.getTraceInputStream();
// The tombstone parser built with protoc uses the tombstone schema, then parses the trace.
Tombstone tombstone = Tombstone.parseFrom(trace);
}
}
تصحيح أخطاء الذاكرة الأصلية
مطهّر العنوان (HWASan/ASan)
HWAddress Sanitizer (HWASan) و
يُعد Address Sanitizer (ASan) مشابهًا لـ Valgrind، لكن
بشكل أسرع بكثير وأفضل بكثير المتوافق مع Android.
هذه هي الخيار الأفضل لتصحيح أخطاء الذاكرة على Android.
تصحيح أخطاء مالوك
عرض
تصحيح أخطاء Maloc
أو
تتبُّع الذاكرة الأصلية باستخدام استدعاءات libc
للحصول على وصف شامل للخيارات المضمنة في مكتبة C لتصحيح الأخطاء
مشكلات الذاكرة الأصلية.
خُطافات مالوك
إذا أردت إنشاء أدواتك الخاصة، تتيح libc في Android أيضًا اعتراض
جميع عمليات التخصيص/المكالمات المجانية التي تحدث أثناء تنفيذ البرنامج. يمكنك الاطّلاع على
مستندات malloc_hooks
للحصول على تعليمات الاستخدام.
إحصاءات مالوك
يتيح Android
mallinfo(3)
أو
malloc_info(3)
الإضافات إلى <malloc.h>
.
تتوفر وظيفة malloc_info
في نظام التشغيل Android 6.0 (Marshmallow)
وتم توثيق مخطط XML الخاص به في هيكل
malloc.h
.
إنشاء الملفات التعريفية
لتحليل وحدة المعالجة المركزية (CPU) للرموز البرمجية الأصلية، يمكنك استخدام Simpleperf.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Debug your project\n\nDebug native crashes\n--------------------\n\nIf you're struggling to understand a native crash dump or tombstone,\n[Debugging Native Android Platform Code](https://source.android.com/devices/tech/debug/index.html)\nis a good introduction.\n\nFor a fuller catalog of common types of crash and how to investigate them, see\n[Diagnosing Native Crashes](https://source.android.com/devices/tech/debug/native-crash).\n\nThe [ndk-stack](/ndk/guides/ndk-stack) tool can help symbolize your crashes.\nYou can debug crashes in Android Studio as described in the general\n[Debug your app](/studio/debug) documentation. If you prefer to use the\ncommand-line, [ndk-gdb](/ndk/guides/ndk-gdb) lets you attach either `gdb` or\n`lldb` from your shell.\n\n### Provide apps direct access to tombstone traces\n\nStarting in Android 12 (API level 31), you can access your app's native crash\ntombstone as a\n[protocol buffer](https://developers.google.com/protocol-buffers/) through the\n[`ApplicationExitInfo.getTraceInputStream()`](/reference/android/app/ApplicationExitInfo#getTraceInputStream())\nmethod. The protocol buffer is serialized using [this schema](https://android.googlesource.com/platform/system/core/+/refs/heads/main/debuggerd/proto/tombstone.proto).\nPreviously, the only way to get access to this information was through the\n[Android Debug Bridge](/studio/command-line/adb) (adb).\n\nHere's an example of how to implement this in your app: \n\n ActivityManager activityManager: ActivityManager = getSystemService(Context.ACTIVITY_SERVICE);\n MutableList\u003cApplicationExitInfo\u003e exitReasons = activityManager.getHistoricalProcessExitReasons(/* packageName = */ null, /* pid = */ 0, /* maxNum = */ 5);\n for (ApplicationExitInfo aei: exitReasons) {\n if (aei.getReason() == REASON_CRASH_NATIVE) {\n // Get the tombstone input stream.\n InputStream trace = aei.getTraceInputStream();\n // The tombstone parser built with protoc uses the tombstone schema, then parses the trace.\n Tombstone tombstone = Tombstone.parseFrom(trace);\n }\n }\n\nDebug native memory issues\n--------------------------\n\n### Address Sanitizer (HWASan/ASan)\n\n[HWAddress Sanitizer](/ndk/guides/hwasan) (HWASan) and\n[Address Sanitizer](/ndk/guides/asan) (ASan) are similar to Valgrind, but\nsignificantly faster and much better supported on Android.\n\nThese are your best option for debugging memory errors on Android.\n\n### Malloc debug\n\nSee\n[Malloc Debug](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_debug/README.md)\nand\n[Native Memory Tracking using libc Callbacks](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_debug/README_api.md)\nfor a thorough description of the C library's built-in options for debugging\nnative memory issues.\n\n### Malloc hooks\n\nIf you want to build your own tools, Android's libc also supports intercepting\nall allocation/free calls that happen during program execution. See the\n[malloc_hooks documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)\nfor usage instructions.\n\n### Malloc statistics\n\nAndroid supports the\n[mallinfo(3)](http://man7.org/linux/man-pages/man3/mallinfo.3.html)\nand\n[malloc_info(3)](http://man7.org/linux/man-pages/man3/malloc_info.3.html)\nextensions to `\u003cmalloc.h\u003e`.\n\nThe `malloc_info` functionality is available in Android 6.0 (Marshmallow) and\nhigher and its XML schema is documented in Bionic's\n[malloc.h](https://android.googlesource.com/platform/bionic/+/main/libc/include/malloc.h)\nheader.\n\nProfiling\n---------\n\nFor CPU profiling of native code, you can use [Simpleperf](/ndk/guides/simpleperf)."]]