Skip to content

PADL/swift-android-native

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android Native

This package provides a Swift interface to various Android NDK APIs.

Requirements

Installation

Swift Package Manager

Add the package to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/skiptools/swift-android-logging.git", from: "1.0.0")
]

AndroidLogging

This module provides a Logger API for native Swift on Android compatible with the OSLog Logger for Darwin platforms.

Installation

Swift Package Manager

Add the AndroidLogging module as a conditional dependency for any targets that need it:

.target(name: "MyTarget", dependencies: [
    .product(name: "AndroidLogging", package: "swift-android-logging", condition: .when(platforms: [.android]))
])

Usage

Example

This example will use the system OSLog on Darwin platforms and AndroidLogging on Android to provide common logging functionality across operating systems:

#if canImport(Darwin)
import OSLog
#elseif os(Android)
import AndroidLogging
#endif
    
let logger = Logger(subsystem: "Subsystem", category: "Category")

logger.info("Hello Android logcat!")

Viewing Logs

Android log messages for connected devices and emulators can be viewed from the Terminal using the adb logcat command. For example, to view only the log message in the example above, you can run:

$ adb logcat '*:S' 'Subsystem/Category:I'

10-27 15:53:12.768 22599 22664 I Subsystem/Category: Hello Android logcat!

Android Studio provides the ability to graphically view and filter log messages, as do most other Android IDEs.

Internals

Implementation details

The Logger functions will forward messages to the NDK __android_log_write function.

Limitations

  • OSLogMessage is simply a typealias to Swift.String, and does not implement any of the redaction features of the Darwin version.

License

Licensed under the Apache 2.0 license with a runtime library exception, meaning you do not need to attribute the project in your application. See the LICENSE file for details.

About

Access to the Android NDK from Swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 93.4%
  • C 6.6%