apk

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 31 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package apk writes Android packages: the ZIP archive, the binary manifest and the v2 signature. Every NSGo build needs only Go, so the Android SDK's aapt2, d8 and apksigner stay out of it; the Java runtime comes prebuilt from platform/android/runtime.

Index

Constants

View Source
const (
	RecordingService = "dev.oneo.nsgo.RecordingService"
	OverlayService   = "dev.oneo.nsgo.OverlayService"
	OverlaySubtype   = "Keeps a window the user opened over other apps showing"
)

The runtime's foreground services: RecordingService is the one microphone.RecordWAV records in (Manifest.Recording), of the microphone type, OverlayService the one overlays over other apps take (Manifest.Overlay), of the specialUse type, and OverlaySubtype the subtype of its specialUse type, which stores read.

View Source
const BundletoolVersion = "1.18.3"

BundletoolVersion is the bundletool the bundle says it is made for.

View Source
const IconSize = 192

IconSize is the launcher icon's size in pixels: 48dp at xxxhdpi, the density the table declares it for. The system scales it for others.

Variables

This section is empty.

Functions

func EncodeManifest

func EncodeManifest(template []byte, m Manifest) ([]byte, error)

EncodeManifest turns the runtime's readable manifest into the binary XML an APK carries, with the app's package, version and label set.

func VersionCode

func VersionCode(version string) int

VersionCode turns a version like 1.2.3 into Android's integer code. A version that is not dotted numbers codes as 1.

func Write

func Write(w io.Writer, template []byte, m Manifest, files []File, key *Key) error

Write writes a signed APK to w: template's manifest with m filled in, then files, and the resource table the system expects, which holds the launcher icon and the app's names when m has them.

func WriteBundle

func WriteBundle(w io.Writer, template []byte, m Manifest, files []File, key *Key) error

WriteBundle writes a signed Android App Bundle to w: template's manifest with m filled in, files as the base module's, by their paths in an APK, and the resource table, which holds the launcher icon and the app's names when m has them.

Types

type File

type File struct {
	Name string
	Data []byte
	// Stored keeps Data uncompressed, for files the system maps instead
	// of reading whole.
	Stored bool
}

File is one entry of an APK.

type Key

type Key struct {
	Private *rsa.PrivateKey
	Cert    *x509.Certificate
}

Key is the identity an APK is signed with.

func NewKey

func NewKey() (*Key, error)

NewKey makes a self-signed signing identity, as a debug keystore holds.

func ReadKeystore

func ReadKeystore(data []byte, storePassword, alias, keyPassword string) (*Key, error)

ReadKeystore reads the signing key alias from a keystore as keytool and Android Studio write them: PKCS#12 (keytool's default since JDK 9) or the older JKS. keyPassword, when empty, is storePassword; alias, when empty, picks the only private key.

type Manifest

type Manifest struct {
	Package string
	Label   string
	// Names are the app's name in its languages, by BCP 47 tag, "" for
	// the default, which the launcher lists it under in place of Label.
	Names       map[string]string
	VersionName string
	VersionCode int
	// Icon is the launcher icon, an IconSize PNG; nil keeps the system's.
	Icon []byte
	// Theme replaces the application's theme, a framework style; empty
	// keeps the runtime's.
	Theme string
	// Debuggable marks a test build, whose launch intent may name the test
	// the runtime runs.
	Debuggable bool
	// Permissions are the permissions the app asks for beyond the
	// runtime's, by their full names.
	Permissions []string
	// TargetSDK replaces the runtime's targetSdkVersion when it is set.
	TargetSDK int
	// Overlay declares the runtime's OverlayService, the specialUse foreground service an overlay over other apps takes, for an app that asks for SYSTEM_ALERT_WINDOW; Permissions name its FOREGROUND_SERVICE permissions.
	Overlay bool
	// Recording declares the runtime's RecordingService, the microphone foreground service microphone.RecordWAV records in, with the permissions it needs. An app without it declares no such service, as Google Play asks an app to justify each foreground-service type its manifest has.
	Recording bool
	// Libraries are the shared libraries of the device the app uses where it has them, by name, as uses-library elements that do not require them.
	Libraries []string
}

Manifest is what packaging fills into the runtime's manifest template.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL