apk

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 37 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"
	DataSyncService      = "dev.oneo.nsgo.DataSyncService"
	OverlayService       = "dev.oneo.nsgo.OverlayService"
	LocationService      = "dev.oneo.nsgo.LocationService"
	MotionService        = "dev.oneo.nsgo.MotionService"
	SensorRegionReceiver = "dev.oneo.nsgo.SensorRegionReceiver"
	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, DataSyncService is the generic dataSync foreground service mobile.StartDataSync runs in (Manifest.DataSync), OverlayService the one overlays over other apps take (Manifest.Overlay), of the specialUse type, LocationService the one background location streams run in (Manifest.Location), of the location 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 ValidAssetPackName

func ValidAssetPackName(name string) bool

ValidAssetPackName reports whether name can identify a Play asset module.

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, app names, network policy and launch screen 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, app names and network policy and launch screen when m has them.

Types

type AdaptiveIcon

type AdaptiveIcon struct {
	Foreground []byte
	Background []byte
	Monochrome []byte
}

AdaptiveIcon holds the PNG layers of an Android adaptive launcher icon.

type AssetPack

type AssetPack struct {
	Name, Delivery string
	Files          []AssetPackFile
}

AssetPack is a Play Asset Delivery module. Files in a pack are read from disk while signing and archiving the bundle.

type AssetPackFile

type AssetPackFile struct {
	Name, Source string
}

AssetPackFile is a relative asset path and the local file that supplies it.

type BundleIdentity

type BundleIdentity struct {
	Package     string
	VersionCode int64
}

BundleIdentity is the package name and version code in a bundle's base manifest.

func ReadBundleIdentity

func ReadBundleIdentity(r io.ReaderAt, size int64) (BundleIdentity, error)

ReadBundleIdentity reads only the protobuf manifest in an Android App Bundle.

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 LaunchAppearance

type LaunchAppearance struct {
	Background uint32
	Image      []byte
}

LaunchAppearance holds an opaque ARGB color and a PNG for the splash screen. Zero and nil leave the default or corresponding light entry in effect.

type LaunchScreen

type LaunchScreen struct {
	Light LaunchAppearance
	Dark  LaunchAppearance
}

LaunchScreen holds the launcher activity's splash screen and its night overrides. The framework theme can pin the selected appearance.

type Manifest

type Manifest struct {
	Widgets []Widget
	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
	// URLSchemes are the app's own links, registered on the launcher activity.
	URLSchemes []string
	// AppLinks are HTTPS hosts registered for Android's verified App Links.
	AppLinks []string
	// ShareTypes are the MIME types registered for incoming text and files.
	ShareTypes []string
	// Icon is the launcher icon, an IconSize PNG; nil keeps the system's.
	Icon []byte
	// Adaptive is the adaptive launcher icon's layers, which @mipmap/ic_launcher names from API 26 on, Icon below it; nil leaves Icon alone.
	Adaptive *AdaptiveIcon
	// Theme replaces the application's theme, a framework style; empty
	// keeps the runtime's.
	Theme string
	// Launch styles the launcher activity's system splash screen on API 31 and later.
	Launch *LaunchScreen
	// Debuggable marks a test or automation dev build, whose launch intent may name the test or enable the automation test agent.
	Debuggable bool
	// CrashReportBuild enables Java crash reports with this release build number.
	CrashReportBuild string
	// 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
	// Cleartext permits plain HTTP to any host, overriding loopback-only policy.
	Cleartext bool
	// LoopbackCleartext permits HTTP only to loopback when Cleartext is false.
	LoopbackCleartext bool
	// 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
	// BackgroundDownloads declares the runtime's dataSync transfer service.
	BackgroundDownloads bool
	// DataSync declares the runtime's generic dataSync foreground service (mobile.StartDataSync) and its permissions.
	DataSync bool
	// Motion declares the finite shortService for explicit background motion.
	Motion bool
	// Location declares the runtime's LocationService, the location foreground service a background location stream runs in (core.LocationOptions.Background), for an app whose Permissions name FOREGROUND_SERVICE_LOCATION; an app without it declares no such service, which Google Play would ask it to justify.
	Location 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
	// Game classifies the app as a game and declares its Game Mode XML.
	Game bool
	// Gamepad declares an optional gamepad and touchscreen.
	Gamepad bool
	// AssetPacks are separately delivered modules of an Android App Bundle.
	AssetPacks []AssetPack
}

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

type Widget

type Widget struct {
	Kind                string
	Names, Descriptions map[string]string
	Families            []string
}

Widget declares one kind of Android App Widget. Localized names and descriptions share the app's string table; "" is the default language.

Jump to

Keyboard shortcuts

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