Skip to content

feat: Managed layer initializes native SDK on Android #1924

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

Merged
merged 86 commits into from
Dec 13, 2024

Conversation

bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Nov 28, 2024

Android: Android SDK Initialization

Overview

Implements the late initialization of the Android SDK. This allows users to apply code changes to the options and for those options to apply to the native layer. Related issue: sentry-unity#1907

Implementation Details

The SDK now always includes the Android SDK in the generated Gradle project with the following changes:

  1. New Native Support Option
  • Added an enum AndroidNativeInitializationType to the SentryOptions. This allows users to switch between Runtime and BuildTime initialization and defaults to Runtime.
  • The AndroidNativeSupportEnabled controls whether the SDK should add native support. This helps i.e. in the case of UaaL where users want to completely disabled the SDK from modifying the Gradle project.
  1. Build Process Changes
  • Adding the native options to the manifest is now controlled by AndroidNativeInitializationType enum
    • With type Runtime the SDK will add auto-init = false.
    • With type BuildTime it will add the options and let the Android SDK autoinitialize.
  1. Runtime Behavior
  • SentryNativeAndroid.Configure checks whether the native SDK was already initialized
  • Both early and late initialization are going through the same code paths: i.e. setting up scope observer.
  1. JNI Executor Behavior
  • The JNI Executor defaults to timeout after 16ms as to not drop more than a frame
  • Android SDK initialization takes about 25ms on a current device. So the timeout is now overwriteable when calling into the executor.

Pending Tasks

  • RuntimeInitialization is default. This means we're missing testing BuildTime in CI right now.
  • "Init Native First" flow
  • "Init Native Late" flow
  • Note: Requires duplicate mobile smoke testing (2x build, compile, test)

@bitsandfoxes bitsandfoxes marked this pull request as ready for review December 5, 2024 17:14
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

CI seems not to be running

@bruno-garcia
Copy link
Member

image

Smoke Test still unreliable?

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

I see 5 new tests for quite a significant change. I'm concerned there are lot of untested use cases. Isn't that the case?

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

One issue left which is the thread.Join on Dispose which can throw.

Other than that, lgtm

@bitsandfoxes bitsandfoxes merged commit c0681ff into main Dec 13, 2024
94 checks passed
@bitsandfoxes bitsandfoxes deleted the feat/android-init-android branch December 13, 2024 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants