Skip to content

Commit ef7a6b8

Browse files
authored
fix(ios): resolve swift6 IRGen compile crash (#717)
## Fixes - finalize HybridSound and conform via base+protocol; avoid RecordBackType interpolation to prevent Swift 6 IRGen recursion - enable BUILD_LIBRARY_FOR_DISTRIBUTION and wholemodule in podspec for stability - silence iOS logs in Release; add Android debug-only Logger for future use Closes #715 Closes #716 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - No user-facing features added. - Refactor - Centralized Android logging and reduced log noise in release builds. - Adjusted iOS logging to avoid verbose output in production. - Minor logging format tweaks during recording for improved reliability. - Chores - Updated iOS build settings to improve distribution readiness and compilation behavior. - Notes - Expect quieter release logs on both platforms and improved stability during recording scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent f150a65 commit ef7a6b8

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,17 @@ array.forEach((e) => {
9797

9898
- Space before `(` and after `)`.
9999
- **If you find code that does not fit in the coding convention, do not ever try to fix code that is not related to your purpose.**
100+
101+
### Logging
102+
103+
Use the following module-provided logging approaches during development. Both are silent in Release/production builds.
104+
105+
- iOS
106+
- Preferred: call `print(...)` as usual inside this module. We provide `ios/Logging.swift` which overrides `print` only in non-DEBUG builds, so all prints are automatically suppressed in Release while remaining visible in Debug.
107+
- Scope: this override affects only this module’s sources; it does not change app-level logging.
108+
109+
- Android
110+
- Preferred: use `Logger` helper instead of `Log.*`.
111+
- File: `android/src/main/java/com/margelo/nitro/audiorecorderplayer/Logger.kt`
112+
- APIs: `Logger.d(...)`, `Logger.i(...)`, `Logger.w(...)`, `Logger.e(...)`
113+
- Behavior: internally gated by `BuildConfig.DEBUG`, so logs print in Debug and are silent in Release. Avoid using `Log.*` directly to keep Release builds quiet.

NitroSound.podspec

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ Pod::Spec.new do |s|
2828
s.pod_target_xcconfig = {
2929
"SWIFT_VERSION" => "5.0",
3030
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited)",
31+
# Enable library evolution to avoid certain Swift 6 IRGen issues
32+
"BUILD_LIBRARY_FOR_DISTRIBUTION" => "YES",
33+
"DEFINES_MODULE" => "YES",
34+
# Favor whole-module to avoid per-file IRGen edge-cases
35+
"SWIFT_COMPILATION_MODE" => "wholemodule",
3136
"HEADER_SEARCH_PATHS" => "$(inherited) ${PODS_ROOT}/RCT-Folly",
3237
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_MOBILE=1 FOLLY_USE_LIBCPP=1 FOLLY_CFG_NO_COROUTINES",
3338
"OTHER_CPLUSPLUSFLAGS" => "$(inherited) #{folly_compiler_flags}",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.margelo.nitro.audiorecorderplayer
2+
3+
import android.util.Log
4+
import com.margelo.nitro.sound.BuildConfig
5+
6+
/**
7+
* Simple logger that only logs in Debug builds.
8+
* Use Logger.d/i/w/e instead of Log.* to avoid logcat noise in Release.
9+
*/
10+
object Logger {
11+
private const val TAG = "NitroSound"
12+
13+
@JvmStatic fun d(message: String, tr: Throwable? = null) {
14+
log(Log.DEBUG, message, tr)
15+
}
16+
17+
@JvmStatic fun i(message: String, tr: Throwable? = null) {
18+
log(Log.INFO, message, tr)
19+
}
20+
21+
@JvmStatic fun w(message: String, tr: Throwable? = null) {
22+
log(Log.WARN, message, tr)
23+
}
24+
25+
@JvmStatic fun e(message: String, tr: Throwable? = null) {
26+
log(Log.ERROR, message, tr)
27+
}
28+
29+
private fun log(priority: Int, message: String, tr: Throwable?) {
30+
if (!BuildConfig.DEBUG) return
31+
val fullMessage = if (tr != null) {
32+
"$message\n${'$'}{Log.getStackTraceString(tr)}"
33+
} else message
34+
Log.println(priority, TAG, fullMessage)
35+
}
36+
}

ios/Logging.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Suppress console logs in production (Release) builds only for this module
2+
#if !DEBUG
3+
@inline(__always)
4+
func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {}
5+
#endif
6+

ios/Sound.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import AVFoundation
33
import NitroModules
44

5-
class HybridSound: HybridSoundSpec {
5+
final class HybridSound: HybridSoundSpec_base, HybridSoundSpec_protocol {
66
// Small delay to ensure the audio session is fully active before recording starts
77
private let audioSessionActivationDelay: TimeInterval = 0.1
88
private var audioRecorder: AVAudioRecorder?
@@ -841,7 +841,8 @@ class HybridSound: HybridSoundSpec {
841841
recordSecs: currentTime
842842
)
843843

844-
print("🎙️ Timer callback: calling recordBackListener with data: \(recordBack)")
844+
// Avoid interpolating RecordBackType directly to prevent Swift IRGen issues on Swift 6
845+
print("🎙️ Timer callback: calling recordBackListener (time=\(currentTime)ms, metering=\(currentMetering))")
845846

846847
if let listener = self.recordBackListener {
847848
print("🎙️ Timer callback: recordBackListener exists, calling it")

0 commit comments

Comments
 (0)