apk

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 24 Imported by: 0

README

apk — Android APK parser

High-level API for reading APK metadata and extracting launcher icon and TV banner images.

Supported inputs

apk.OpenFile accepts:

Input Example Behavior
Standard APK app.apk Root contains AndroidManifest.xml
Zip bundle disney.zip Finds base.apk or largest .apk with resources.arsc
XAPK (split) com.jakob.speedtest.xapk Base APK + split config APKs; fallback to root icon.png

Icon and Banner

Icon(resConfig)
  • Reads android:icon on <application>, then first <activity> if empty
  • Returns (image.Image, string, error) — second value is reserved (empty for raster output)
  • Raster first: walks resources.arsc and picks the highest-density mipmap PNG/WebP
  • Fallback: adaptive-icon XML → background + foreground composite; vector → SVG → rasterize
  • Vector/adaptive icons rasterize at 192×192; mipmap PNG/WebP keep native size
  • If no icon is configured: (nil, "", nil) — not an error
Banner(resConfig)
  • Reads android:banner on <application>, then first <activity> if empty
  • Does not fall back to Icon when banner is missing
  • Vector/shape banners rasterize at 320×180; PNG/WebP keep native size
  • If no banner: (nil, "", nil)
Save as PNG
icon, _, err := pkg.Icon(nil)
if err != nil {
	return err
}
if icon == nil {
	return fmt.Errorf("no icon")
}
f, _ := os.Create("ic_launcher.png")
defer f.Close()
return png.Encode(f, icon)

extract-icons

Command-line tool to export ic_launcher and banner from an APK, zip, or xapk.

cd apk

# flags
go run ./cmd/extract-icons -apk testdata/disney.zip -o ./out

# positional APK path
go run ./cmd/extract-icons testdata/Emby.xapk

# build binary
go build -o extract-icons ./cmd/extract-icons
./extract-icons -apk testdata/base.apk -o ./out

Output files (prefix = APK basename without extension):

  • {name}_ic_launcher.png
  • {name}_banner.png (skipped if app has no banner)

Tests

Large APK fixtures are not in git. Copy samples into testdata/ (see testdata/README.md), then:

go test -v -run TestParseAPKFile      # needs testdata/base.apk
go test -v -run TestOpenFileZipContainer  # needs testdata/disney.zip
go test -v -run TestOpenFileXapk      # needs testdata/Emby.xapk

Without fixtures, these tests are skipped so CI stays green.

Example — read package info

pkg, err := apk.OpenFile("testdata/base.apk")
if err != nil {
	log.Fatal(err)
}
defer pkg.Close()

log.Println(pkg.PackageName())
log.Println(pkg.VersionName(), pkg.VersionCode())
log.Println(pkg.MainActivity())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityAction

type ActivityAction struct {
	Name androidbinary.String `xml:"http://schemas.android.com/apk/res/android name,attr"`
}

ActivityAction is an action of an activity.

type ActivityCategory

type ActivityCategory struct {
	Name androidbinary.String `xml:"http://schemas.android.com/apk/res/android name,attr"`
}

ActivityCategory is a category of an activity.

type ActivityIntentFilter

type ActivityIntentFilter struct {
	Actions    []ActivityAction   `xml:"action"`
	Categories []ActivityCategory `xml:"category"`
}

ActivityIntentFilter is an androidbinary.Int32ent filter of an activity.

type Apk

type Apk struct {
	// contains filtered or unexported fields
}

Apk is an application package file for android.

func OpenFile

func OpenFile(filename string) (apk *Apk, err error)

OpenFile opens an APK file or a zip/xapk container (e.g. disney.zip, Emby.xapk) that embeds a base APK.

func OpenZipReader

func OpenZipReader(r io.ReaderAt, size int64) (*Apk, error)

OpenZipReader has same arguments like zip.NewReader. The reader must point at an APK zip (with AndroidManifest.xml at root), not an outer container zip.

func (*Apk) Banner

func (k *Apk) Banner(resConfig *androidbinary.ResTableConfig) (image.Image, string, error)

Banner returns the TV banner image of the APK (android:banner only). If the app has no banner, returns nil image and nil error.

func (*Apk) Close

func (k *Apk) Close() error

Close is avaliable only if apk is created with OpenFile

func (*Apk) ConvertXMLToSVG

func (k *Apk) ConvertXMLToSVG(xmlContent string) (string, error)

func (*Apk) Icon

func (k *Apk) Icon(resConfig *androidbinary.ResTableConfig) (image.Image, string, error)

Icon returns the app icon (android:icon only) as a raster image. Prefers mipmap PNG/WebP over adaptive-icon XML; falls back to vector rasterization when needed. If the app has no icon, returns nil image and nil error.

func (*Apk) Label

func (k *Apk) Label(resConfig *androidbinary.ResTableConfig) (s string, err error)

Label returns the label of the APK.

func (*Apk) MainActivity

func (k *Apk) MainActivity() (activity string, err error)

MainActivity returns the name of the main activity.

func (*Apk) Manifest

func (k *Apk) Manifest() Manifest

Manifest returns the manifest of the APK.

func (*Apk) PackageName

func (k *Apk) PackageName() string

PackageName returns the package name of the APK.

func (*Apk) Size

func (k *Apk) Size() int64

Size returns the size of the APK.

func (*Apk) VersionCode

func (k *Apk) VersionCode() int32

VersionCode returns the versionCode of the APK.

func (*Apk) VersionName

func (k *Apk) VersionName() string

VersionName returns the version name of the APK.

type AppActivity

type AppActivity struct {
	Theme             androidbinary.String   `xml:"http://schemas.android.com/apk/res/android theme,attr"`
	Banner            androidbinary.String   `xml:"http://schemas.android.com/apk/res/android banner,attr"`
	Icon              androidbinary.String   `xml:"http://schemas.android.com/apk/res/android icon,attr"`
	Name              androidbinary.String   `xml:"http://schemas.android.com/apk/res/android name,attr"`
	Label             androidbinary.String   `xml:"http://schemas.android.com/apk/res/android label,attr"`
	ScreenOrientation androidbinary.String   `xml:"http://schemas.android.com/apk/res/android screenOrientation,attr"`
	IntentFilters     []ActivityIntentFilter `xml:"intent-filter"`
}

AppActivity is an activity in an application.

type AppActivityAlias

type AppActivityAlias struct {
	Name           androidbinary.String   `xml:"http://schemas.android.com/apk/res/android name,attr"`
	Label          androidbinary.String   `xml:"http://schemas.android.com/apk/res/android label,attr"`
	TargetActivity androidbinary.String   `xml:"http://schemas.android.com/apk/res/android targetActivity,attr"`
	IntentFilters  []ActivityIntentFilter `xml:"intent-filter"`
}

AppActivityAlias https://developer.android.com/guide/topics/manifest/activity-alias-element

type Application

type Application struct {
	AllowTaskReparenting  androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android allowTaskReparenting,attr"`
	AllowBackup           androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android allowBackup,attr"`
	BackupAgent           androidbinary.String `xml:"http://schemas.android.com/apk/res/android backupAgent,attr"`
	Debuggable            androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android debuggable,attr"`
	Description           androidbinary.String `xml:"http://schemas.android.com/apk/res/android description,attr"`
	Enabled               androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android enabled,attr"`
	HasCode               androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android hasCode,attr"`
	HardwareAccelerated   androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android hardwareAccelerated,attr"`
	Icon                  androidbinary.String `xml:"http://schemas.android.com/apk/res/android icon,attr"`
	Banner                androidbinary.String `xml:"http://schemas.android.com/apk/res/android banner,attr"`
	KillAfterRestore      androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android killAfterRestore,attr"`
	LargeHeap             androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android largeHeap,attr"`
	Label                 androidbinary.String `xml:"http://schemas.android.com/apk/res/android label,attr"`
	ManageSpaceActivity   androidbinary.String `xml:"http://schemas.android.com/apk/res/android manageSpaceActivity,attr"`
	Name                  androidbinary.String `xml:"http://schemas.android.com/apk/res/android name,attr"`
	Permission            androidbinary.String `xml:"http://schemas.android.com/apk/res/android permission,attr"`
	Persistent            androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android persistent,attr"`
	Process               androidbinary.String `xml:"http://schemas.android.com/apk/res/android process,attr"`
	RestoreAnyVersion     androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android restoreAnyVersion,attr"`
	RequiredAccountType   androidbinary.String `xml:"http://schemas.android.com/apk/res/android requiredAccountType,attr"`
	RestrictedAccountType androidbinary.String `xml:"http://schemas.android.com/apk/res/android restrictedAccountType,attr"`
	SupportsRtl           androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android supportsRtl,attr"`
	TaskAffinity          androidbinary.String `xml:"http://schemas.android.com/apk/res/android taskAffinity,attr"`
	TestOnly              androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android testOnly,attr"`
	Theme                 androidbinary.String `xml:"http://schemas.android.com/apk/res/android theme,attr"`
	UIOptions             androidbinary.String `xml:"http://schemas.android.com/apk/res/android uiOptions,attr"`
	VMSafeMode            androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android vmSafeMode,attr"`
	Activities            []AppActivity        `xml:"activity"`
	ActivityAliases       []AppActivityAlias   `xml:"activity-alias"`
	MetaData              []MetaData           `xml:"meta-data"`
}

Application is an application in an APK.

type Instrumentation

type Instrumentation struct {
	Name            androidbinary.String `xml:"http://schemas.android.com/apk/res/android name,attr"`
	Target          androidbinary.String `xml:"http://schemas.android.com/apk/res/android targetPackage,attr"`
	HandleProfiling androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android handleProfiling,attr"`
	FunctionalTest  androidbinary.Bool   `xml:"http://schemas.android.com/apk/res/android functionalTest,attr"`
}

Instrumentation is an application instrumentation code.

type Manifest

type Manifest struct {
	Package         androidbinary.String `xml:"package,attr"`
	VersionCode     androidbinary.Int32  `xml:"http://schemas.android.com/apk/res/android versionCode,attr"`
	VersionName     androidbinary.String `xml:"http://schemas.android.com/apk/res/android versionName,attr"`
	App             Application          `xml:"application"`
	Instrument      Instrumentation      `xml:"instrumentation"`
	SDK             UsesSDK              `xml:"uses-sdk"`
	UsesPermissions []UsesPermission     `xml:"uses-permission"`
}

Manifest is a manifest of an APK.

type MetaData

type MetaData struct {
	Name  androidbinary.String `xml:"http://schemas.android.com/apk/res/android name,attr"`
	Value androidbinary.String `xml:"http://schemas.android.com/apk/res/android value,attr"`
}

MetaData is a metadata in an application.

type UsesPermission

type UsesPermission struct {
	Name androidbinary.String `xml:"http://schemas.android.com/apk/res/android name,attr"`
	Max  androidbinary.Int32  `xml:"http://schemas.android.com/apk/res/android maxSdkVersion,attr"`
}

UsesPermission is user grant the system permission.

type UsesSDK

type UsesSDK struct {
	Min    androidbinary.Int32 `xml:"http://schemas.android.com/apk/res/android minSdkVersion,attr"`
	Target androidbinary.Int32 `xml:"http://schemas.android.com/apk/res/android targetSdkVersion,attr"`
	Max    androidbinary.Int32 `xml:"http://schemas.android.com/apk/res/android maxSdkVersion,attr"`
}

UsesSDK is target SDK version.

Directories

Path Synopsis
cmd
extract-icons command
从 APK、zip 或 xapk(如 disney.zip、Emby.xapk)提取 ic_launcher 与 banner 并保存为 PNG。
从 APK、zip 或 xapk(如 disney.zip、Emby.xapk)提取 ic_launcher 与 banner 并保存为 PNG。

Jump to

Keyboard shortcuts

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