Skip to content

Commit 2dd4bba

Browse files
authored
Merge pull request #13 from bugfender/develop
Develop
2 parents 5315788 + 2790035 commit 2dd4bba

8 files changed

Lines changed: 175 additions & 73 deletions

File tree

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Changelog
2+
3+
All notable changes to this project are documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6+
7+
## [3.0.1]
8+
9+
### Added
10+
11+
- `Bugfender.EnableNativeLogCapture()` — forward native system logs to Bugfender (**Android:** logcat; **iOS 15+:** NSLog/OSLog).
12+
- `Resources/bugfender_native_log_capture.txt` — set to `true` to enable native log capture during initialization (same behavior as the API above).
13+
- Optional overrides using text files under `Assets/Resources/` (see [docs](https://docs.bugfender.com/docs/platforms/hybrid-platforms/bugfender-for-unity)), including `bugfender_app_key.txt` (one-line app key; useful for CI or per-build config). If a file is missing or empty, Inspector values apply where applicable.
14+
15+
### Fixed
16+
17+
- iOS Simulator build error with recent Xcode versions.
18+
19+
### Changed
20+
21+
- SDK reports type `unity` and build version `30001` to the Bugfender backend when initializing, so sessions and devices can be identified as Unity SDK traffic.
22+
23+
### Compatibility
24+
25+
- **Unity:** 2022.3 or later (including Unity 6). Tested with Unity 6000.3.11f1.
26+
- **iOS:** Xcode 15+; iOS Simulator.
27+
- **Android:** ARM64 devices.
28+
29+
### Documentation
30+
31+
- [Bugfender for Unity](https://docs.bugfender.com/docs/platforms/hybrid-platforms/bugfender-for-unity)
32+
- [GitHub Releases](https://github.com/bugfender/BugfenderSDK-Unity/releases)
33+
34+
### Installation
35+
36+
See [README.md](README.md). Quick UPM (git URL): `https://github.com/bugfender/BugfenderSDK-Unity.git` — optional pin: `#v3.0.1`.
37+
38+
[Unreleased]: https://github.com/bugfender/BugfenderSDK-Unity/compare/v3.0.1...HEAD
39+
[3.0.1]: https://github.com/bugfender/BugfenderSDK-Unity/releases/tag/v3.0.1

CHANGELOG.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.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ By default, the latest compatible versions are used. If you would like to tweak
3131
* For iOS: `Editor/IOSProjectBuildCustomizer.cs`
3232
* For Android: `Runtime/Plugins/Android/Bugfender.androidlib/build.gradle`
3333

34+
## Changelog
35+
36+
See [CHANGELOG.md](CHANGELOG.md) for version history.
37+
3438
## Example project
3539
Check out this project to see Bugfender in action: https://github.com/bugfender/unity-demo
3640

Runtime/Bugfender.cs

Lines changed: 50 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using UnityEngine;
2-
using System.Runtime.InteropServices;
32
using UnityEngine.Diagnostics;
43

54
public class Bugfender : MonoBehaviour {
65
private const string SDK_TYPE = "unity";
7-
private const int SDK_TYPE_VERSION = 30000;
6+
private const int SDK_TYPE_VERSION = 30001;
87

98
public string APP_KEY;
109
public bool ENABLE_UI_EVENT_LOGGING = false;
@@ -17,58 +16,19 @@ public class Bugfender : MonoBehaviour {
1716

1817
public enum LogLevel { Debug, Warning, Error, Trace, Info, Fatal };
1918

20-
private const int SDK_VERSION = 20260119;
19+
private static bool BugfenderResourceFlagTrue(string resourceName)
20+
{
21+
var asset = Resources.Load<TextAsset>(resourceName);
22+
return asset != null && string.Equals(asset.text.Trim(), "true", System.StringComparison.OrdinalIgnoreCase);
23+
}
24+
25+
private static bool ResourcesWantNativeLogCapture()
26+
{
27+
return BugfenderResourceFlagTrue("bugfender_native_log_capture");
28+
}
2129

2230
#if UNITY_ANDROID && !UNITY_EDITOR
2331
private static AndroidJavaClass bugfender;
24-
#elif UNITY_IOS && !UNITY_EDITOR
25-
[DllImport ("__Internal")]
26-
private static extern void BugfenderSetSDKType(string sdkType, int version);
27-
28-
[DllImport ("__Internal")]
29-
private static extern void BugfenderActivateLogger(string key, bool printToConsole, bool hideDeviceName, string apiURL, string baseURL);
30-
31-
[DllImport ("__Internal")]
32-
private static extern void BugfenderEnableUIEventLogging();
33-
34-
[DllImport ("__Internal")]
35-
private static extern void BugfenderEnableCrashReporting();
36-
37-
[DllImport ("__Internal")]
38-
private static extern void BugfenderSetDeviceString(string key, string value);
39-
40-
[DllImport ("__Internal")]
41-
private static extern void BugfenderRemoveDeviceKey(string key);
42-
43-
[DllImport ("__Internal")]
44-
private static extern void BugfenderLog(int logLevel, string tag, string message);
45-
46-
[DllImport ("__Internal")]
47-
private static extern string BugfenderSendCrash(string title, string text);
48-
49-
[DllImport ("__Internal")]
50-
private static extern string BugfenderSendIssue(string title, string markdown);
51-
52-
[DllImport ("__Internal")]
53-
private static extern string BugfenderSendUserFeedback(string subject, string message);
54-
55-
[DllImport ("__Internal")]
56-
private static extern void BugfenderSetMaximumLocalStorageSize(ulong maximumLocalStorageSizeBytes);
57-
58-
[DllImport ("__Internal")]
59-
private static extern string BugfenderGetDeviceIdentifierUrl();
60-
61-
[DllImport ("__Internal")]
62-
private static extern string BugfenderGetSessionIdentifierUrl();
63-
64-
[DllImport ("__Internal")]
65-
private static extern void BugfenderSetForceEnabled(bool enabled);
66-
67-
[DllImport ("__Internal")]
68-
private static extern void BugfenderForceSendOnce();
69-
70-
[DllImport ("__Internal")]
71-
private static extern void BugfenderSetSDKType(string sdkType, int version);
7232
#endif
7333

7434
// Automatically called when scene starts
@@ -121,19 +81,24 @@ void Start()
12181
if (debugAsset != null && string.Equals(debugAsset.text.Trim(), "true", System.StringComparison.OrdinalIgnoreCase)) {
12282
try { bugfender.CallStatic("setDebugMode", true); } catch (AndroidJavaException) { /* ignore if not available */ }
12383
}
124-
//bugfender.CallStatic ("enableLogcatLogging"); // optional, uncomment if you want it (Android only)
84+
if (ResourcesWantNativeLogCapture()) {
85+
try { bugfender.CallStatic("enableLogcatLogging"); } catch (AndroidJavaException) { }
86+
}
12587
}
12688

12789
}
12890
}
12991
#elif UNITY_IOS && !UNITY_EDITOR
130-
BugfenderSetSDKType(SDK_TYPE, SDK_TYPE_VERSION);
131-
BugfenderActivateLogger(APP_KEY, PRINT_TO_CONSOLE, HIDE_DEVICE_NAME, API_URL, BASE_URL);
92+
BugfenderNativeIos.SetSDKType(SDK_TYPE, SDK_TYPE_VERSION);
93+
BugfenderNativeIos.ActivateLogger(APP_KEY, PRINT_TO_CONSOLE, HIDE_DEVICE_NAME, API_URL, BASE_URL);
13294
if(ENABLE_UI_EVENT_LOGGING) {
133-
BugfenderEnableUIEventLogging();
95+
BugfenderNativeIos.EnableUIEventLogging();
13496
}
13597
if (ENABLE_CRASH_REPORTING) {
136-
BugfenderEnableCrashReporting();
98+
BugfenderNativeIos.EnableCrashReporting();
99+
}
100+
if (ResourcesWantNativeLogCapture()) {
101+
BugfenderNativeIos.EnableNSLogLogging();
137102
}
138103
#endif
139104
/* Some examples on how to use Bugfender:
@@ -153,7 +118,7 @@ public static void SetDeviceString(string key, string value)
153118
bugfender.CallStatic ("setDeviceString", key, value);
154119
}
155120
#elif UNITY_IOS && !UNITY_EDITOR
156-
BugfenderSetDeviceString(key, value);
121+
BugfenderNativeIos.SetDeviceString(key, value);
157122
#else
158123
Debug.Log("[BF] Set device key:" + key + " value:" + value);
159124
#endif
@@ -166,12 +131,29 @@ public static void RemoveDeviceKey(string key)
166131
bugfender.CallStatic ("removeDeviceKey", key);
167132
}
168133
#elif UNITY_IOS && !UNITY_EDITOR
169-
BugfenderRemoveDeviceKey(key);
134+
BugfenderNativeIos.RemoveDeviceKey(key);
170135
#else
171136
Debug.Log("[BF] Remove device key: " + key);
172137
#endif
173138
}
174139

140+
/// <summary>
141+
/// Enables native system log capture for the current platform (Android logcat; iOS 15+ NSLog/OSLog).
142+
/// Call after the Bugfender component has initialized, or add <c>Assets/Resources/bugfender_native_log_capture.txt</c> with <c>true</c>.
143+
/// </summary>
144+
public static void EnableNativeLogCapture()
145+
{
146+
#if UNITY_ANDROID && !UNITY_EDITOR
147+
if (bugfender != null) {
148+
try { bugfender.CallStatic("enableLogcatLogging"); } catch (AndroidJavaException) { }
149+
}
150+
#elif UNITY_IOS && !UNITY_EDITOR
151+
BugfenderNativeIos.EnableNSLogLogging();
152+
#else
153+
Debug.Log("[BF] EnableNativeLogCapture is for Android or iOS device builds only.");
154+
#endif
155+
}
156+
175157
public static void Log(string message)
176158
{
177159
Log(LogLevel.Debug, "", message);
@@ -187,7 +169,7 @@ public static void Log(LogLevel logLevel, string tag, string message)
187169
}
188170
#elif UNITY_IOS && !UNITY_EDITOR
189171
int intLevel = (int)logLevel;
190-
BugfenderLog(intLevel, tag, message);
172+
BugfenderNativeIos.Log(intLevel, tag, message);
191173
#else
192174
Debug.Log("[BF] Sending log to Bugfender: [" + logLevel + "][" + tag + "] " + message);
193175
#endif
@@ -201,7 +183,7 @@ public static string SendCrash(string title, string text) {
201183
}
202184
return null;
203185
#elif UNITY_IOS && !UNITY_EDITOR
204-
return BugfenderSendCrash(title, text);
186+
return BugfenderNativeIos.SendCrash(title, text);
205187
#else
206188
Debug.Log("[BF] Send crash: " + title + " : " + text);
207189
return null;
@@ -216,7 +198,7 @@ public static string SendIssue(string title, string text) {
216198
}
217199
return null;
218200
#elif UNITY_IOS && !UNITY_EDITOR
219-
return BugfenderSendIssue(title, text);
201+
return BugfenderNativeIos.SendIssue(title, text);
220202
#else
221203
Debug.Log("[BF] Send issue: " + title + " : " + text);
222204
return null;
@@ -231,7 +213,7 @@ public static string SendUserFeedback(string subject, string message) {
231213
}
232214
return null;
233215
#elif UNITY_IOS && !UNITY_EDITOR
234-
return BugfenderSendUserFeedback(subject, message);
216+
return BugfenderNativeIos.SendUserFeedback(subject, message);
235217
#else
236218
Debug.Log("[BF] Send user feedback: " + subject + " : " + message);
237219
return null;
@@ -246,7 +228,7 @@ public static void SetMaximumLocalStorageSize(ulong bytes)
246228
bugfender.CallStatic ("setMaximumLocalStorageSize", b);
247229
}
248230
#elif UNITY_IOS && !UNITY_EDITOR
249-
BugfenderSetMaximumLocalStorageSize(bytes);
231+
BugfenderNativeIos.SetMaximumLocalStorageSize(bytes);
250232
#else
251233
Debug.Log("[BF] Set max storage size:" + bytes);
252234
#endif
@@ -260,7 +242,7 @@ public static string DeviceIdentifierUrl() {
260242
}
261243
return null;
262244
#elif UNITY_IOS && !UNITY_EDITOR
263-
return BugfenderGetDeviceIdentifierUrl();
245+
return BugfenderNativeIos.GetDeviceIdentifierUrl();
264246
#else
265247
return null;
266248
#endif
@@ -274,7 +256,7 @@ public static string SessionIdentifierUrl() {
274256
}
275257
return null;
276258
#elif UNITY_IOS && !UNITY_EDITOR
277-
return BugfenderGetSessionIdentifierUrl();
259+
return BugfenderNativeIos.GetSessionIdentifierUrl();
278260
#else
279261
return null;
280262
#endif
@@ -287,7 +269,7 @@ public static void SetForceEnabled(bool enabled)
287269
bugfender.CallStatic ("setForceEnabled", enabled);
288270
}
289271
#elif UNITY_IOS && !UNITY_EDITOR
290-
BugfenderSetForceEnabled(enabled);
272+
BugfenderNativeIos.SetForceEnabled(enabled);
291273
#else
292274
Debug.Log("[BF] Set force enabled:" + enabled);
293275
#endif
@@ -300,7 +282,7 @@ public static void ForceSendOnce()
300282
bugfender.CallStatic ("forceSendOnce");
301283
}
302284
#elif UNITY_IOS && !UNITY_EDITOR
303-
BugfenderForceSendOnce();
285+
BugfenderNativeIos.ForceSendOnce();
304286
#else
305287
Debug.Log("[BF] Force send once");
306288
#endif
@@ -313,7 +295,7 @@ public static void SetSDKType(string sdkType, int version)
313295
bugfender.CallStatic ("setSDKType", sdkType, version);
314296
}
315297
#elif UNITY_IOS && !UNITY_EDITOR
316-
BugfenderSetSDKType(sdkType, version);
298+
BugfenderNativeIos.SetSDKType(sdkType, version);
317299
#else
318300
Debug.Log("[BF] Set SDK type: " + sdkType + " version: " + version);
319301
#endif

Runtime/BugfenderNativeIos.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#if UNITY_IOS && !UNITY_EDITOR
2+
using System.Runtime.InteropServices;
3+
4+
/// <summary>
5+
/// iOS native entry points (BugfenderBridge.mm). Kept in a separate type to avoid duplicate P/Invoke declarations on <see cref="Bugfender"/>.
6+
/// </summary>
7+
internal static class BugfenderNativeIos
8+
{
9+
[DllImport("__Internal", EntryPoint = "BugfenderSetSDKType")]
10+
internal static extern void SetSDKType(string sdkType, int version);
11+
12+
[DllImport("__Internal", EntryPoint = "BugfenderActivateLogger")]
13+
internal static extern void ActivateLogger(string key, bool printToConsole, bool hideDeviceName, string apiURL, string baseURL);
14+
15+
[DllImport("__Internal", EntryPoint = "BugfenderEnableUIEventLogging")]
16+
internal static extern void EnableUIEventLogging();
17+
18+
[DllImport("__Internal", EntryPoint = "BugfenderEnableCrashReporting")]
19+
internal static extern void EnableCrashReporting();
20+
21+
[DllImport("__Internal", EntryPoint = "BugfenderEnableNSLogLogging")]
22+
internal static extern void EnableNSLogLogging();
23+
24+
[DllImport("__Internal", EntryPoint = "BugfenderSetDeviceString")]
25+
internal static extern void SetDeviceString(string key, string value);
26+
27+
[DllImport("__Internal", EntryPoint = "BugfenderRemoveDeviceKey")]
28+
internal static extern void RemoveDeviceKey(string key);
29+
30+
[DllImport("__Internal", EntryPoint = "BugfenderLog")]
31+
internal static extern void Log(int logLevel, string tag, string message);
32+
33+
[DllImport("__Internal", EntryPoint = "BugfenderSendCrash")]
34+
internal static extern string SendCrash(string title, string text);
35+
36+
[DllImport("__Internal", EntryPoint = "BugfenderSendIssue")]
37+
internal static extern string SendIssue(string title, string markdown);
38+
39+
[DllImport("__Internal", EntryPoint = "BugfenderSendUserFeedback")]
40+
internal static extern string SendUserFeedback(string subject, string message);
41+
42+
[DllImport("__Internal", EntryPoint = "BugfenderSetMaximumLocalStorageSize")]
43+
internal static extern void SetMaximumLocalStorageSize(ulong maximumLocalStorageSizeBytes);
44+
45+
[DllImport("__Internal", EntryPoint = "BugfenderGetDeviceIdentifierUrl")]
46+
internal static extern string GetDeviceIdentifierUrl();
47+
48+
[DllImport("__Internal", EntryPoint = "BugfenderGetSessionIdentifierUrl")]
49+
internal static extern string GetSessionIdentifierUrl();
50+
51+
[DllImport("__Internal", EntryPoint = "BugfenderSetForceEnabled")]
52+
internal static extern void SetForceEnabled(bool enabled);
53+
54+
[DllImport("__Internal", EntryPoint = "BugfenderForceSendOnce")]
55+
internal static extern void ForceSendOnce();
56+
}
57+
#endif

Runtime/BugfenderNativeIos.cs.meta

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

Runtime/Plugins/iOS/BugfenderBridge.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ void BugfenderEnableCrashReporting() {
5555
[Bugfender enableCrashReporting];
5656
}
5757

58+
void BugfenderEnableNSLogLogging(void) {
59+
if (@available(iOS 15.0, *)) {
60+
[Bugfender enableNSLogLogging];
61+
}
62+
}
63+
5864
void BugfenderSetDeviceString(const char* key, const char* value) {
5965
[Bugfender setDeviceString:convertCStringToNSString(value) forKey:convertCStringToNSString(key)];
6066
}
@@ -104,8 +110,4 @@ void BugfenderForceSendOnce() {
104110
[Bugfender forceSendOnce];
105111
}
106112

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

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": "3.0.0",
3+
"version": "3.0.1",
44
"displayName": "Bugfender",
55
"description": "Unity bindings for the native Bugfender iOS and Android SDKs",
66
"unity": "2022.3",

0 commit comments

Comments
 (0)