xCrash
🔥 xCrash provides the Android app with the ability to capture java crash, native crash and ANR. No root permission or any system permissions are required.
Top Related Projects
Quick Overview
xCrash is an open-source crash reporting and analysis tool developed by iQIYI, a leading online video platform in China. It provides a comprehensive solution for capturing, analyzing, and managing application crashes on Android devices.
Pros
- Comprehensive Crash Reporting: xCrash captures detailed information about crashes, including stack traces, system logs, and device information, enabling thorough analysis and debugging.
- Customizable Crash Handling: Developers can customize the crash handling behavior, such as uploading crash reports to a remote server or displaying a user-friendly crash dialog.
- Minimal Performance Impact: xCrash is designed to have a minimal impact on the application's performance, ensuring a smooth user experience.
- Cross-Platform Support: While primarily focused on Android, xCrash also provides support for iOS and other platforms, making it a versatile solution.
Cons
- Limited Documentation: The project's documentation, while available, could be more comprehensive and user-friendly, especially for developers new to the tool.
- Dependency on External Libraries: xCrash relies on several external libraries, which may introduce additional complexity and potential compatibility issues.
- Specific to iQIYI's Needs: As an internal tool developed by iQIYI, xCrash may not fully address the needs of all developers outside the company.
- Lack of Active Maintenance: The project's GitHub repository shows limited recent activity, which could raise concerns about ongoing support and updates.
Code Examples
Here are a few code examples demonstrating the usage of xCrash:
- Initializing xCrash:
XCrash.init(this);
This code initializes the xCrash library within the application's context.
- Customizing Crash Handling:
XCrash.setCustomCrashHandler(new XCrashCustomCrashHandler() {
@Override
public void onCrash(Thread thread, Throwable throwable, String errorMessage, String stackTrace, String logcatMsg) {
// Implement custom crash handling logic here
// e.g., upload crash report to a remote server
}
});
This code sets a custom crash handler, allowing developers to define their own logic for handling crashes.
- Capturing Native Crashes:
XCrash.setNativeCallback(new XCrashNativeCallback() {
@Override
public void onCrash(String errorMessage, String stackTrace, String logcatMsg) {
// Implement logic for handling native crashes
}
});
This code sets a callback for capturing and handling native (C/C++) crashes within the application.
- Capturing Java Crashes:
XCrash.setJavaCallback(new XCrashJavaCallback() {
@Override
public void onCrash(Thread thread, Throwable throwable, String errorMessage, String stackTrace, String logcatMsg) {
// Implement logic for handling Java crashes
}
});
This code sets a callback for capturing and handling Java crashes within the application.
Getting Started
To get started with xCrash, follow these steps:
- Add the xCrash dependency to your project's
build.gradle
file:
dependencies {
implementation 'com.iqiyi.xcrash:xcrash-android-lib:3.0.0'
}
- Initialize xCrash in your application's
onCreate()
method:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
XCrash.init(this);
}
}
- (Optional) Customize the crash handling behavior by setting a custom crash handler:
XCrash.setCustomCrashHandler(new XCrashCustomCrashHandler() {
@Override
public void onCrash(Thread thread, Throwable throwable, String errorMessage, String stackTrace, String logcatMsg) {
// Implement custom crash handling logic here
}
});
- (Optional) Capture native crashes by setting a native callback:
Competitor Comparisons
Mirror of Google Breakpad project
Pros of Breakpad
- Breakpad is a mature and widely-used open-source project, with a large community and extensive documentation.
- It supports a wide range of platforms, including Windows, macOS, Linux, and Android.
- Breakpad provides a robust and reliable crash reporting system, with advanced features like symbol file management and minidump analysis.
Cons of Breakpad
- Breakpad can be complex to set up and integrate into a project, especially for smaller or less experienced teams.
- The project's focus on low-level system integration may make it less suitable for some modern application architectures, such as those using containerization or microservices.
- Breakpad's reliance on platform-specific system libraries can make it more difficult to maintain and update across different environments.
Code Comparison
Here's a brief comparison of the code structure between Breakpad and xCrash:
Breakpad (C++):
class ExceptionHandler {
public:
ExceptionHandler(const std::wstring& dump_path,
FilterCallback filter,
MinidumpCallback callback,
void* callback_context,
int handler_types);
// ...
};
xCrash (C++):
class XCrash {
public:
static void Initialize(const XCrashConfig& config);
static void Uninitialize();
static void SetUserInfo(const XCrashUserInfo& user_info);
// ...
};
Both projects provide a high-level API for integrating crash reporting functionality into an application, but the specific approaches and features differ. Breakpad focuses on low-level system integration, while xCrash aims for a more modern, platform-agnostic design.
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.
Pros of Tinker
- Tinker provides a comprehensive solution for hot-fixing Android applications, allowing developers to quickly patch and deploy updates without the need for a full app release.
- The project has a large and active community, with extensive documentation and a wide range of resources available for developers.
- Tinker is highly customizable, allowing developers to tailor the solution to their specific needs and requirements.
Cons of Tinker
- Tinker's complexity may be a barrier for some developers, as it requires a deeper understanding of the Android platform and build process.
- The project's focus on hot-fixing may not be suitable for all use cases, as it may not address more fundamental issues within the application.
Code Comparison
Tinker:
public class SampleApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Beta.installTinker(this);
}
}
xCrash:
public class XCrashApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
XCrash.init(this);
}
}
Both code snippets demonstrate the initialization of the respective crash handling libraries, Tinker and xCrash, within an Android application's Application
class.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
xCrash
xCrash provides the Android app with the ability to capture java crash, native crash and ANR. No root permission or any system permissions are required.
xCrash can generate a tombstone file (similar format as Android system's tombstone file) in the directory you specified when the app process crashes or ANRs.
xCrash has been used in many Android apps (including iQIYI video) on different platforms (mobile, tablet, TV) of iQIYI for many years.
Features
- Support Android 4.1 - 11 (API level 16 - 30).
- Support armeabi-v7a, arm64-v8a, x86 and x86_64.
- Capturing java crash, native crash and ANR.
- Dumping detailed statistics about process, threads, memory, FD and network.
- Setting which thread's info should be dumped via regular expressions.
- Do not require root permission or any system permissions.
Tombstone File Previews
- java crash
- native crash (armeabi-v7a)
- native crash (arm64-v8a)
- native crash (x86)
- native crash (x86_64)
- ANR (armeabi-v7a)
- ANR (arm64-v8a)
- ANR (x86)
- ANR (x86_64)
Overview Maps
Architecture
Capture Native Crash
Capture ANR
Usage
1. Add dependency.
dependencies {
implementation 'com.iqiyi.xcrash:xcrash-android-lib:3.0.0'
}
2. Specify one or more ABI(s) you need.
android {
defaultConfig {
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
}
3. Initialize xCrash.
Java
public class MyCustomApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
xcrash.XCrash.init(this);
}
}
Kotlin
class MyCustomApplication : Application() {
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
xcrash.XCrash.init(this)
}
}
Tombstone files will be written to Context#getFilesDir() + "/tombstones"
directory by default. (usually in: /data/data/PACKAGE_NAME/files/tombstones
)
There is a more practical and complex sample app in the xcrash_sample folder.
Build
If you want to build xCrash from source code. Follow this guide:
Build AAR library.
./gradlew :xcrash_lib:build
Support
Contributing
See xCrash Contributing Guide.
License
xCrash is MIT licensed, as found in the LICENSE file.
xCrash documentation is Creative Commons licensed, as found in the LICENSE-docs file.
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot