Skip to content

How to import the OSLog wrapper for AndroidLogging? #31

@dpogueproton

Description

@dpogueproton

With the 2.0.0 release, AndroidLogging was changed and a new OSLog wrapper was introduced for API compatibility with the OSLog module on Darwin systems. However, it doesn't seem to be able to be used by downstream projects, and the example code in the README does not compile.

Adding AndroidLogging as a dependency alone does not bring in the OSLog wrapper, but trying to add OSLog as a dependency results in an error:

      dependencies: [
        .product(name: "Logging", package: "swift-log", condition: .when(platforms: [.linux])),
        .product(name: "OSLog", package: "swift-android-native", condition: .when(platforms: [.android]))
      ]
error: 'myproj': product 'OSLog' required by package 'myproj' target 'MyLogger' not found in package 'swift-android-native'.

It looks like the OSLog module is conditionally defined in Package.swift, which is probably why it is unavailable:

if android {
// add compatibility import from OSLog to AndroidLogging
package.targets += [.target(name: "OSLog", dependencies: ["AndroidLogging"])]
package.targets.first(where: { $0.name == "AndroidLoggingTests" })?.dependencies += [.target(name: "OSLog")]
}

Is there a reason it can't be unconditionally defined when targeting the Android platform? Or, how is this intended to be used since the example code is broken?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions