Skip to content

Instantly share code, notes, and snippets.

@kaedea
Created July 1, 2020 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaedea/2f9184168c9e720228e5435baee81e33 to your computer and use it in GitHub Desktop.
Save kaedea/2f9184168c9e720228e5435baee81e33 to your computer and use it in GitHub Desktop.
Utility to trigger native crash in Android
public class NativeCrashUtils {
public static void crashNatively() {
try {
Class<?> clazz = Class.forName("dalvik.system.VMDebug");
Method method = reflectMethod(clazz, "crash");
method.setAccessible(true);
method.invoke(null);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Method reflectMethod(Class<?> clazz, String methodName, Class... args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
Method getDeclaredMethod = Class.class.getDeclaredMethod("getDeclaredMethod", String.class, Class[].class);
getDeclaredMethod.setAccessible(true);
return (Method) getDeclaredMethod.invoke(clazz, methodName, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment