Closed AnalogDevelop closed 1 week ago
Happens to me also
Unfortunately, nobody in the team can replicate this.
You can try to add this code to line 120 in file CorkApp
:
demoActivatedAt = nil
@buresdv , I tried your tip (I hope I didn't make any mistakes), but it didn't work either.
Does anyone have any more ideas on how to solve this issue, please? Thanks for your time!
Sonoma 14.5 (23F79) Xcode 15.4 (15F31d)
Here are some images:
Can you post the output of the Xcode console?
Here is the build log for release 1.4.4.2(74): Build Self-Compiled_2024-08-20T10-58-06.txt
I also tried to compile the v1.4.4.2(76) (up to commit 407f2ed4c94521d947c9d7f765cad58ed5f5cd48) without your tip @buresdv, asking for the licence too. Here is the build log: Build Self-Compiled_2024-08-21T11-59-45.txt
v1.4.4.2(76) (up to commit 407f2ed4c94521d947c9d7f765cad58ed5f5cd48) with your tip @buresdv, gave the same problem. Here is the build log: Build Self-Compiled_2024-08-21T12-18-56.txt
same here
I'm still unfortunately still unable to reproduce this problem. I suspect it might be some edge case regarding Tuist.
Could you please add this code to line 200
in the file ContentView.swift
?
print("Process environment: \(ProcessInfo.processInfo.environment)")
It will print the process environment. This environment has info about the flag that sets the self compiled state. Could you make sure this is included in the Xcode console logs?
@MarFre22 thanks for the logs! Could you also send me the logs from the Xcode console itself? Those that show up here when you build
@MarFre22 @lpgneg19 @OliverRhyme In the meantime, feel free to use this pre-compiled build. It would also be really helpful if you got in touch with me through Discord?
I'm still unfortunately still unable to reproduce this problem. I suspect it might be some edge case regarding Tuist.
Could you please add this code to line
200
in the fileContentView.swift
?print("Process environment: \(ProcessInfo.processInfo.environment)")
It will print the process environment. This environment has info about the flag that sets the self compiled state. Could you make sure this is included in the Xcode console logs?
@MarFre22 thanks for the logs! Could you also send me the logs from the Xcode console itself? Those that show up here when you build
@MarFre22 @lpgneg19 @OliverRhyme In the meantime, feel free to use this pre-compiled build. It would also be really helpful if you got in touch with me through Discord?
the pre compiled build you linked still has the license checking
Same here, @OliverRhyme
@buresdv , I tried the latest commit 85191bb, it's interesting to see that the archived version asks for the licence, but the version started in Xcode (debug mode) does not.
Here is the debug log with "Process environment": Xcode console log.txt
@MarFre22 thanks for the logs. The scheme is working correctly, but I suppose something got screwed up at some point and the internal state of the licensing is wrong.
Pull the current state of main
. Switch the scheme to Debug
, run Cork, and use the following action: DEBUG → DEBUG: Licensing → DEBUG: Reset licensing state
.
They rebuild with the correct scheme (Self-compiled
).
In my testing, that solved any licensing issues I could think of
@MarFre22 thanks for the logs. The scheme is working correctly, but I suppose something got screwed up at some point and the internal state of the licensing is wrong.
Pull the current state of
main
. Switch the scheme toDebug
, run Cork, and use the following action:DEBUG → DEBUG: Licensing → DEBUG: Reset licensing state
.They rebuild with the correct scheme (
Self-compiled
).In my testing, that solved any licensing issues I could think of
I've tried this workaround and if I run Cork through Xcode, I get the message that I self-compiled. If I archive with the self-compiled scheme the app continues to run in Demo Mode.
@mvicari I'm not saying this is your fault (definitely isn't), but your situation seems impossible. It seems like an Xcode error, and I have never heard of anyone encountering this.
I'd report this to Apple
I've uploaded a video demonstrating what I'm describing. I've attempted all fixes described in this thread:
https://github.com/user-attachments/assets/a924322b-cbe1-469d-b206-103b7b2a35dc
Cork 1.4.4.2 (77) macOS 14.6.1 (23G93) Xcode 15.4 (15F31d) tuist 4.25.0
I should mention this is a continuation of the issue mentioned here: https://github.com/buresdv/Cork/issues/275#issuecomment-2278950397
I think I've found a solution:
The problem stemmed from relying on an environment variable (SELF_COMPILED
) to determine whether the app was self-compiled. Environment variables set in Xcode for a particular scheme may not persist or be correctly recognized when the app is archived and distributed, leading to unexpected behavior.
To resolve this, I switched from using an environment variable to a compiler flag (-DSELF_COMPILED
). Compiler flags are embedded directly into the compiled binary, ensuring the check is consistent regardless of the environment in which the app is running.
Add a Compiler Flag:
In Xcode, go to Product > Scheme > Edit Scheme and navigate to the Build Settings:
SELF_COMPILED
.-DSELF_COMPILED
Update the Code to Use Compiler Directives:
Replace the environment variable check in CorkApp.swift with the following compiler directive in the code around line 121:
.onAppear
{
#if SELF_COMPILED
AppConstants.logger.debug("Will set licensing state to Self Compiled")
appDelegate.appState.licensingState = .selfCompiled
#else
if !hasValidatedEmail
{
if appDelegate.appState.licensingState != .selfCompiled
{
if let demoActivatedAt
{
let timeDemoWillRunOutAt: Date = demoActivatedAt + AppConstants.demoLengthInSeconds
AppConstants.logger.debug("There is \(demoActivatedAt.timeIntervalSinceNow.formatted()) to go on the demo")
AppConstants.logger.debug("Demo will time out at \(timeDemoWillRunOutAt.formatted(date: .complete, time: .complete))")
if ((demoActivatedAt.timeIntervalSinceNow) + AppConstants.demoLengthInSeconds) > 0
{
// Continue with demo mode
}
else
{
// Handle demo timeout
}
}
}
}
#endif
}
Verify the Correct Behavior:
After making these changes:
licensingState
is set to .selfCompiled
and the app does not revert to demo mode.After implementing the above changes, the app correctly recognized the self-compiled status when archived and run outside the development environment. This approach eliminates dependency on environment variables, which may not always be reliable in different runtime contexts.
I think I've found a solution:
Root Cause
The problem stemmed from relying on an environment variable (
SELF_COMPILED
) to determine whether the app was self-compiled. Environment variables set in Xcode for a particular scheme may not persist or be correctly recognized when the app is archived and distributed, leading to unexpected behavior.Solution: Use Compiler Flags Instead of Environment Variables
To resolve this, I switched from using an environment variable to a compiler flag (
-DSELF_COMPILED
). Compiler flags are embedded directly into the compiled binary, ensuring the check is consistent regardless of the environment in which the app is running.Implementation Steps
Add a Compiler Flag: In Xcode, go to Product > Scheme > Edit Scheme and navigate to the Build Settings:
- Under Run, select the Arguments tab.
- Remove any environment variables related to
SELF_COMPILED
.- Instead, add a Swift Compiler Flag under Build Settings > Other Swift Flags:
-DSELF_COMPILED
Update the Code to Use Compiler Directives: Replace the environment variable check in CorkApp.swift with the following compiler directive in the code around line 121:
.onAppear { #if SELF_COMPILED AppConstants.logger.debug("Will set licensing state to Self Compiled") appDelegate.appState.licensingState = .selfCompiled #else if !hasValidatedEmail { if appDelegate.appState.licensingState != .selfCompiled { if let demoActivatedAt { let timeDemoWillRunOutAt: Date = demoActivatedAt + AppConstants.demoLengthInSeconds AppConstants.logger.debug("There is \(demoActivatedAt.timeIntervalSinceNow.formatted()) to go on the demo") AppConstants.logger.debug("Demo will time out at \(timeDemoWillRunOutAt.formatted(date: .complete, time: .complete))") if ((demoActivatedAt.timeIntervalSinceNow) + AppConstants.demoLengthInSeconds) > 0 { // Continue with demo mode } else { // Handle demo timeout } } } } #endif }
Verify the Correct Behavior: After making these changes:
- Archive the app and run it locally to test if it correctly recognizes the self-compiled mode.
- Verify that the
licensingState
is set to.selfCompiled
and the app does not revert to demo mode.Outcome
After implementing the above changes, the app correctly recognized the self-compiled status when archived and run outside the development environment. This approach eliminates dependency on environment variables, which may not always be reliable in different runtime contexts.
Can you open a pull request?
@mvicari thank you for the detailed response, but this solution would not work for Tuist. If you set it that way, it will only work for your generated Xcode project that's only on your machine.
Your solution was the original solution that's been implemented a few months ago along with the licensing system, but during the migration to Tuist, it had to be changed to the Environment variable, as recommended by the Tuist developers.
Check out this permalink for an older version: https://github.com/buresdv/Cork/blob/50f728087511cf0c5522db354d140e66a37203a4/Cork/CorkApp.swift#L122
So please don't do a PR
@OliverRhyme
Someone finally managed to reproduce this issue, so we're looking into it
Try the branch main.scheme-adjustments
. The new scheme is called Cork-SelfCompiled
Try the branch
main.scheme-adjustments
. The new scheme is calledCork-SelfCompiled
Ran git clone --branch main.scheme-adjustments --single-branch https://github.com/buresdv/Cork && cd Cork && tuist install && tuist generate --no-binary-cache
, then followed the self-compiled instructions like normal, and it successfully compiled with the proper scheme.
Perfect. I'm glad I managed to fix it this fast after finally reproducing it. For the time being, I wil consider this issue resolved.
Still having the issue, there is no main.scheme-adjustments branch
Still having the issue, there is no main.scheme-adjustments branch
I believe you can return to the main branch. Follow the build instructions in the readme and select the Cork-SelfCompiled scheme.
@fpatrick That branch was merged into main
, so now you can use the main
branch
What were you trying to do?
Attempting to compile v1.4.4.2 from source and selected the Self-Compile scheme
What was the problem?
The application still expects license verification.
Error logs
No response
App Version
1.4.4.2
App Acquisition
Self-Compiled
Final checklist