Skip to content
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

Move NDK from sentry-java to sentry-native #3189

Merged
merged 15 commits into from
May 28, 2024
Merged
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "sentry-android-ndk/sentry-native"]
path = sentry-android-ndk/sentry-native
url = https://github.com/getsentry/sentry-native
5 changes: 1 addition & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ buildscript {
classpath(Config.QualityPlugins.errorpronePlugin)
classpath(Config.QualityPlugins.gradleVersionsPlugin)

// add classpath of androidNativeBundle
// com.ydq.android.gradle.build.tool:nativeBundle:{version}}
classpath(Config.NativePlugins.nativeBundlePlugin)

// add classpath of sentry android gradle plugin
// classpath("io.sentry:sentry-android-gradle-plugin:{version}")

Expand Down Expand Up @@ -78,6 +74,7 @@ allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
}
group = Config.Sentry.group
version = properties[Config.Sentry.versionNameProp].toString()
Expand Down
5 changes: 0 additions & 5 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,4 @@ object Config {
val errorprone = "com.google.errorprone:error_prone_core:2.11.0"
val errorProneNullAway = "com.uber.nullaway:nullaway:0.9.5"
}

object NativePlugins {
val nativeBundlePlugin = "io.github.howardpang:androidNativeBundle:1.1.1"
val nativeBundleExport = "com.ydq.android.gradle.native-aar.export"
}
}
17 changes: 0 additions & 17 deletions sentry-android-ndk/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion sentry-android-ndk/api/sentry-android-ndk.api
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public final class io/sentry/android/ndk/BuildConfig {
}

public final class io/sentry/android/ndk/DebugImagesLoader : io/sentry/android/core/IDebugImagesLoader {
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/ndk/NativeModuleListLoader;)V
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/ndk/NativeModuleListLoader;)V
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This smells like a breaking change - should we make it part of v8 actually?

public fun clearDebugImages ()V
public fun loadDebugImages ()Ljava/util/List;
}
Expand Down
32 changes: 2 additions & 30 deletions sentry-android-ndk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,21 @@ plugins {
kotlin("android")
jacoco
id(Config.QualityPlugins.jacocoAndroid)
id(Config.NativePlugins.nativeBundleExport)
id(Config.QualityPlugins.gradleVersions)
}

var sentryNativeSrc: String = "sentry-native"
val sentryAndroidSdkName: String by project

android {
compileSdk = Config.Android.compileSdkVersion
namespace = "io.sentry.android.ndk"

sentryNativeSrc = if (File("${project.projectDir}/sentry-native-local").exists()) {
"sentry-native-local"
} else {
"sentry-native"
}
println("sentry-android-ndk: $sentryNativeSrc")

defaultConfig {
targetSdk = Config.Android.targetSdkVersion
minSdk = Config.Android.minSdkVersionNdk // NDK requires a higher API level than core.

testInstrumentationRunner = Config.TestLibs.androidJUnitRunner

externalNativeBuild {
cmake {
arguments.add(0, "-DANDROID_STL=c++_static")
arguments.add(0, "-DSENTRY_NATIVE_SRC=$sentryNativeSrc")
arguments.add(0, "-DSENTRY_SDK_NAME=$sentryAndroidSdkName")
}
}

ndk {
abiFilters.addAll(Config.Android.abiFilters)
}
Expand All @@ -45,15 +28,6 @@ android {
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
}

// we use the default NDK and CMake versions based on the AGP's version
// https://developer.android.com/studio/projects/install-ndk#apply-specific-version

externalNativeBuild {
cmake {
path("CMakeLists.txt")
}
}

buildTypes {
getByName("debug")
getByName("release") {
Expand Down Expand Up @@ -81,10 +55,6 @@ android {
checkReleaseBuilds = false
}

nativeBundleExport {
headerDir = "${project.projectDir}/$sentryNativeSrc/include"
}

// needed because of Kotlin 1.4.x
configurations.all {
resolutionStrategy.force(Config.CompileOnly.jetbrainsAnnotations)
Expand All @@ -101,6 +71,8 @@ dependencies {
api(projects.sentry)
api(projects.sentryAndroidCore)

implementation("io.sentry:sentry-native-ndk:0.7.20")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll probably need to make our dependency updater work for this module too


compileOnly(Config.CompileOnly.jetbrainsAnnotations)

testImplementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
Expand Down
1 change: 0 additions & 1 deletion sentry-android-ndk/sentry-native
Submodule sentry-native deleted from 4ec95c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import io.sentry.SentryOptions;
import io.sentry.android.core.IDebugImagesLoader;
import io.sentry.android.core.SentryAndroidOptions;
import io.sentry.ndk.NativeModuleListLoader;
import io.sentry.protocol.DebugImage;
import io.sentry.util.Objects;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -45,9 +46,20 @@ public DebugImagesLoader(
synchronized (debugImagesLock) {
if (debugImages == null) {
try {
final DebugImage[] debugImagesArr = moduleListLoader.loadModuleList();
final io.sentry.ndk.DebugImage[] debugImagesArr = moduleListLoader.loadModuleList();
if (debugImagesArr != null) {
debugImages = Arrays.asList(debugImagesArr);
debugImages = new ArrayList<>(debugImagesArr.length);
for (io.sentry.ndk.DebugImage d : debugImagesArr) {
final DebugImage debugImage = new DebugImage();
debugImage.setUuid(d.getUuid());
debugImage.setType(d.getType());
debugImage.setDebugId(d.getDebugId());
debugImage.setCodeId(d.getCodeId());
debugImage.setImageAddr(d.getImageAddr());
debugImage.setImageSize(d.getImageSize());
debugImage.setArch(d.getArch());
debugImages.add(debugImage);
}
options
.getLogger()
.log(SentryLevel.DEBUG, "Debug images loaded: %d", debugImages.size());
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import io.sentry.ScopeObserverAdapter;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.ndk.INativeScope;
import io.sentry.ndk.NativeScope;
import io.sentry.protocol.User;
import io.sentry.util.Objects;
import java.util.Locale;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.sentry.android.ndk;

import io.sentry.android.core.SentryAndroidOptions;
import io.sentry.ndk.NativeModuleListLoader;
import io.sentry.ndk.NdkOptions;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

Expand All @@ -9,29 +11,25 @@ public final class SentryNdk {

private SentryNdk() {}

static {
// On older Android versions, it was necessary to manually call "`System.loadLibrary` on all
// transitive dependencies before loading [the] main library."
// The dependencies of `libsentry.so` are currently `lib{c,m,dl,log}.so`.
// See
// https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#changes-to-library-dependency-resolution
System.loadLibrary("log");
System.loadLibrary("sentry");
System.loadLibrary("sentry-android");
}

private static native void initSentryNative(@NotNull final SentryAndroidOptions options);

private static native void shutdown();

/**
* Init the NDK integration
*
* @param options the SentryAndroidOptions
*/
public static void init(@NotNull final SentryAndroidOptions options) {
SentryNdkUtil.addPackage(options.getSdkVersion());
initSentryNative(options);

final @NotNull NdkOptions ndkOptions =
new NdkOptions(
options.getDsn(),
options.isDebug(),
options.getOutboxPath(),
options.getRelease(),
options.getEnvironment(),
options.getDist(),
options.getMaxBreadcrumbs(),
options.getNativeSdkName());
io.sentry.ndk.SentryNdk.init(ndkOptions);

// only add scope sync observer if the scope sync is enabled.
if (options.isEnableScopeSync()) {
Expand All @@ -43,6 +41,6 @@ public static void init(@NotNull final SentryAndroidOptions options) {

/** Closes the NDK integration */
public static void close() {
shutdown();
io.sentry.ndk.SentryNdk.close();
}
}
Loading
Loading