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

How to debug the Swift source in Android Studio? #372

Open
vinceplusplus opened this issue Jul 9, 2022 · 3 comments
Open

How to debug the Swift source in Android Studio? #372

vinceplusplus opened this issue Jul 9, 2022 · 3 comments
Labels

Comments

@vinceplusplus
Copy link

Like setting a breakpoint inside a Swift source file? Or what is the suggested way to debug?

For the getting-started sample, I can't seem to set a breakpoint on any Swift source files, such as androidNativeInit.swift

@ephemer
Copy link
Member

ephemer commented Jul 9, 2022

The native debugger is currently not supported, unfortunately. We don't really understand why not, because lldb should be supported, but it's probably because Swift ships with its own version of lldb that is difficult to install on an Android device without enabling root mode on there

@3d4m-volodymyr
Copy link

3d4m-volodymyr commented Jul 25, 2023

Debugging partially works, but no swift support in NDK's lldb.

  1. You need to configure debug in buildTypes
    buildTypes {
        release {
            minifyEnabled false
        }
        debug {
            // The doNotStrip option is not properly scoped to the "debug" build type
            // See https://issuetracker.google.com/issues/155215248.
            packagingOptions {
                doNotStrip '**/*.so'
            }
            debuggable true
            jniDebuggable true
        }
    }
  1. Change build type to Debug option in CMake. In getting-started sample it will be like this
def getSwiftBuildCommand(abi) {
    def cmakeBuildType = "Debug"
    def buildScript = "../../../../swift-android-toolchain/swift-build.sh"
    return "CMAKE_BUILD_TYPE=$cmakeBuildType ANDROID_ABI=$abi LIBRARY_OUTPUT_DIRECTORY='${projectDir}/src/main/jniLibs/${abi}' $buildScript ../../"
}
  1. In Android Studio go to Run -> Edit Configurations... -> Debugger tab
    Select Dual (Java + Native).
    Set starting lldb command: settings set target.language swift - maybe one day this will just work!

More useful reads on lldb https://github.com/rustymagnet3000/lldb_debugger

@3d4m-volodymyr
Copy link

Btw, I was able to use xcode's lldb and lldb-server from apple's llvm fork.
Not the best experience but looks promising
Screenshot 2023-07-26 at 11 22 48
Screenshot 2023-07-26 at 11 35 42

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

No branches or pull requests

3 participants