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

+2
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

+3
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

+4
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

+44-11
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

+1
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

+7
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

+1-1
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

+1-1
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

+1
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package unity.of.bugs
2+
3+
import android.util.Log
4+
import kotlin.concurrent.thread
5+
6+
object KotlinPlugin {
7+
@JvmStatic fun `throw`() {
8+
try {
9+
throw Exception("Bugs in Kotlin 🐛")
10+
}
11+
catch (e: Exception) {
12+
Log.e("test", "Exception thrown in Kotlin!", e)
13+
throw e
14+
}
15+
}
16+
@JvmStatic fun throwOnBackgroundThread() {
17+
thread(start = true) {
18+
throw Exception("Kotlin 🐛 from a background thread.")
19+
}
20+
}
21+
}

samples/unity-of-bugs/Assets/Scripts/KotlinPlugin.kt.meta

+91
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/unity-of-bugs/ProjectSettings/GraphicsSettings.asset

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ GraphicsSettings:
3434
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
3535
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
3636
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
37-
- {fileID: 16002, guid: 0000000000000000f000000000000000, type: 0}
37+
- {fileID: 16003, guid: 0000000000000000f000000000000000, type: 0}
3838
m_PreloadedShaders: []
3939
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
4040
type: 0}

src/Sentry.Unity.Editor.iOS/BuildPostProcess.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using Sentry.Extensibility;
3-
using Sentry.Infrastructure;
43
using UnityEditor;
54
using UnityEditor.Callbacks;
65

src/Sentry.Unity.Editor.iOS/Sentry.Unity.Editor.iOS.csproj

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
</ItemGroup>
1212

1313
<!-- Add reference once we figure out where the DLL is (find Unity version and install location) -->
14-
<Target Name="FindIOSBuildTools"
15-
AfterTargets="FindUnity"
16-
BeforeTargets="BeforeResolveReferences">
14+
<Target Name="FindIOSBuildTools" AfterTargets="FindUnity" BeforeTargets="BeforeResolveReferences">
1715

1816
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
1917
<IOSBuildTools>$(UnityRoot)/../PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.Xcode.dll</IOSBuildTools>
@@ -23,8 +21,7 @@
2321
<IOSBuildTools>$(UnityRoot)/Data/PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.Xcode.dll</IOSBuildTools>
2422
</PropertyGroup>
2523

26-
<Error Condition="!Exists('$(IOSBuildTools)')"
27-
Text="iOS build tools not found. Make sure to install the Unity iOS Module."></Error>
24+
<Error Condition="!Exists('$(IOSBuildTools)')" Text="iOS build tools not found. Make sure to install the Unity iOS Module."></Error>
2825

2926
<ItemGroup>
3027
<Reference Include="UnityEditor">

src/Sentry.Unity.Editor.iOS/SentryXcodeProject.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.IO;
33
using UnityEditor.iOS.Xcode;
44
using UnityEditor.iOS.Xcode.Extensions;
5-
using UnityEngine;
65

76
namespace Sentry.Unity.Editor.iOS
87
{

0 commit comments

Comments
 (0)