Skip to content

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

Open

Description

@vinceplusplus

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

Activity

  1. ephemer commented on Jul 9, 2022

    @ephemer
    Member

    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

  2. 3d4m-volodymyr commented on Jul 25, 2023

    @3d4m-volodymyr

    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

  3. 3d4m-volodymyr commented on Jul 26, 2023

    @3d4m-volodymyr

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions