Skip to content

feat: add NDK crashes example #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

## [15.0.2](https://github.com/Instabug/Instabug-Flutter/compare/v14.3.0...15.0.2) (Jul 7, 2025)
## [Unreleased](https://github.com/Instabug/Instabug-Flutter/compare/v15.0.2...dev)

### Added

- Add new APIs to support NDK Crashes. ([#607](https://github.com/Instabug/Instabug-Flutter/pull/607))

## [15.0.2](https://github.com/Instabug/Instabug-Flutter/compare/v14.3.0...15.0.2) (Jul 7, 2025)

### Added

Expand All @@ -20,7 +26,6 @@

- Bump Instabug Android SDK to v14.3.1 ([#577](https://github.com/Instabug/Instabug-Flutter/pull/577)). [See release notes](https://github.com/Instabug/Instabug-Android/releases/tag/v14.3.1).


## [14.3.0](https://github.com/Instabug/Instabug-Flutter/compare/v14.1.0...14.3.0) (April 21, 2025)

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ public void sendNonFatalError(@NonNull String jsonCrash, @Nullable Map<String, S
}
}

@Override
public void setNDKEnabled(@NonNull Boolean isEnabled) {
if (isEnabled) {
CrashReporting.setNDKCrashesState(Feature.State.ENABLED);
} else {
CrashReporting.setNDKCrashesState(Feature.State.DISABLED);
}
}
}
5 changes: 4 additions & 1 deletion example/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
key.properties

# c++
/app/.cxx/
19 changes: 15 additions & 4 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ plugins {
id "dev.flutter.flutter-gradle-plugin"
}

def enableProguardInReleaseBuilds = false
def enableShrinkResources = false

android {
namespace = "com.instabug.flutter.example"
namespace = "com.example.InstabugSample"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

Expand All @@ -20,7 +23,7 @@ android {
}

defaultConfig {
applicationId "com.instabug.flutter.example"
applicationId "com.example.InstabugSample"
minSdkVersion 21
targetSdkVersion 34
versionCode flutter.versionCode
Expand All @@ -33,10 +36,18 @@ android {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.debug
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
shrinkResources enableShrinkResources
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
}
}
namespace 'com.instabug.flutter.example'

configurations.all {
resolutionStrategy.force 'org.hamcrest:hamcrest-core:1.3'
Expand Down
10 changes: 10 additions & 0 deletions example/android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:
52 changes: 52 additions & 0 deletions example/android/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html.
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.

# Sets the minimum CMake version required for this project.
cmake_minimum_required(VERSION 3.22.1)

# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
# Since this is the top level CMakeLists.txt, the project name is also accessible
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
# build script scope).
project("native-lib")

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
#
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
# is preferred for the same purpose.
#
# In order to load a library into your app from Java/Kotlin, you must call
# System.loadLibrary() and pass the name of the library defined here;
# for GameActivity/NativeActivity derived applications, the same library name must be
# used in the AndroidManifest.xml file.
add_library(${CMAKE_PROJECT_NAME} SHARED
# List C/C++ source files with relative paths to this CMakeLists.txt.
native-lib.cpp
crasher.c
crasher_2.c
crasher_3.c
crasher_4.cpp
)
find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log)


# Specifies libraries CMake should link to your target library. You
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
target_link_libraries(${CMAKE_PROJECT_NAME}
# List libraries link to the target library
android
log
${log-lib}
)
50 changes: 50 additions & 0 deletions example/android/app/src/main/cpp/crasher.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

#include <jni.h>
#include <sys/user.h>
#include <unistd.h>
#include <stdlib.h>
#include "crasher_2.h"

/************* SIGSEGV *******************************/
JNIEXPORT void JNICALL
Java_com_example_InstabugSample_ndk_CppNativeLib_causeSIGSEGVCrash(JNIEnv *env, jobject thiz) {
causeSIGSEGVCrashF1();
}

/*****************************************************/

/************* SIGABRT *******************************/
JNIEXPORT void JNICALL
Java_com_example_InstabugSample_ndk_CppNativeLib_causeSIGABRTCrash(JNIEnv *env, jobject thiz) {
causeSIGABRTCrashF1();
}
/****************************************************/

/************* SIGFPE *******************************/
JNIEXPORT void JNICALL
Java_com_example_InstabugSample_ndk_CppNativeLib_causeSIGFPECrash(JNIEnv *env, jobject thiz) {
causeSIGFPECrashF1();
}
/***************************************************/

/************* SIGILL *******************************/

JNIEXPORT void JNICALL
Java_com_example_InstabugSample_ndk_CppNativeLib_causeSIGILLCrash(JNIEnv *env, jobject thiz) {
causeSIGILLCrashF1();
}
/***************************************************/

/************* SIGBUS *******************************/
JNIEXPORT void JNICALL
Java_com_example_InstabugSample_ndk_CppNativeLib_causeSIGBUSCrash(JNIEnv *env, jobject thiz) {
causeSIGBUSCrashF1();
}
/***************************************************/

/************* SIGTRAP *******************************/
JNIEXPORT void JNICALL
Java_com_example_InstabugSample_ndk_CppNativeLib_causeSIGTRAPCrash(JNIEnv *env, jobject thiz) {
causeSIGTRAPCrashF1();
}
/***************************************************/
47 changes: 47 additions & 0 deletions example/android/app/src/main/cpp/crasher_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@


#include <jni.h>
#include <sys/user.h>
#include <unistd.h>
#include <stdlib.h>
#include "crasher_3.h"

/************* SIGSEGV *******************************/
void causeSIGSEGVCrashF1() {
causeSIGSEGVCrashF2();
}
/*****************************************************/

/************* SIGABRT *******************************/
void causeSIGABRTCrashF1() {
causeSIGABRTCrashF2();
}
/****************************************************/

/************* SIGFPE *******************************/


void causeSIGFPECrashF1() {
causeSIGFPECrashF2();
}
/***************************************************/

/************* SIGILL *******************************/

void causeSIGILLCrashF1() {
causeSIGILLCrashF2();
}
/***************************************************/

/************* SIGBUS *******************************/

void causeSIGBUSCrashF1() {
causeSIGBUSCrashF2();
}
/***************************************************/

/************* SIGTRAP *******************************/
void causeSIGTRAPCrashF1() {
causeSIGTRAPCrashF2();
}
/***************************************************/
58 changes: 58 additions & 0 deletions example/android/app/src/main/cpp/crasher_2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@


/************* SIGSEGV *******************************/
void causeSIGSEGVCrashF3();

void causeSIGSEGVCrashF2();

void causeSIGSEGVCrashF1();

/*****************************************************/

/************* SIGABRT *******************************/
void causeSIGABRTCrashF3();

void causeSIGABRTCrashF2();

void causeSIGABRTCrashF1();

/****************************************************/

/************* SIGFPE *******************************/

int causeSIGFPECrashF3();

void causeSIGFPECrashF2();

void causeSIGFPECrashF1();

/***************************************************/

/************* SIGILL *******************************/

void causeSIGILLCrashF3();

void causeSIGILLCrashF2();

void causeSIGILLCrashF1();

/***************************************************/

/************* SIGBUS *******************************/

void causeSIGBUSCrashF3();

void causeSIGBUSCrashF2();

void causeSIGBUSCrashF1();

/***************************************************/

/************* SIGTRAP *******************************/

void causeSIGTRAPCrashF3();

void causeSIGTRAPCrashF2();

void causeSIGTRAPCrashF1();
/***************************************************/
44 changes: 44 additions & 0 deletions example/android/app/src/main/cpp/crasher_3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#pragma GCC optimize ("O0")
#include <jni.h>
#include <sys/user.h>
#include <unistd.h>
#include <stdlib.h>
#include "crasher_4.h"

/************* SIGSEGV *******************************/
void causeSIGSEGVCrashF2() {
causeSIGSEGVCrashF3(NULL);
}
/*****************************************************/

/************* SIGABRT *******************************/
void causeSIGABRTCrashF2() {
causeSIGABRTCrashF3();
}
/****************************************************/

/************* SIGFPE *******************************/
void causeSIGFPECrashF2() {
unsigned int *bad_pointer = (unsigned int *)(0xdeadbeef);
*bad_pointer=0xfeedface;
}
/***************************************************/

/************* SIGILL *******************************/
void causeSIGILLCrashF2() {
causeSIGILLCrashF3();
}
/***************************************************/

/************* SIGBUS *******************************/
void causeSIGBUSCrashF2() {
causeSIGBUSCrashF3();
}
/***************************************************/

/************* SIGTRAP *******************************/
void causeSIGTRAPCrashF2() {
causeSIGTRAPCrashF3();
}
/***************************************************/
24 changes: 24 additions & 0 deletions example/android/app/src/main/cpp/crasher_3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

/************* SIGSEGV *******************************/
void causeSIGSEGVCrashF2();
/*****************************************************/

/************* SIGABRT *******************************/
void causeSIGABRTCrashF2();
/****************************************************/

/************* SIGFPE *******************************/
void causeSIGFPECrashF2();
/***************************************************/

/************* SIGILL *******************************/
void causeSIGILLCrashF2();
/***************************************************/

/************* SIGBUS *******************************/
void causeSIGBUSCrashF2();
/***************************************************/

/************* SIGTRAP *******************************/
void causeSIGTRAPCrashF2();
/***************************************************/
Loading