Skip to content

Commit 5315788

Browse files
authored
Merge pull request #12 from bugfender/develop
Develop
2 parents 31d3d86 + b3e6daf commit 5315788

9 files changed

Lines changed: 144 additions & 8 deletions

File tree

Editor/IOSProjectBuildCustomizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuil
2222
string mainTargetGuid = pbxProject.GetUnityMainTargetGuid();
2323

2424
// Get the remote package GUID
25-
string packageGuid = pbxProject.AddRemotePackageReferenceAtVersionUpToNextMajor("https://github.com/bugfender/BugfenderSDK-iOS", "2.0.0");
25+
string packageGuid = pbxProject.AddRemotePackageReferenceAtVersionUpToNextMajor("https://github.com/bugfender/BugfenderSDK-iOS", "2.2.0");
2626

2727
// Add the Remote Package to the Xcode project (both Unity framework and main target)
2828
pbxProject.AddRemotePackageFrameworkToProject(pbxProject.GetUnityFrameworkTargetGuid(), "BugfenderLibrary", packageGuid, false /* required dependency */);
@@ -36,4 +36,4 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuil
3636
// Apply changes to the pbxproj file
3737
pbxProject.WriteToFile(projectPath);
3838
}
39-
}
39+
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ By default, the latest compatible versions are used. If you would like to tweak
3333

3434
## Example project
3535
Check out this project to see Bugfender in action: https://github.com/bugfender/unity-demo
36+
37+
## Testing
38+
See `TESTING.md` for a manual validation checklist for Unity import, Android builds, iOS builds, and runtime verification.

Runtime/Bugfender.cs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using UnityEngine;
1+
using UnityEngine;
22
using System.Runtime.InteropServices;
33
using UnityEngine.Diagnostics;
44

55
public class Bugfender : MonoBehaviour {
6+
private const string SDK_TYPE = "unity";
7+
private const int SDK_TYPE_VERSION = 30000;
68

79
public string APP_KEY;
810
public bool ENABLE_UI_EVENT_LOGGING = false;
@@ -15,9 +17,14 @@ public class Bugfender : MonoBehaviour {
1517

1618
public enum LogLevel { Debug, Warning, Error, Trace, Info, Fatal };
1719

20+
private const int SDK_VERSION = 20260119;
21+
1822
#if UNITY_ANDROID && !UNITY_EDITOR
1923
private static AndroidJavaClass bugfender;
2024
#elif UNITY_IOS && !UNITY_EDITOR
25+
[DllImport ("__Internal")]
26+
private static extern void BugfenderSetSDKType(string sdkType, int version);
27+
2128
[DllImport ("__Internal")]
2229
private static extern void BugfenderActivateLogger(string key, bool printToConsole, bool hideDeviceName, string apiURL, string baseURL);
2330

@@ -59,11 +66,26 @@ public enum LogLevel { Debug, Warning, Error, Trace, Info, Fatal };
5966

6067
[DllImport ("__Internal")]
6168
private static extern void BugfenderForceSendOnce();
69+
70+
[DllImport ("__Internal")]
71+
private static extern void BugfenderSetSDKType(string sdkType, int version);
6272
#endif
6373

6474
// Automatically called when scene starts
6575
void Start()
6676
{
77+
// Optional override from Resources/bugfender_app_key.txt (e.g. for CI or per-build config)
78+
var keyAsset = Resources.Load<TextAsset>("bugfender_app_key");
79+
if (keyAsset != null && !string.IsNullOrWhiteSpace(keyAsset.text))
80+
{
81+
APP_KEY = keyAsset.text.Trim();
82+
}
83+
// Optional: set Resources/bugfender_print_to_console.txt to "true" to mirror logs to logcat (Android) / Xcode console (iOS)
84+
var printAsset = Resources.Load<TextAsset>("bugfender_print_to_console");
85+
if (printAsset != null && string.Equals(printAsset.text.Trim(), "true", System.StringComparison.OrdinalIgnoreCase))
86+
{
87+
PRINT_TO_CONSOLE = true;
88+
}
6789
Debug.Log("[BF] *** INITIALIZING BUGFENDER ***");
6890
#if UNITY_ANDROID && !UNITY_EDITOR
6991
if (bugfender == null) {
@@ -72,6 +94,11 @@ void Start()
7294

7395
bugfender = new AndroidJavaClass ("com.bugfender.sdk.Bugfender");
7496
if (bugfender != null) {
97+
try {
98+
bugfender.CallStatic ("setSDKType", SDK_TYPE, SDK_TYPE_VERSION);
99+
} catch (AndroidJavaException) {
100+
Debug.LogWarning("[BF] Bugfender.setSDKType is not available in the Android SDK.");
101+
}
75102
if(HIDE_DEVICE_NAME) {
76103
bugfender.CallStatic ("overrideDeviceName", "Unknown");
77104
}
@@ -89,12 +116,18 @@ void Start()
89116
if (ENABLE_CRASH_REPORTING) {
90117
bugfender.CallStatic ("enableCrashReporting");
91118
}
119+
// Optional: set Resources/bugfender_debug.txt to "true" to enable native SDK debug logs (tag BF/DEBUG in logcat)
120+
var debugAsset = Resources.Load<TextAsset>("bugfender_debug");
121+
if (debugAsset != null && string.Equals(debugAsset.text.Trim(), "true", System.StringComparison.OrdinalIgnoreCase)) {
122+
try { bugfender.CallStatic("setDebugMode", true); } catch (AndroidJavaException) { /* ignore if not available */ }
123+
}
92124
//bugfender.CallStatic ("enableLogcatLogging"); // optional, uncomment if you want it (Android only)
93125
}
94126

95127
}
96128
}
97129
#elif UNITY_IOS && !UNITY_EDITOR
130+
BugfenderSetSDKType(SDK_TYPE, SDK_TYPE_VERSION);
98131
BugfenderActivateLogger(APP_KEY, PRINT_TO_CONSOLE, HIDE_DEVICE_NAME, API_URL, BASE_URL);
99132
if(ENABLE_UI_EVENT_LOGGING) {
100133
BugfenderEnableUIEventLogging();
@@ -273,4 +306,17 @@ public static void ForceSendOnce()
273306
#endif
274307
}
275308

276-
}
309+
public static void SetSDKType(string sdkType, int version)
310+
{
311+
#if UNITY_ANDROID && !UNITY_EDITOR
312+
if (bugfender != null) {
313+
bugfender.CallStatic ("setSDKType", sdkType, version);
314+
}
315+
#elif UNITY_IOS && !UNITY_EDITOR
316+
BugfenderSetSDKType(sdkType, version);
317+
#else
318+
Debug.Log("[BF] Set SDK type: " + sdkType + " version: " + version);
319+
#endif
320+
}
321+
322+
}

Runtime/Plugins/Android/Bugfender.androidlib.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Plugins/Android/Bugfender.androidlib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ android {
1010
}
1111

1212
dependencies {
13-
implementation 'com.bugfender.sdk:android:3.+'
13+
implementation 'com.bugfender.sdk:android:3.6.2'
1414
}

Runtime/Plugins/iOS/BugfenderBridge.mm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
}
2424

2525
extern "C" {
26+
void BugfenderSetSDKType(const char* sdkType, int version) {
27+
SEL selector = NSSelectorFromString(@"setSDKType:version:");
28+
if ([Bugfender respondsToSelector:selector]) {
29+
typedef void (*SetSDKTypeFunc)(id, SEL, NSString*, int);
30+
SetSDKTypeFunc invoke = (SetSDKTypeFunc)[Bugfender methodForSelector:selector];
31+
invoke((id)[Bugfender class], selector, convertCStringToNSString(sdkType), version);
32+
}
33+
}
34+
2635
void BugfenderActivateLogger(const char* key, bool printToConsole, bool hideDeviceName, const char* apiURL, const char* baseURL) {
2736
NSString* apiURLString = convertCStringToNSString(apiURL);
2837
if(apiURLString.length > 0) {
@@ -95,4 +104,8 @@ void BugfenderForceSendOnce() {
95104
[Bugfender forceSendOnce];
96105
}
97106

107+
void BugfenderSetSDKType(const char* sdkType, int version) {
108+
[Bugfender setSDKType:convertCStringToNSString(sdkType) version:version];
109+
}
110+
98111
}

TESTING.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Testing Bugfender SDK for Unity
2+
3+
This document describes the manual validation flow for the Unity SDK package.
4+
5+
## Test project
6+
7+
Use the sample project at:
8+
9+
`/home/aleix/Projects/bugfender/unity-demo`
10+
11+
To test local package changes, the sample project's package manifest should point to:
12+
13+
`file:../../BugfenderSDK-Unity`
14+
15+
## Unity version
16+
17+
Validate with Unity `6000.3.10f` or the target Unity 6 version under support.
18+
19+
## Import checks
20+
21+
1. Open `/home/aleix/Projects/bugfender/unity-demo` in Unity.
22+
2. Wait for Package Manager and asset import to finish.
23+
3. Confirm the Bugfender package resolves from the local file path.
24+
4. Confirm there are no C# compilation errors.
25+
5. Confirm there are no Android plugin import errors for `Bugfender.androidlib`.
26+
6. Confirm there are no iOS plugin compilation issues for `BugfenderBridge.mm`.
27+
28+
## Android build checks
29+
30+
1. Switch the active platform to Android.
31+
2. Build the sample project.
32+
3. If the build fails, capture the first Gradle error block.
33+
34+
Expected result:
35+
36+
- No `Could not find com.bugfender.sdk:android` errors.
37+
- No `ClassNotFoundException` or `cannot find symbol` errors for `com.bugfender.sdk.Bugfender`.
38+
- No missing module or `Project with path` errors involving `Bugfender.androidlib`.
39+
40+
## iOS build checks
41+
42+
1. Switch the active platform to iOS.
43+
2. Build the Xcode project from Unity.
44+
3. Open the generated Xcode project and build it.
45+
46+
Expected result:
47+
48+
- Swift Package Manager resolves `BugfenderSDK-iOS`.
49+
- No compile or link errors for `Bugfender`.
50+
- No selector or symbol errors related to `setSDKType:version:`.
51+
52+
## Runtime checks
53+
54+
1. Set a valid Bugfender app key in the sample scene.
55+
2. Run the app on a device or simulator.
56+
3. Confirm startup completes without crashing.
57+
4. Confirm Bugfender initializes successfully.
58+
5. Send a test log and verify it appears in Bugfender.
59+
60+
## What to capture on failure
61+
62+
When reporting a failure, include:
63+
64+
- Unity version
65+
- Target platform
66+
- Whether the failure happens during import, build, or runtime
67+
- The first relevant error block from Unity Console, Gradle, or Xcode

TESTING.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.bugfender.unity",
3-
"version": "2.0.2",
3+
"version": "3.0.0",
44
"displayName": "Bugfender",
55
"description": "Unity bindings for the native Bugfender iOS and Android SDKs",
66
"unity": "2022.3",

0 commit comments

Comments
 (0)