Skip to content

Commit

Permalink
Exclude SentryOptions from obfuscation (#2699)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Zavarnitsyn <rom4ek93@gmail.com>
Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
  • Loading branch information
3 people committed May 16, 2023
1 parent 6a11214 commit 360297d
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 126 deletions.
39 changes: 30 additions & 9 deletions .github/workflows/agp-matrix.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: AGP Matrix Sample Release
name: AGP Matrix Compatibility

on:
push:
Expand All @@ -16,29 +16,50 @@ jobs:
with:
access_token: ${{ github.token }}

agp-matrix-sample-release:
runs-on: ubuntu-latest
agp-matrix-compatibility:
timeout-minutes: 25
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
agp: ['8.0.0-rc01','8.1.0-alpha11']
agp: [ '8.0.0','8.1.0-alpha11' ]
ndk: [ true, false ]

name: AGP Matrix Sample Release - AGP ${{ matrix.agp }}
name: AGP Matrix Release - AGP ${{ matrix.agp }} - NDK ${{ matrix.ndk }}
env:
VERSION_AGP: ${{ matrix.agp }}
APPLY_NDK: ${{ matrix.ndk }}

steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Gradle
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 # pin@v2

- name: Setup Java Version
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Build the Release variant
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 # pin@v2
# Clean, build and release a test apk
- name: Make assembleUiTests
run: make assembleUiTests

# We stop gradle at the end to make sure the cache folders
# don't contain any lock files and are free to be cached.
- name: Make stop
run: make stop

- name: Run instrumentation tests
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b # pin@v2
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
arguments: sentry-android-integration-tests:sentry-test-agp:assembleRelease
api-level: 30
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
disable-spellchecker: true
target: 'aosp_atd'
channel: canary # Necessary for ATDs
script: ./gradlew sentry-android-integration-tests:sentry-uitest-android:connectedReleaseAndroidTest -DtestBuildType=release --daemon
11 changes: 10 additions & 1 deletion .github/workflows/integration-tests-ui.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Integration Tests - Ui tests'
name: 'Integration Tests'
on:
push:
branches:
Expand All @@ -7,6 +7,14 @@ on:
pull_request:

jobs:
cancel-previous-workflow:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # pin@0.11.0
with:
access_token: ${{ github.token }}

test:
name: Ui tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -43,3 +51,4 @@ jobs:
sauce-access-key: ${{ secrets.SAUCE_ACCESS_KEY }}
config-file: .sauce/sentry-uitest-android-ui.yml
if: env.SAUCE_USERNAME != null

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
- Android Profiler on calling thread ([#2691](https://github.com/getsentry/sentry-java/pull/2691))
- Use `configureScope` instead of `withScope` in `Hub.close()`. This ensures that the main scope releases the in-memory data when closing a hub instance. ([#2688](https://github.com/getsentry/sentry-java/pull/2688))
- Remove null keys/values before creating concurrent hashmap in order to avoid NPE ([#2708](https://github.com/getsentry/sentry-java/pull/2708))
- Exclude SentryOptions from R8/ProGuard obfuscation ([#2699](https://github.com/getsentry/sentry-java/pull/2699))
- This fixes AGP 8.+ incompatibility, where full R8 mode is enforced

### Dependencies

Expand Down
4 changes: 4 additions & 0 deletions sentry-android-core/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@
# Keep Classnames for integrations
-keepnames class * implements io.sentry.IntegrationName

# Keep any custom option classes like SentryAndroidOptions, as they're loaded via reflection
# Also keep method names, as they're e.g. used by native via JNI calls
-keep class * extends io.sentry.SentryOptions { *; }

##---------------End: proguard configuration for android-core ----------
2 changes: 1 addition & 1 deletion sentry-android-integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* [App metrics test specification (yaml)](./metrics-test.yml)
* [Espresso-based benchmarks](./sentry-uitest-android-benchmark) - run within SauceLabs (see /.sauce/*.yml)
* [Espresso-based UI tests](./sentry-uitest-android) - run within SauceLabs (see /.sauce/*.yml)
* [Sample app for testing against AGP compatibility matrix](./sentry-test-agp)
* Also used for compatibility test matrix against new AGP versions

This file was deleted.

64 changes: 0 additions & 64 deletions sentry-android-integration-tests/sentry-test-agp/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ android {
isShrinkResources = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
signingConfig = signingConfigs.getByName("debug") // to be able to run release mode
testProguardFiles("proguard-rules.pro")
}
}

Expand All @@ -87,11 +88,17 @@ android {
}
}

val applyNdk = System.getenv("APPLY_NDK")?.toBoolean() ?: false

dependencies {

implementation(kotlin(Config.kotlinStdLib, org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION))

implementation(projects.sentryAndroid)
if (applyNdk) {
implementation(projects.sentryAndroid)
} else {
implementation(projects.sentryAndroidCore)
}
implementation(projects.sentryCompose)
implementation(Config.Libs.appCompat)
implementation(Config.Libs.androidxCore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,23 @@
# hide the original source file name.
#-renamesourcefileattribute SourceFile

#Shrinking removes annotations and "unused classes" from test apk, so we don't shrink
-dontshrink

-dontwarn com.google.errorprone.**
-dontwarn com.sun.jna.**
-dontwarn edu.umd.cs.findbugs.**
-dontwarn java.lang.instrument.**
-dontwarn java.lang.management.**
-dontwarn okhttp3.Handshake$Companion
-dontwarn okhttp3.Headers$Companion
-dontwarn okhttp3.HttpUrl$Companion
-dontwarn okhttp3.Protocol$Companion
-dontwarn okhttp3.internal.**
-dontwarn okio.ByteString$Companion
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
-dontwarn org.opentest4j.AssertionFailedError
-dontwarn org.mockito.internal.**
-dontwarn org.jetbrains.annotations.**

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.sentry.Sentry
import io.sentry.android.core.SentryAndroid
import io.sentry.android.core.SentryAndroidOptions
import io.sentry.uitest.android.mockservers.MockRelay
import java.io.FileInputStream
import java.util.concurrent.TimeUnit
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
Expand Down Expand Up @@ -39,6 +40,17 @@ abstract class BaseUiTest {
/** Mock relay server that receives all envelopes sent during the test. */
protected val relay = MockRelay(false, relayIdlingResource)

private fun disableDontKeepActivities() {
val automation = InstrumentationRegistry.getInstrumentation().uiAutomation
val pfd = automation.executeShellCommand("settings put global always_finish_activities 0")
try {
FileInputStream(pfd.fileDescriptor).readBytes()
} catch (e: Throwable) {
// ignored
}
pfd.close()
}

@BeforeTest
fun baseSetUp() {
runner = InstrumentationRegistry.getInstrumentation() as AndroidJUnitRunner
Expand All @@ -47,6 +59,7 @@ abstract class BaseUiTest {
context.cacheDir.deleteRecursively()
relay.start()
mockDsn = relay.createMockDsn()
disableDontKeepActivities()
}

@AfterTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import io.sentry.protocol.SentryTransaction
import org.junit.runner.RunWith
import java.io.File
import java.util.concurrent.TimeUnit
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand All @@ -43,6 +44,7 @@ class EnvelopeTests : BaseUiTest() {
}
}

@Ignore("Something is wrong with measurements assertions, flaking almost every time")
@Test
fun checkEnvelopeProfiledTransaction() {
initSentry(true) { options: SentryAndroidOptions ->
Expand Down
4 changes: 2 additions & 2 deletions sentry-android-ndk/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# The Android SDK checks at runtime if this class is available via Class.forName
-keep class io.sentry.android.ndk.SentryNdk { *; }
# The JNI layer uses this classes through reflection
-keep class io.sentry.android.core.SentryAndroidOptions { *; }

# The JNI layer uses this class through reflection
-keep class io.sentry.protocol.DebugImage { *; }

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
Expand Down
3 changes: 1 addition & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ include(
"sentry-android-integration-tests:sentry-uitest-android-benchmark",
"sentry-android-integration-tests:sentry-uitest-android",
"sentry-android-integration-tests:test-app-plain",
"sentry-android-integration-tests:test-app-sentry",
"sentry-android-integration-tests:sentry-test-agp"
"sentry-android-integration-tests:test-app-sentry"
)

gradle.beforeProject {
Expand Down

0 comments on commit 360297d

Please sign in to comment.