Skip to content

Commit dd0a059

Browse files
feat: Android Native Support (#307)
Co-authored-by: Sentry Github Bot <[email protected]>
1 parent 19b3bc6 commit dd0a059

31 files changed

+726
-34
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ samples/unity-of-bugs/Assets/InitTestScene*
2121
package-dev/**/*.dll
2222
package-dev/**/*.meta
2323
package-dev/**/*.framework
24+
# Android SDK files
25+
package-dev/Plugins/Android/Sentry/*
2426
# required to be makred as iOS only
2527
!package-dev/**/*.framework.meta
2628
!package-dev/Runtime/Sentry.Unity.dll.meta

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "src/sentry-cocoa"]
55
path = src/sentry-cocoa
66
url = https://github.com/getsentry/sentry-cocoa
7+
[submodule "src/sentry-java"]
8+
path = src/sentry-java
9+
url = https://github.com/getsentry/sentry-java.git

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Feature
6+
7+
- Android Native Support ([#307](https://github.com/getsentry/sentry-unity/pull/307))
8+
59
### Fixes
610

711
- Import link.xml caused an infinite loop ([#315](https://github.com/getsentry/sentry-unity/pull/315))

Directory.Build.targets

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
<UnitySampleProjectUnityVersion>$(SolutionDir)samples/unity-of-bugs/ProjectSettings/ProjectVersion.txt</UnitySampleProjectUnityVersion>
1111
<UnityTestPlayModeResultFilePath>../../artifacts/test/playmode/results.xml</UnityTestPlayModeResultFilePath>
1212
<UnityTestEditModeResultFilePath>../../artifacts/test/editmode/results.xml</UnityTestEditModeResultFilePath>
13-
<!-- Cocoa-->
14-
<CocoaRoot>$(SolutionDir)src/sentry-cocoa/</CocoaRoot>
15-
<CocoaFrameworkDestination>$(SolutionDir)package-dev/Plugins/iOS/Sentry.framework/</CocoaFrameworkDestination>
13+
<!-- Cocoa -->
14+
<SentryCocoaRoot>$(SolutionDir)src/sentry-cocoa/</SentryCocoaRoot>
15+
<SentryCocoaArtifactsDestination>$(SolutionDir)package-dev/Plugins/iOS/Sentry.framework/</SentryCocoaArtifactsDestination>
16+
<!-- Android -->
17+
<SentryAndroidRoot>$(SolutionDir)src/sentry-java/</SentryAndroidRoot>
18+
<SentryAndroidArtifactsDestination>$(SolutionDir)package-dev/Plugins/Android/Sentry/</SentryAndroidArtifactsDestination>
1619
</PropertyGroup>
1720

1821
<!-- Use the Unity Editor version set in the sample project of the repo -->
@@ -56,29 +59,59 @@
5659
<RemoveDir Directories="$(UnityPackageProject)" />
5760
</Target>
5861

59-
<Target Name="CleanCocoaSDK" AfterTargets="Clean" Condition="Exists('$(CocoaFrameworkDestination)')">
60-
<RemoveDir Directories="$(CocoaFrameworkPath)Sentry.framework" />
62+
<Target Name="CleanCocoaSDK" AfterTargets="Clean" Condition="Exists('$(SentryCocoaArtifactsDestination)')">
63+
<RemoveDir Directories="$(SentryCocoaArtifactsDestination)" ContinueOnError="true" />
64+
</Target>
65+
66+
<Target Name="CleanAndroidSDK" AfterTargets="Clean" Condition="Exists('$(SentryAndroidArtifactsDestination)')">
67+
<RemoveDir Directories="$(SentryAndroidArtifactsDestination)" ContinueOnError="true" />
6168
</Target>
6269

6370
<!-- Build the iOS SDK: dotnet msbuild /t:BuildCocoaSDK -->
6471
<Target Name="BuildCocoaSDK"
6572
Condition="$([MSBuild]::IsOSPlatform('OSX'))
6673
And '$(MSBuildProjectName)' == 'Sentry.Unity'
67-
And !Exists('$(CocoaFrameworkDestination)')"
74+
And !Exists('$(SentryCocoaArtifactsDestination)')"
6875
BeforeTargets="BeforeBuild">
69-
<Error Condition="!Exists('$(CocoaRoot)')" Text="Couldn't find the Cocoa root at $(CocoaRoot)."></Error>
76+
<Error Condition="!Exists('$(SentryCocoaRoot)')" Text="Couldn't find the Cocoa root at $(SentryCocoaRoot)."></Error>
77+
<Message Importance="High" Text="Building Sentry iOS SDK."></Message>
7078

71-
<Exec WorkingDirectory="$(CocoaRoot)" Command="carthage build --use-xcframeworks --no-skip-current --platform iOS"></Exec>
79+
<Exec WorkingDirectory="$(SentryCocoaRoot)" Command="carthage build --use-xcframeworks --no-skip-current --platform iOS"></Exec>
7280

7381
<!-- Itemgroup for the output Sentry.framework so we have access to '%(RecursiveDir)' when copying -->
7482
<ItemGroup>
75-
<CocoaBuildPath Include="$(CocoaRoot)Carthage/Build/Sentry.xcframework/ios-arm64_armv7/Sentry.framework/**/*" />
83+
<CocoaBuildPath Include="$(SentryCocoaRoot)Carthage/Build/Sentry.xcframework/ios-arm64_armv7/Sentry.framework/**/*" />
7684
</ItemGroup>
7785
<Copy SourceFiles="@(CocoaBuildPath)"
78-
DestinationFiles="@(CocoaBuildPath->'$(CocoaFrameworkDestination)%(RecursiveDir)%(Filename)%(Extension)')">
86+
DestinationFiles="@(CocoaBuildPath->'$(SentryCocoaArtifactsDestination)%(RecursiveDir)%(Filename)%(Extension)')">
87+
</Copy>
88+
89+
<Error Condition="!Exists('$(SentryCocoaArtifactsDestination)')" Text="Failed to build the Cocoa SDK."></Error>
90+
</Target>
91+
92+
<!-- Build the Android SDK: dotnet msbuild /t:BuildAndroidSDK -->
93+
<Target Name="BuildAndroidSDK"
94+
Condition="'$(MSBuildProjectName)' == 'Sentry.Unity'
95+
And !Exists('$(SentryAndroidArtifactsDestination)')"
96+
BeforeTargets="BeforeBuild">
97+
<Error Condition="!Exists('$(SentryAndroidRoot)')" Text="Couldn't find the Android root at $(SentryAndroidRoot)."></Error>
98+
<Message Importance="High" Text="Building Sentry Android SDK."></Message>
99+
100+
<Exec WorkingDirectory="$(SentryAndroidRoot)" Command="./gradlew :sentry-android-core:assembleRelease :sentry-android-ndk:assembleRelease :sentry:jar"></Exec>
101+
102+
<ItemGroup>
103+
<!-- building snapshot based on version, i.e: sentry-5.0.0-beta.3-SNAPSHOT.jar -->
104+
<AndroidSdkArtifacts Include="$(SentryAndroidRoot)sentry/build/libs/sentry*.jar" />
105+
<AndroidSdkArtifacts Include="$(SentryAndroidRoot)sentry-android-ndk/build/outputs/aar/sentry-android-ndk-release.aar" />
106+
<AndroidSdkArtifacts Include="$(SentryAndroidRoot)sentry-android-core/build/outputs/aar/sentry-android-core-release.aar" />
107+
<AndroidSdkArtifacts Include="$(SolutionDir)lib/gson-2.8.5.jar" />
108+
</ItemGroup>
109+
110+
<Copy SourceFiles="@(AndroidSdkArtifacts)"
111+
DestinationFiles="@(AndroidSdkArtifacts->'$(SentryAndroidArtifactsDestination)%(RecursiveDir)%(Filename)%(Extension)')">
79112
</Copy>
80113

81-
<Error Condition="!Exists('$(CocoaFrameworkDestination)')" Text="Failed to build the Cocoa SDK."></Error>
114+
<Error Condition="!Exists('$(SentryAndroidArtifactsDestination)')" Text="Failed to build the Android SDK."></Error>
82115
</Target>
83116

84117
<!-- Even with a successful build, Unity will error on 'usbmuxd' or log out to std-error which breaks msbuild.

before.Sentry.Unity.sln.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<!-- If sentry-dotnet is not found, restore git submodules -->
33
<Target Name="RestoreSubmodules"
44
Condition="!Exists('src/sentry-dotnet/src/Sentry/Sentry.csproj')
5+
OR !Exists('src/sentry-java/build.gradle.kts')
56
OR !Exists('src/sentry-cocoa/Sentry.xcodeproj')">
67
<Message Importance="High" Text="Restoring git submodules."></Message>
78
<Exec Command="git submodule update --init --recursive"></Exec>

lib/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
`gson` is a dependency of Sentry Android and is planned to be removed.
2+
3+
While it is still a dependency, we'll copy from here when assembling the Unity package in combination with the Sentry SDK for Android.
4+
5+
From: https://search.maven.org/remotecontent?filepath=com/google/code/gson/gson/2.8.5/gson-2.8.5.jar
6+
7+
[Version defined in buildSrc](../src/sentry-java/buildSrc/src/main/java/Config.kt)

lib/gson-2.8.5.jar

236 KB
Binary file not shown.

samples/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<Project>
2-
<!-- Stops msbuild from looking on the part directory. Can't deal with the properties set such as C# 9 -->
2+
<!-- Stops msbuild from looking on the parent directory. Can't deal with the properties set such as C# 9 -->
33
</Project>

samples/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<Project>
2-
<!-- Stops msbuild from looking on the part directory. Can't deal with the properties set such as C# 9 -->
2+
<!-- Stops msbuild from looking on the parent directory. Can't deal with the properties set such as C# 9 -->
33
</Project>

samples/unity-of-bugs/Assets/Resources/Sentry/SentryOptions.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ MonoBehaviour:
3131
<ShutdownTimeout>k__BackingField: 2000
3232
<MaxQueueItems>k__BackingField: 30
3333
<IOSNativeSupportEnabled>k__BackingField: 1
34+
<AndroidNativeSupportEnabled>k__BackingField: 1
3435
<Debug>k__BackingField: 1
3536
<DebugOnlyInEditor>k__BackingField: 1
3637
<DiagnosticLevel>k__BackingField: 0

0 commit comments

Comments
 (0)