Repository navigation
feat(native): Add Android support for out-of-process crash handling #1725
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
base: v1
Are you sure you want to change the base?
Changes from all commits
7f4f85a
db692ea
8c5b4f8
8ecb9a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import com.android.build.api.dsl.LibraryExtension | ||
| import com.diffplug.gradle.spotless.SpotlessPlugin | ||
| import com.diffplug.spotless.LineEnding | ||
| import com.vanniktech.maven.publish.MavenPublishBaseExtension | ||
|
|
@@ -73,6 +74,11 @@ subprojects { | |
| } | ||
| } | ||
| } | ||
| if (name == "sentry-native-ndk-outproc") { | ||
| plugins.withId("com.android.library") { | ||
| configureNdkLibrary() | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inproc module lost backend capabilityMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit c451ff8. Configure here. |
||
| } | ||
|
|
||
| plugins.withId("io.gitlab.arturbosch.detekt") { | ||
| configure<DetektExtension> { | ||
|
|
@@ -224,5 +230,207 @@ fun MavenPublishBaseExtension.assignAarTypes() { | |
| } | ||
|
|
||
| apiValidation { | ||
| ignoredProjects.addAll(listOf("sample")) | ||
| ignoredProjects.addAll(listOf("sample", "sentry-native-ndk-outproc")) | ||
| } | ||
|
|
||
| fun Project.configureNdkLibrary() { | ||
| var sentryNativeSrc: String = "${project.projectDir}/../.." | ||
| val nativeBackend = project.name == "sentry-native-ndk-outproc" | ||
| val sentryBackend = if (nativeBackend) "native" else providers.gradleProperty("sentryBackend").orElse("inproc").get() | ||
| val libDir = rootProject.file("lib") | ||
| val sanitizer = | ||
| System.getenv("RUN_ANALYZER").orEmpty().split(',') | ||
| .firstOrNull { it == "asan" || it == "tsan" } | ||
|
|
||
| configure<LibraryExtension> { | ||
| compileSdk = 37 | ||
| // retain AGP 8.7.3's default NDK to avoid changing the compiler and libc++ in a hotfix | ||
| ndkVersion = System.getenv("ANDROID_NDK")?.let { File(it).name } ?: "27.0.12077973" | ||
| namespace = "io.sentry.ndk" | ||
|
|
||
| testBuildType = "debug" | ||
|
|
||
| defaultConfig { | ||
| minSdk = 21 | ||
|
|
||
| aarMetadata { | ||
| // avoid requiring consumers to compile against API 37 | ||
| minCompileSdk = 1 | ||
| } | ||
|
|
||
| externalNativeBuild { | ||
| cmake { | ||
| arguments.add(0, "-DSENTRY_BACKEND=$sentryBackend") | ||
| if (sentryBackend == "inproc") { | ||
| arguments.add(0, "-DSENTRY_TRANSPORT=none") | ||
| } | ||
| arguments.add(0, "-DANDROID_STL=${if (sanitizer != null) "c++_shared" else "c++_static"}") | ||
| arguments.add(0, "-DSENTRY_NATIVE_SRC=$sentryNativeSrc") | ||
| if (sanitizer == "asan") { | ||
| arguments.add(0, "-DWITH_ASAN_OPTION=ON") | ||
| } | ||
| if (sanitizer == "tsan") { | ||
| arguments.add(0, "-DWITH_TSAN_OPTION=ON") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ndk { | ||
| abiFilters.addAll( | ||
| if (sanitizer == "tsan") { | ||
| listOf("x86_64", "arm64-v8a") | ||
| } else { | ||
| listOf("x86", "armeabi-v7a", "x86_64", "arm64-v8a") | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| } | ||
|
|
||
| if (nativeBackend) { | ||
| sourceSets.all { setRoot("$libDir/src/$name") } | ||
| } | ||
|
|
||
| if (sanitizer != null) { | ||
| sourceSets.getByName("androidTest") { | ||
| jniLibs.srcDir("$libDir/build/$sanitizer/jniLibs") | ||
| resources.srcDir("$libDir/build/$sanitizer/resources") | ||
| } | ||
| } | ||
|
|
||
| // 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("$libDir/CMakeLists.txt") | ||
| } | ||
| } | ||
|
|
||
| buildTypes { | ||
| getByName("debug") { | ||
| externalNativeBuild { | ||
| cmake { | ||
| arguments.add(0, "-DENABLE_TESTS=ON") | ||
| } | ||
| } | ||
| } | ||
| getByName("release") { | ||
| consumerProguardFiles("$libDir/proguard-rules.pro") | ||
| } | ||
| } | ||
|
|
||
| buildFeatures { | ||
| prefab = true | ||
| prefabPublishing = true | ||
| buildConfig = true | ||
| } | ||
|
|
||
| // creates | ||
| // lib.aar/prefab/modules/sentry-android/libs/<arch>/<lib>.so | ||
| // lib.aar/prefab/modules/sentry-android/include/sentry.h | ||
| prefab { | ||
| create("sentry-android") {} | ||
| create("sentry") { | ||
| headers = "../../include" | ||
| } | ||
| } | ||
|
|
||
| testOptions { | ||
| animationsDisabled = true | ||
| unitTests.apply { | ||
| isReturnDefaultValues = true | ||
| isIncludeAndroidResources = true | ||
| } | ||
| } | ||
|
|
||
| lint { | ||
| warningsAsErrors = true | ||
| checkDependencies = true | ||
| checkReleaseBuilds = true | ||
| disable.add("NewerVersionAvailable") | ||
| } | ||
|
|
||
| packaging { | ||
| jniLibs { | ||
| useLegacyPackaging = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // legacy pre-prefab support | ||
| // creates lib.aar/jni/include/sentry.h alongside AGP's lib.aar/jni/<arch>/<lib>.so | ||
| tasks.withType<Zip>().configureEach { | ||
| if (name.startsWith("bundle") && name.endsWith("Aar")) { | ||
| from("../../include") { | ||
| into("jni/include") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| "compileOnly"("org.jetbrains:annotations:23.0.0") | ||
|
|
||
| "testImplementation"("androidx.test.ext:junit:1.3.0") | ||
|
|
||
| "androidTestImplementation"("androidx.test:runner:1.7.0") | ||
| "androidTestImplementation"("androidx.test.ext:junit:1.3.0") | ||
| "androidTestImplementation"("androidx.test:rules:1.7.0") | ||
| } | ||
|
|
||
| /* | ||
| * Prefab doesn't support c++_static, so we need to change it to none. | ||
| * This should be fine, as we don't expose any conflicting symbols. | ||
| * Based on: https://github.com/bugsnag/bugsnag-android/blob/59460018551750dfcce4fd4e9f612eae7826559e/bugsnag-plugin-android-ndk/build.gradle.kts | ||
| * | ||
| * Copyright (c) 2012 Bugsnag | ||
|
|
||
| * Permission is hereby granted, free of charge, to any person obtaining | ||
| * a copy of this software and associated documentation files (the | ||
| * "Software"), to deal in the Software without restriction, including | ||
| * without limitation the rights to use, copy, modify, merge, publish, | ||
| * distribute, sublicense, and/or sell copies of the Software, and to | ||
| * permit persons to whom the Software is furnished to do so, subject to | ||
| * the following conditions: | ||
|
|
||
| * The above copyright notice and this permission notice shall be | ||
| * included in all copies or substantial portions of the Software. | ||
|
|
||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
| * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
| * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
| * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| * | ||
| */ | ||
| afterEvaluate { | ||
| configurations.matching { | ||
| it.name.startsWith("releaseVariant") && it.name.endsWith("Publication") | ||
| }.configureEach { | ||
| outgoing.capability("$group:${project.name}:$version") | ||
| outgoing.capability("$group:sentry-ndk-backend:$version") | ||
| } | ||
|
|
||
| tasks.matching { it.name.startsWith("prefab") && it.name.endsWith("Package") }.configureEach { | ||
| doLast { | ||
| project.fileTree("build/intermediates/") { | ||
| include("**/abi.json") | ||
| include("**/prefab.json") | ||
| include("**/prefab_publication.json/*") | ||
| }.forEach { file -> | ||
| val contents = file.readText().replace("c++_static", "none") | ||
| file.writeText( | ||
| if (nativeBackend) { | ||
| contents.replace("\"name\": \"${project.name}\"", "\"name\": \"sentry-native-ndk\"") | ||
| .replace("\"packageName\": \"${project.name}\"", "\"packageName\": \"sentry-native-ndk\"") | ||
| } else { | ||
| contents | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||


Uh oh!
There was an error while loading. Please reload this page.