Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle fail to compile from Android Studio when making a release or with skip export #180

Open
macshodan opened this issue Jul 27, 2024 · 10 comments
Assignees

Comments

@macshodan
Copy link

Hi, I'm struggling to create an APK of the App without debug symbols to run on devices.

I've the latest version of skip (0.10.6) and I've created a new project from scratch. I can run it from Xcode just fine on both the iOS simulator and the Android simulator, but when I try to use skip export or directly Android Studio (2024.1 version) for either debug on Android or create an Apk the gradle build fails with the following errors:

[13/16] Skip NsgMobile
[14/16] Copying .NsgMobile.sourcehash
[16/20] Compiling NsgMobile RepairView.swift
/Users/simo/Developer/Consulting/nsgApp/Sources/NsgMobile/Repair/RepairView.swift:196:10: error: 'navigationBarTitleDisplayMode' is unavailable in macOS
        .navigationBarTitleDisplayMode(.inline)
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SwiftUI.View:5:17: note: 'navigationBarTitleDisplayMode' has been explicitly marked unavailable here
    public func navigationBarTitleDisplayMode(_ displayMode: NavigationBarItem.TitleDisplayMode) -> some View
                ^
[17/20] Compiling NsgMobile CalendarView.swift
/Users/simo/Developer/Consulting/nsgApp/Sources/NsgMobile/Calendar/CalendarView.swift:136:14: error: 'navigationBarTitleDisplayMode' is unavailable in macOS
            .navigationBarTitleDisplayMode(.inline)
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SwiftUI.View:5:17: note: 'navigationBarTitleDisplayMode' has been explicitly marked unavailable here
    public func navigationBarTitleDisplayMode(_ displayMode: NavigationBarItem.TitleDisplayMode) -> some View
                ^
/Users/simo/Developer/Consulting/nsgApp/Sources/NsgMobile/Calendar/CalendarView.swift:137:14: error: 'fullScreenCover(isPresented:onDismiss:content:)' is unavailable in macOS
            .fullScreenCover(isPresented: $showSelectedDayEvents, onDismiss: {
             ^~~~~~~~~~~~~~~
SwiftUI.View:9:17: note: 'fullScreenCover(isPresented:onDismiss:content:)' has been explicitly marked unavailable here
    public func fullScreenCover<Content>(isPresented: Binding<Bool>, onDismiss: (() -> Void)? = nil, @ViewBuilder content: @escaping () -> Content) -> some View where Content : View
                ^
[18/20] Emitting module NsgMobile
[19/20] Compiling NsgMobile DayEventsList.swift
/Users/simo/Developer/Consulting/nsgApp/Sources/NsgMobile/Calendar/DayEventsList.swift:49:14: error: 'navigationBarTitleDisplayMode' is unavailable in macOS
            .navigationBarTitleDisplayMode(.inline)
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SwiftUI.View:5:17: note: 'navigationBarTitleDisplayMode' has been explicitly marked unavailable here
    public func navigationBarTitleDisplayMode(_ displayMode: NavigationBarItem.TitleDisplayMode) -> some View
                ^
error: fatalError

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/simo/Developer/Consulting/nsgApp/Android/settings.gradle.kts' line: 18

* What went wrong:
Process 'command 'swift'' finished with non-zero exit value 1

It seems that for example the view property .navigationBartTitleDisplayMode isn't supported on MacOS and somehow the gradle build complains for that, the same thing for the .fullScreenCover.

If I remove those instructions everything's works fine.

I tried to remove the macOS support in the Xcode package description, but nothing changes when coming to gradle. I've also tried to embed those instruction in the #if !SKIP directive... but nothing.

Is there some way to make the gradle building process not care about MacOS, or, better, declare the app only for iOS and Android?

Thanks for your help, and great work!

@marcprux marcprux self-assigned this Jul 27, 2024
@marcprux
Copy link
Contributor

This is a shortcoming with our skip export command: in order to build locally, it first launches swift build to create the transpiled Kotlin sources, which it then builds and packages using gradle. But the swift build command can only build against the default macOS target, and so you are seeing errors with any API that isn't supported in macOS.

This has been irksome for a while, so I plan to try to fix it soon. In the meantime, however, I'm afraid you'll need to block out and non-macOS-compatible symbols inside if #os(iOS)/endif blocks.

But if all you want to do is launch the release version of the app, Skip will respect the Build Configuration for the scheme when you launch, so if you swift the configuration from "Debug" to "Release" in the Run target, then the apk that is build should be the release version. If you build your .apk this way, you will avoid the issue with skip export attempting a macOS build, since it will build using Xcode rather than launching swift build. In this case, the binary will be located at .build/Android/app/outputs/apk/release/app-release.apk rather than .build/Android/app/outputs/apk/debug/app-debug.apk.

Screenshot 2024-07-27 at 12 49 01

@macshodan
Copy link
Author

Thanks a lot for your clarifications and for pointing me in the right direction!

since sometimes I need to debug on the Android code using Android Studio I will stick with the #if os(iOS) blocks, because otherwise Android Studio will complain too :)

@marcprux marcprux pinned this issue Aug 16, 2024
@davidakoontz
Copy link

I'm wondering if you, @marcprux have worked out the issues here?
I feel like I'm getting similar errors and at one time had a macOS in the project file - was thinking it didn't get removed in some of the children files... but after reading this ... maybe the macOS build errors are coming from this workaround.

Perhaps there is a better explanation of building the Android package I will need - I hope?

@marcprux
Copy link
Contributor

@davidakoontz Are you referring to errors from the Xcode release build, or errors from skip export?

@davidakoontz
Copy link

Sorry I don’t fully recall (which Xcode build OR export) now. Let’s just ignore for now and I will create a new Question when it arrives.

I do remember getting the errors with navigationBartTitleDisplayMode and noting the macOS

Which is why I tagged onto this issue.

I feel that is related to building on/for MacOS (for some reason) - it appeared you were working on a solution.

Let’s just ignore my report as …. Me too.

@nex5turbo
Copy link

Can I ask if this problem is still unresolved?

@marcprux
Copy link
Contributor

marcprux commented Oct 7, 2024

The issue still exists. In order to run skip export, the project must be able to be built for macOS, which means that iOS-specific API calls (like fullScreenCover), need to be guarded within #if os(iOS)/#endif blocks. This is a hassle, but there shouldn't be too many of them. You can quickly identify them in Xcode by changing your target destination from iPhone to My Mac and trying to build the project.

@nex5turbo
Copy link

@marcprux Oh Thanks! :)

@nex5turbo
Copy link

The issue still exists. In order to run skip export, the project must be able to be built for macOS, which means that iOS-specific API calls (like fullScreenCover), need to be guarded within #if os(iOS)/#endif blocks. This is a hassle, but there shouldn't be too many of them. You can quickly identify them in Xcode by changing your target destination from iPhone to My Mac and trying to build the project.

This makes code applied only for iPhone. I made that #if os(iOS) || SKIP / #endif and works for both iPhone and Android without macOS error when do export or swift build.

@marcprux
Copy link
Contributor

marcprux commented Oct 8, 2024

This makes code applied only for iPhone. I made that #if os(iOS) || SKIP / #endif and works for both iPhone and Android without macOS error when do export or swift build.

Good point. You could also do #if !os(macOS) / #endif, which will have the same effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants