https://github.com/leleliu008/ndk-pkg
A package builder/manager for Android NDK to build projects written in C, C++, Rust, Golang, etc.
https://github.com/leleliu008/ndk-pkg
android-ndk c cli cxx golang package-manager rust
Last synced: 3 months ago
JSON representation
A package builder/manager for Android NDK to build projects written in C, C++, Rust, Golang, etc.
- Host: GitHub
- URL: https://github.com/leleliu008/ndk-pkg
- Owner: leleliu008
- License: apache-2.0
- Created: 2020-06-25T10:05:02.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2026-03-04T22:27:27.000Z (3 months ago)
- Last Synced: 2026-03-05T04:21:52.342Z (3 months ago)
- Topics: android-ndk, c, cli, cxx, golang, package-manager, rust
- Language: C
- Homepage: http://blog.fpliu.com/project/ndk-pkg
- Size: 12.5 MB
- Stars: 98
- Watchers: 4
- Forks: 19
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ndk-pkg
A package builder using [Android NDK](https://developer.android.google.cn/ndk)
## Caveats
Please read these caveats carefully before starting to use this software.
- This software is being actively developed. It's in beta stage and may not be stable. Some features are subject to change without notice.
- Please do NOT place your own files under `~/.ndk-pkg` directory, as `ndk-pkg` will change files under `~/.ndk-pkg` directory without notice.
- Please do NOT run `ndk-pkg` command in parallel so as not to generate dirty data.
## Platforms that this software can run on
|HostOS|HostArch|SubSystem|recommended|fully tested|fully supported|
|------|--------|---------|-----------|------------|-------|
|✶|`x86_64`|[Docker](https://www.docker.com/)|✔︎|✔︎|✔︎|
|[GNU/Linux](https://www.gnu.org/gnu/linux-and-gnu.en.html)|`x86_64`||✔︎|✔︎|✔︎|
|[Windows](https://www.microsoft.com/en-us/windows/)|`x86_64`|[WSL](https://docs.microsoft.com/en-us/windows/wsl/)||||
|[macOS](https://www.apple.com.cn/mac/)|`x86_64` `arm64`|||✔︎||
|[Android](https://www.apple.com.cn/mac/)|`aarch64`|[Termux](https://termux.dev/)||||
**Notes** :
- This software can NOT run on [Cygwin](http://cygwin.org/) and [MSYS2](https://www.msys2.org/) due to a cmake error: `CMake: Builds hosted on 'CYGWIN' not supported.`, for the reason please refer to [Android-Determine.cmake](https://github.com/Kitware/CMake/blob/master/Modules/Platform/Android-Determine.cmake#L278-L300). If you really want to use this software on [Windows](https://www.microsoft.com/en-us/windows/), please use via [Docker](https://www.docker.com/) or [WSL](https://docs.microsoft.com/en-us/windows/wsl/) instead.
## About the Android NDK toolchain
Generally, you don't need to download the `Android NDK`, because `ndk-pkg` will automatically download it when needed, unless you want to use your own `Android NDK`, you can specify your location of `Android NDK` via `--ndk-home=` option. **Please note that you can't specify your location of `Android NDK` via environment variable `ANDROID_NDK_HOME` and `ANDROID_NDK_ROOT`**
`ndk-pkg` also allows you to use a specific revision of `Android NDK` via `--ndk-revision=` option. For example, if you want to use the `Android NDK r28c`, you can run `ndk-pkg install --ndk-revision=28c`
## About 16KB page size support
At the moment, `ndk-pkg` use `Android NDK r27d (the latest LTS revision)`, it doesn't compile 16 KB-aligned by default. Due to Android NDK r28 and higher compile 16 KB-aligned by default, you can run `ndk-pkg install --ndk-revision=28c` if you need 16 KB-aligned ELF files.
## Using ndk-pkg via GitHub Actions
This is the recommended way of using this software.
In this way, you don't need a computer in hand, you could use GitHub mobile Apps.
In this way, you will be liberated from the rut of setting up the build environment.
In this way, you do NOT need to frequently update this software, you always use the latest version.
In this way, all you need to do is just clicking the buttons and waiting for finishing. After finishing, a url refers to a zip archive will be provided to download.
For more details please refer to
## Using ndk-pkg via [Docker](https://www.docker.com/)
This is the recommended way of using this software if you want to use this software locally.
`docker` container is an isolated clean environment where the running process can not be affected by your host system's environemt variables.
**step1. create the ndk-pkg docker container**
```bash
mkdir -p ~/ndk-pkg-home
mkdir -p ~/.m2
docker create -it --name ndk-pkg -v ~/ndk-pkg-home:/root/.ndk-pkg -v ~/.m2:/root/.m2 ghcr.io/leleliu008/ndk-pkg
```
**step2. start the ndk-pkg docker container**
```bash
docker start ndk-pkg
```
**step3. install essential tools**
```bash
docker exec -it ndk-pkg ndk-pkg setup
```
**step4. update formula repositories**
```bash
docker exec -it ndk-pkg ndk-pkg update
```
If all goes well, then next you can start to install packages whatever you want, for example, let's install `curl` package for target `android-35-arm64-v8a`:
```bash
docker exec -it ndk-pkg ndk-pkg install curl --target=android-35-arm64-v8a --static
```
**Note:** you can use `podman` instead of `docker`
## Using ndk-pkg via chroot+ubuntu
This is the recommended way of using this software if you want to use this software locally and your host is `linux-x86_64`.
`chroot`, an isolated clean environment, is much like `docker` container, where the running process can not be affected by your host system's environment variables.
```bash
curl -LO https://cdimage.ubuntu.com/ubuntu-base/releases/24.04/release/ubuntu-base-24.04.3-base-amd64.tar.gz
install -d ubuntu-rootfs
tar xf ubuntu-base-24.04.3-base-amd64.tar.gz -C ubuntu-rootfs
cp -p /etc/resolv.conf ubuntu-rootfs/etc/
curl -LO https://raw.githubusercontent.com/leleliu008/ndk-pkg/master/ndk-pkg
chmod a+x ndk-pkg
mv ndk-pkg ubuntu-rootfs/bin/
sudo mount -o bind /dev ubuntu-rootfs/dev
sudo mount -t proc none ubuntu-rootfs/proc
sudo mount -t sysfs none ubuntu-rootfs/sys
sudo mount -t tmpfs none ubuntu-rootfs/tmp
sudo chroot ubuntu-rootfs ndk-pkg setup -y
sudo chroot ubuntu-rootfs ndk-pkg update
sudo chroot ubuntu-rootfs ndk-pkg install curl --target=android-35-arm64-v8a --static
```
## Using ndk-pkg via chroot+alpine
This is the recommended way of using this software if you want to use this software locally and your host is `linux-x86_64`.
`chroot`, an isolated clean environment, is much like `docker` container, where the running process can not be affected by your host system's environment variables.
```bash
curl -LO https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/x86_64/alpine-minirootfs-3.22.0-x86_64.tar.gz
install -d alpine-rootfs
tar xf alpine-minirootfs-3.22.0-x86_64.tar.gz -C alpine-rootfs
cp -p /etc/resolv.conf alpine-rootfs/etc/
curl -LO https://raw.githubusercontent.com/leleliu008/ndk-pkg/master/ndk-pkg
chmod a+x ndk-pkg
mv ndk-pkg alpine-rootfs/bin/
sudo mount -o bind /dev alpine-rootfs/dev
sudo mount -t proc none alpine-rootfs/proc
sudo mount -t sysfs none alpine-rootfs/sys
sudo chroot alpine-rootfs ndk-pkg setup
sudo chroot alpine-rootfs ndk-pkg update
sudo chroot alpine-rootfs ndk-pkg install curl --target=android-35-arm64-v8a --static
```
## Using ndk-pkg via [WSL](https://docs.microsoft.com/en-us/windows/wsl)
**Note** :
- As of Android NDK r25, Android NDK for Linux is incompatible with WSL1 due to the use of [BOLT](https://github.com/llvm/llvm-project/tree/main/bolt). For more details please refer to https://github.com/android/ndk/issues/1755
**/etc/wsl.conf** :
```ini
[network]
hostname = ubuntu
generateHosts = false
[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=11"
mountFsTab = true
```
**installation instructions** :
```bash
# If you want to store ndk-pkg generated data to D:\ partition
export NDKPKG_HOME=/mnt/d/ndk-pkg
# If you use Ubuntu or Debian distribution
sudo apt -y update
sudo apt -y install curl
curl -LO https://raw.githubusercontent.com/leleliu008/ndk-pkg/master/ndk-pkg
chmod a+x ndk-pkg
./ndk-pkg setup
```
## Install ndk-pkg via cURL
**Caveats**:
- Running `ndk-pkg` locally directly on your local host is not recommended due to build tools(e.g. autotools, cmake, etc) are easy to be affected by environment variables. Running `ndk-pkg` in an isolated clean environment (`docker`, `chroot`) is highly recommended.
```bash
curl -LO https://raw.githubusercontent.com/leleliu008/ndk-pkg/master/ndk-pkg
chmod a+x ndk-pkg
./ndk-pkg setup
```
中国大陆的用户亦可将上面的地址替换为下面的地址:
- https://ghfast.top/https://raw.githubusercontent.com/leleliu008/ndk-pkg/master/ndk-pkg
- https://cdn.jsdelivr.net/gh/leleliu008/ndk-pkg/ndk-pkg
- https://gitee.com/fpliu/ndk-pkg/raw/master/ndk-pkg
## Install ndk-pkg via git
```bash
git clone --depth 1 https://github.com/leleliu008/ndk-pkg
ndk-pkg/ndk-pkg setup
```
## ~/.ndk-pkg
**Caveats**: Please do NOT place your own files under `~/.ndk-pkg` directory, as `ndk-pkg` will change (remove, modify, override) files under `~/.ndk-pkg` directory without notice.
A typical hierarchical structure under `~/.ndk-pkg` directory looks like below:
```text
~/.ndk-pkg
├── core
│ ├── SourceCodePro-Light.otf
│ ├── cacert.pem
│ ├── fonts.conf
│ ├── init.sh
│ ├── ndk-pkg-core-2024.05.15-linux-x86_64.tar.xz
│ ├── ndk-pkg-core-latest-release-version
│ ├── uppm
│ ├── wrapper-native-cc
│ ├── wrapper-native-c++
│ ├── wrapper-native-objc
│ ├── wrapper-target-cc
│ └── wrapper-target-c++
├── downloads
│ ├── 8f74213b56238c85a50a5329f77e06198771e70dd9a739779f4c02f65d971313.tgz
│ ├── b3a24de97a8fdbc835b9833169501030b8977031bcb54b3b3ac13740f846ab30.tgz
│ └── c642ae9b75fee120b2d96c712538bd2cf283228d2337df2cf2988e3c02678ef4.tgz
├── installed
│ ├── android-35-arm64-v8a
│ │ ├── f39a5f7836ac7ca1e04de14c8103e663d0b375a524a40e537258747e2deb3c0b
│ │ │ ├── include
│ │ │ ├── lib
│ │ │ └── share
│ │ └── zlib -> f39a5f7836ac7ca1e04de14c8103e663d0b375a524a40e537258747e2deb3c0b
│ ├── android-35-armeabi-v7a
│ │ ├── cc9b367d5068ef6b8aaaee38ec2a25691da35e02757c7e0d83aff3775aef3323
│ │ │ ├── include
│ │ │ ├── lib
│ │ │ └── share
│ │ └── zlib -> cc9b367d5068ef6b8aaaee38ec2a25691da35e02757c7e0d83aff3775aef3323
│ ├── android-35-x86
│ │ ├── a0718632fe829426c1d946e6658cc7586da0039e99d5a140d1e402a6b4a4e2f3
│ │ │ ├── include
│ │ │ ├── lib
│ │ │ └── share
│ │ └── zlib -> a0718632fe829426c1d946e6658cc7586da0039e99d5a140d1e402a6b4a4e2f3
│ └── android-35-x86_64
│ ├── c099047714d4ce1402d66346da88d14f25c313b0d4c879520198426ebc2f36fe
│ │ ├── include
│ │ ├── lib
│ │ └── share
│ └── zlib -> c099047714d4ce1402d66346da88d14f25c313b0d4c879520198426ebc2f36fe
├── native
│ └── linux-x86_64
│ ├── 30b5043e2c5513343152506e5b1e14436ddbb654f7edf69167df05f117fcdb16
│ │ ├── bin
│ │ │ ├── aclocal
│ │ │ ├── aclocal-1.16
│ │ │ ├── automake
│ │ │ └── automake-1.16
│ │ ├── share
│ │ └── receipt.txt
│ └── automake -> 30b5043e2c5513343152506e5b1e14436ddbb654f7edf69167df05f117fcdb16
├── uppm
│ ├── downloads
│ │ ├── fe6b6f7db67a20ccca0385ae38c4aafc7b2bfedc98f9d86880dfeb127a56c012.txz
│ │ └── ff66b70c830a38d331d44f6c25a37b582471def9a161c93902bac7bea3098319.tgz
│ ├── installed
│ │ ├── android-ndk-r26d
│ │ │ ├── CHANGELOG.md
│ │ │ ├── NOTICE
│ │ │ ├── NOTICE.toolchain
│ │ │ ├── README.md
│ │ │ ├── build
│ │ │ ├── meta
│ │ │ ├── ndk-build
│ │ │ ├── ndk-gdb
│ │ │ ├── ndk-lldb
│ │ │ ├── ndk-stack
│ │ │ ├── ndk-which
│ │ │ ├── prebuilt
│ │ │ ├── python-packages
│ │ │ ├── shader-tools
│ │ │ ├── simpleperf
│ │ │ ├── source.properties
│ │ │ ├── sources
│ │ │ ├── toolchains
│ │ │ └── wrap.sh
│ │ ├── bash
│ │ │ ├── bin
│ │ │ └── share
│ │ ├── bsdtar
│ │ │ ├── bin
│ │ │ └── share
│ │ ├── coreutils
│ │ │ ├── bin
│ │ │ ├── libexec
│ │ │ └── share
│ │ ├── curl
│ │ │ ├── bin
│ │ │ └── share
│ │ ├── d2
│ │ │ ├── bin
│ │ │ └── share
│ │ ├── dot_static
│ │ │ └── bin
│ │ ├── findutils
│ │ │ ├── bin
│ │ │ ├── libexec
│ │ │ ├── share
│ │ │ └── var
│ │ ├── gawk
│ │ │ ├── bin
│ │ │ ├── etc
│ │ │ ├── libexec
│ │ │ └── share
│ │ ├── git
│ │ │ ├── bin
│ │ │ ├── libexec
│ │ │ └── share
│ │ ├── grep
│ │ │ ├── bin
│ │ │ └── share
│ │ ├── gsed
│ │ │ ├── bin
│ │ │ └── share
│ │ ├── jq
│ │ │ ├── bin
│ │ │ └── share
│ │ ├── patchelf
│ │ │ ├── bin
│ │ │ └── share
│ │ ├── pkg-config
│ │ │ ├── bin
│ │ │ └── share
│ │ ├── tree
│ │ │ ├── bin
│ │ │ └── share
│ │ ├── xxd
│ │ │ └── bin
│ │ ├── yq
│ │ │ └── bin
│ │ └── zip
│ │ ├── bin
│ │ └── share
│ └── repos.d
│ └── official-core
│ ├── LICENSE
│ ├── README.md
│ └── formula
├── repos.d
│ └── official-core
│ ├── formula
│ │ ├── zlib.yml
│ │ ├── libbz2.yml
│ │ ├── liblzma.yml
│ │ └── libzstd.yml
│ └── README.md
└── run
├── 3409784
├── 3447656
└── 3457395
```
## ndk-pkg command usage
- **show help of this command**
```bash
ndk-pkg -h
ndk-pkg --help
```
- **show version of this command**
```bash
ndk-pkg -V
ndk-pkg --version
```
- **show basic information about this software**
```bash
ndk-pkg about
```
- **show basic information about your current running operation system**
```bash
ndk-pkg sysinfo
```
- **show basic information about the specified location of [Android NDK](https://developer.android.com/ndk)**
```bash
ndk-pkg ndkinfo /usr/local/share/android-ndk
```
- **generate url-transform sample**
```bash
ndk-pkg gen-url-transform-sample
```
- **install essential tools used by this shell script**
```bash
ndk-pkg setup
ndk-pkg setup -y
```
This command is mainly doing the following things:
- install `curl` via your system's package manager if none of `curl` `wget` `http` `lynx` `aria2c` `axel` command is found when `-y` option is given.
- install [uppm](https://github.com/leleliu008/uppm) to `~/.ndk-pkg/core`
- install other essential tools (listed below) that are used by this shell script via [uppm](https://github.com/leleliu008/uppm)
- [GNU Bash](https://www.gnu.org/software/bash/manual/bash.html)
- [GNU CoreUtils](https://www.gnu.org/software/coreutils/manual/coreutils.html)
- [GNU FindUtils](https://www.gnu.org/software/findutils/manual/html_mono/find.html)
- [GNU awk](https://www.gnu.org/software/gawk/manual/gawk.html)
- [GNU sed](https://www.gnu.org/software/sed/manual/sed.html)
- [GNU grep](https://www.gnu.org/software/grep/manual/grep.html)
- [BSD tar](https://man.archlinux.org/man/core/libarchive/bsdtar.1.en)
- [patchelf](https://github.com/NixOS/patchelf)
- [tree](https://linux.die.net/man/1/tree)
- [curl](https://curl.se/docs/manpage.html)
- [git](https://git-scm.com/docs/git)
- [xxd](https://raw.githubusercontent.com/vim/vim/master/runtime/doc/xxd.man)
- [fzf](https://github.com/junegunn/fzf)
- [bat](https://github.com/sharkdp/bat)
- [jq](https://stedolan.github.io/jq/manual/)
- [yq](https://mikefarah.gitbook.io/yq/)
- [d2](https://github.com/terrastruct/d2)
- [dot](https://graphviz.org/doc/info/command.html)
- **integrate `zsh-completion` script**
```bash
ndk-pkg integrate zsh
ndk-pkg integrate zsh --output-dir=/usr/local/share/zsh/site-functions
ndk-pkg integrate zsh -v
```
This software provides a zsh-completion script for `ndk-pkg`. when you've typed `ndk-pkg` then type `TAB` key, the rest of the arguments will be automatically complete for you.
**Note**: to apply this feature, you may need to run the command `autoload -U compinit && compinit` in your terminal (your current running shell must be zsh).
**Caveat**: to use this feature, you should put `ndk-pkg` command in `PATH`
- **update all available formula repositories**
```bash
ndk-pkg update
```
- **search all available packages whose name matches the given regular expression pattern**
```bash
ndk-pkg search curl
ndk-pkg search lib
```
- **show information of the given available package**
```bash
ndk-pkg info-available curl
ndk-pkg info-available curl --yaml
ndk-pkg info-available curl --json
ndk-pkg info-available curl version
ndk-pkg info-available curl license
ndk-pkg info-available curl summary
ndk-pkg info-available curl web-url
ndk-pkg info-available curl git-url
ndk-pkg info-available curl git-sha
ndk-pkg info-available curl git-ref
ndk-pkg info-available curl src-url
ndk-pkg info-available curl src-sha
ndk-pkg info-available curl src-ft
ndk-pkg info-available curl src-fp
```
- **show information of the given installed package**
```bash
ndk-pkg info-installed android-35-arm64-v8a/curl --prefix
ndk-pkg info-installed android-35-arm64-v8a/curl --files
ndk-pkg info-installed android-35-arm64-v8a/curl builtat
ndk-pkg info-installed android-35-arm64-v8a/curl builtat-iso-8601
ndk-pkg info-installed android-35-arm64-v8a/curl builtat-rfc-3339
ndk-pkg info-installed android-35-arm64-v8a/curl builtat-iso-8601-utc
ndk-pkg info-installed android-35-arm64-v8a/curl builtat-rfc-3339-utc
```
- **show packages that are depended by the given package**
```bash
ndk-pkg depends curl
ndk-pkg depends curl -t d2
ndk-pkg depends curl -t dot
ndk-pkg depends curl -t box
ndk-pkg depends curl -t png
ndk-pkg depends curl -t svg
ndk-pkg depends curl -t d2 -o dependencies/
ndk-pkg depends curl -t dot -o dependencies/
ndk-pkg depends curl -t box -o dependencies/
ndk-pkg depends curl -t png -o dependencies/
ndk-pkg depends curl -t svg -o dependencies/
ndk-pkg depends curl -o curl-dependencies.d2
ndk-pkg depends curl -o curl-dependencies.dot
ndk-pkg depends curl -o curl-dependencies.box
ndk-pkg depends curl -o curl-dependencies.png
ndk-pkg depends curl -o curl-dependencies.svg
ndk-pkg depends curl -t svg -o . --engine=d2
ndk-pkg depends curl -t svg -o . --engine=dot
```
- **download resources of the given package to the local cache**
```bash
ndk-pkg fetch curl
ndk-pkg fetch curl -v
```
- **install packages**
```bash
ndk-pkg install curl
ndk-pkg install android-35-arm64-v8a/curl
ndk-pkg install android-35-arm64-v8a/curl --static
```
- **reinstall packages**
```bash
ndk-pkg reinstall curl
ndk-pkg reinstall android-35-arm64-v8a/curl --static
```
- **uninstall packages**
```bash
ndk-pkg uninstall curl
ndk-pkg uninstall android-35-arm64-v8a/curl
```
- **upgrade the outdated packages**
```bash
ndk-pkg upgrade curl
ndk-pkg upgrade android-35-arm64-v8a/curl --static
```
- **upgrade this software**
```bash
ndk-pkg upgrade-self
ndk-pkg upgrade-self -v
```
- **list all available formula repositories**
```bash
ndk-pkg formula-repo-list
```
- **add a new formula repository**
```bash
ndk-pkg formula-repo-add my_repo https://github.com/leleliu008/ndk-pkg-formula-repository-my_repo
ndk-pkg formula-repo-add my_repo https://github.com/leleliu008/ndk-pkg-formula-repository-my_repo --branch=master
ndk-pkg formula-repo-add my_repo https://github.com/leleliu008/ndk-pkg-formula-repository-my_repo --branch=main
ndk-pkg formula-repo-add my_repo https://github.com/leleliu008/ndk-pkg-formula-repository-my_repo --sync
ndk-pkg formula-repo-add my_repo https://github.com/leleliu008/ndk-pkg-formula-repository-my_repo --sync --branch=master
ndk-pkg formula-repo-add my_repo https://github.com/leleliu008/ndk-pkg-formula-repository-my_repo --sync --branch=main
```
- **delete a existing formula repository**
```bash
ndk-pkg formula-repo-del my_repo
```
- **list all available packages**
```bash
ndk-pkg ls-available
```
- **list all installed packages**
```bash
ndk-pkg ls-installed
```
- **list all outdated packages**
```bash
ndk-pkg ls-outdated
```
- **check if the given package is available**
```bash
ndk-pkg is-available curl
```
- **check if the given package is installed**
```bash
ndk-pkg is-installed curl
ndk-pkg is-installed android-35-arm64-v8a/curl
```
- **check if the given package is outdated**
```bash
ndk-pkg is-outdated curl
ndk-pkg is-outdated android-35-arm64-v8a/curl
```
- **list installed files of the given installed package in a tree-like format**
```bash
ndk-pkg tree curl
ndk-pkg tree android-35-arm64-v8a/curl -L 3
```
- **show logs of the given installed package**
```bash
ndk-pkg logs curl
ndk-pkg logs android-35-arm64-v8a/curl
```
- **bundle the given installed package into a single archive file**
```bash
ndk-pkg bundle android-35-arm64-v8a/curl .tar.gz
ndk-pkg bundle android-35-arm64-v8a/curl .tar.xz
ndk-pkg bundle android-35-arm64-v8a/curl .tar.lz
ndk-pkg bundle android-35-arm64-v8a/curl .tar.bz2
ndk-pkg bundle android-35-arm64-v8a/curl .zip
ndk-pkg bundle android-35-arm64-v8a/curl xx.zip
ndk-pkg bundle android-35-arm64-v8a/curl a/.zip
ndk-pkg bundle android-35-arm64-v8a/curl a/xx.zip
```
- **export the given installed package as the google prefab aar**
```bash
ndk-pkg export android-35-arm64-v8a,x86_64/curl -o .
ndk-pkg export android-35-arm64-v8a,x86_64/curl -o curl-8.1.2.aar
```
- **export the given installed package as the google prefab aar then deploy it to Maven Local Repository**
```bash
ndk-pkg depoly android-35-arm64-v8a,x86_64/curl
ndk-pkg depoly android-35-arm64-v8a,x86_64/curl --debug
ndk-pkg depoly android-35-arm64-v8a,x86_64/curl --local=/somewhere
```
- **export the given installed package as the google prefab aar then deploy it to Sonatype OSSRH**
```bash
ndk-pkg depoly android-35-arm64-v8a,x86_64/curl --remote < ~/OSSRH-config
ndk-pkg depoly android-35-arm64-v8a,x86_64/curl --remote <`
`/path/of/url-transform` command must output a ``
you can generate a url-transform sample via `ndk-pkg gen-url-transform-sample`
If you want to change the request url, you can set this environment variable. It is very useful for chinese users.
- **NDKPKG_DNS_SERVERS**
DNS servers to be used instead of the system default.
```bash
export NDKPKG_DNS_SERVERS='1.1.1.1,8.8.8.8'
```
- **NDKPKG_XTRACE**
For debugging purposes.
enable `set -x`:
```bash
export NDKPKG_XTRACE=1
```
- **NDKPKG_HOME**
If this environment variable is not set or set a empty string, `~/.ndk-pkg` will be used as the default value.
```bash
export NDKPKG_HOME=/path/of/ndk-pkg-home
```
- **NDKPKG_DEFAULT_TARGET**
Some ACTIONs of ndk-pkg are associated with an installed package which need `PACKAGE-SPEC` to be specified.
**PACKAGE-SPEC** : a formatted string that has form: `/`, represents an installed package.
**PACKAGE-NAME** : should match the regular expression pattern `^[A-Za-z0-9+-_.@]{1,50}$`
**TARGET** : a formatted string that has form: `android--`
**ANDROID-API** : indicates which minimum [Android SDK API Level](https://developer.android.com/tools/releases/platforms) was built with.
**ANDROID-ABI** : indicates which [Android ABI](https://developer.android.com/ndk/guides/abis) was built for.
To simplify the usage, you are allowed to omit `/`. If `/` is omitted, environment variable `NDKPKG_DEFAULT_TARGET` would be checked, if this environment variable is not set, then `android-21-arm64-v8a` will be used as the default.
**Example**:
```bash
export NDKPKG_DEFAULT_TARGET='android-35-arm64-v8a'
```
- **NDKPKG_FORMULA_SEARCH_DIRS**
colon-seperated list of directories to search formulas.
**Note:** some commonly used environment variables are overridden by this software, these are `CC`, `CXX`, `CPP`, `AS`, `AR`, `LD`, `CFLAGS`, `CPPFLAGS`, `LDFLAGS`, `PKG_CONFIG_LIBDIR`, `PKG_CONFIG_PATH`, `ACLOCAL_PATH`
## ndk-pkg formula scheme
A ndk-pkg formula is a [YAML](https://yaml.org/spec/1.2.2/) format file, which is used to config a ndk-pkg package's meta-information such as one sentence description, package version, installation instructions, etc.
A ndk-pkg formula's filename suffix must be `.yml`
A ndk-pkg formula'a filename prefix would be treated as the package name.
A ndk-pkg formula'a filename prefix must match regular expression pattern `^[A-Za-z0-9+-._@]{1,50}$`
A ndk-pkg formula's file content only has one level mapping and shall/might have the following `KEY`s:
|KEY|TYPE|overview|
|-|-|-|
|`pkgtype`|`ENUM`|the type of this package.
value shall be any one of `exe`, `lib`, `exe+lib`.
If this mapping is not present, `ndk-pkg` will determine the package type by package name, if the package name starts/ends with `lib` or ends with `-dev`, it would be recognized as type `lib`, otherwise, it would be recognized as type `exe`|
|`linkage`|`ENUM`|This mapping is only for `exe` type package to specify the executable's link method.
value shall be any one of `static`, `static/pie`, `shared`, `shared/most`.
`static` indicates this package only support creating fully statically linked executables.
`shared` indicates this package only support creating dynamically linked executables and `ndk-pkg` will try to link as many static libraries as possible.
`shared/most` indicates this package only support creating dynamically linked executables and `ndk-pkg` will try to link as many shared libraries as possible.
`shared` as default if this mapping is not present.|
|`summary`|`TEXT`|one sentence description of this package.|
|`license`|`LIST`|A space-separated list of [SPDX license short identifiers](https://spdx.github.io/spdx-spec/v2.3/SPDX-license-list/#a1-licenses-with-short-identifiers)|
|`version`|`TEXT`|the version of this package.
If this mapping is not present, it will be calculated from `src-url`, if `src-url` is also not present, it will be calculated from running time as format `date +%Y.%m.%d`|
||||
|`web-url`|`URL`|the home webpage of this package.
If this mapping is not present, if `git-url` mapping is present, use it as `web-url`, if `git-url` mapping is not present, extract from `src-url`.|
||||
|`git-url`|`URL`|the source code git repository url.
If `src-url` is not present, this mapping must be present.|
|`git-ref`|`TEXT`|reference:
example values: `HEAD` `refs/heads/master` `refs/heads/main` `refs/tags/v1`, default value is `HEAD`|
|`git-sha`|`SHA1SUM`|the full git commit id, 40-byte hexadecimal string, if `git-ref` and `git-sha` both are present, `git-sha` takes precedence over `git-ref`|
|`git-nth`|`INT`|tell `ndk-pkg` that how many depth commits would you like to fetch. default is `1`, this would save your time and storage. If you have to fetch all commits, set this to `0`|
||||
|`src-url`|`URI`|the source code download url of this package.
If value of this mapping ends with one of `.zip` `.tar.xz` `.tar.gz` `.tar.lz` `.tar.bz2` `.tgz` `.txz` `.tlz` `.tbz2` `.crate`, it will be uncompressed to `$PACKAGE_WORKING_DIR/src` while this package is installing, otherwise, it will be copied to `$PACKAGE_WORKING_DIR/src`
also support format like `dir://DIR`|
|`src-uri`|`URL`|the mirror of `src-url`.|
|`src-sha`|`SHA256SUM`|the `sha256sum` of source code.
`src-sha` and `src-url` must appear together.|
||||
|`fix-url`|`URL`|the patch file download url of this package.
If value of this mapping ends with one of `.zip` `.tar.xz` `.tar.gz` `.tar.lz` `.tar.bz2` `.tgz` `.txz` `.tlz` `.tbz2` `.crate`, it will be uncompressed to `$PACKAGE_WORKING_DIR/fix` while this package is installing, otherwise, it will be copied to `$PACKAGE_WORKING_DIR/fix`.|
|`fix-uri`|`URL`|the mirror of `fix-url`.|
|`fix-sha`|`SHA256SUM`|the `sha256sum` of patch file.
`fix-sha` and `fix-url` must appear together.|
|`fix-opt`|`LIST`|A space-separated list of arguments to be passed to `patch` command. default value is `-p1`.|
||||
|`patches`|`LIST`|A LF-delimited list of formatted TEXTs. each TEXT has format: `\|[\|fix-uri][\|fix-opt]`|
||||
|`res-url`|`URL`|other resource download url of this package.
If value of this mapping ends with one of `.zip` `.tar.xz` `.tar.gz` `.tar.lz` `.tar.bz2` `.tgz` `.txz` `.tlz` `.tbz2` `.crate`, it will be uncompressed to `$PACKAGE_WORKING_DIR/res` while this package is installing, otherwise, it will be copied to `$PACKAGE_WORKING_DIR/res`.|
|`res-uri`|`URL`|the mirror of `res-url`.|
|`res-sha`|`SHA256SUM`|the `sha256sum` of resource file.
`res-sha` and `res-url` must appear together.|
||||
|`reslist`|`LIST`|A LF-delimited list of formatted TEXTs. each TEXT has format: `\|[\|res-uri][\|unpack-dir][\|N]`. `unpack-dir` is relative to `$PACKAGE_WORKING_DIR/res`, default value is empty. `N` is `--strip-components=N`|
||||
|`dep-lib`|`LIST`|A space-separated list of `pkg-config` packages needed by this package when installing.
each of them will be calculated via `pkg-config --libs-only-l ` then passed to the linker.|
|`dep-pkg`|`LIST`|A space-separated list of `ndk-pkg packages` depended by this package when installing, which will be installed via [ndk-pkg](https://github.com/leleliu008/ndk-pkg).|
|`dep-upp`|`LIST`|A space-separated list of `uppm packages` depended by this package when installing, which will be installed via [uppm](https://github.com/leleliu008/uppm).|
|`dep-plm`|`LIST`|A space-separated list of `perl modules` depended by this package when installing, which will be installed via [cpan](https://metacpan.org/dist/CPAN/view/scripts/cpan).|
|`dep-pip`|`LIST`|A space-separated list of `python packages` depended by this package when installing, which will be installed via [pip](https://github.com/pypa/pip).|
|`dep-gem`|`LIST`|A space-separated list of `ruby packages` depended by this package when installing, which will be installed via [gem](https://github.com/rubygems/rubygems).|
|`dep-npm`|`LIST`|A space-separated list of `nodejs packages` depended by this package when installing, which will be installed via [npm](https://github.com/npm/cli).|
||||
|`ccflags`|`LIST`|A space-separated list of arguments to be passed to the C compiler.|
|`xxflags`|`LIST`|A space-separated list of arguments to be passed to the C++ compiler.|
|`ppflags`|`LIST`|A space-separated list of arguments to be passed to the PreProcessor.|
|`ldflags`|`LIST`|A space-separated list of arguments to be passed to the linker.
`ndk-pkg` supports a custom option `-p`. It will be substituted by the result of `pkg-config --libs-only-l `|
||||
|`bsystem`|`LIST`|A space-separated list of build system names (e.g. `autogen` `autotools` `configure` `cmake` `cmake+gmake` `cmake+ninja` `meson` `xmake` `gmake` `ninja` `cargo` `cabal` `go` `rake` `ndk-build`)|
|`bscript`|`PATH`|the directory where the build script is located, relative to `$PACKAGE_WORKING_DIR/src`. build script such as `configure`, `Makefile`, `CMakeLists.txt`, `meson.build`, `Cargo.toml`, etc.|
|`binbstd`|`BOOL`|whether to build in the directory where the build script is located, otherwise build in other directory.
value shall be `0` or `1`. default value is `0`.|
|`ltoable`|`BOOL`|whether support [LTO](https://gcc.gnu.org/wiki/LinkTimeOptimization).
value shall be `0` or `1`. default value is `1`.|
|`movable`|`BOOL`|whether the installed files can be moved/copied to other locations.
value shall be `0` or `1`. default value is `1`.|
|`parallel`|`BOOL`|whether to allow build system to run jobs in parallel.
value shall be `0` or `1`. default value is `1`.|
||||
|`dofetch`|`CODE`|POSIX shell code to be run to take over the fetching process.
It would be run in a separate process.
`PWD` is `$PACKAGE_WORKING_DIR`|
|`do12345`|`CODE`|POSIX shell code to be run for native build.
It is running in a separated process.|
|`dopatch`|`CODE`|POSIX shell code to be run to apply patches manually.
`PWD` is `$PACKAGE_BSCRIPT_DIR`|
|`prepare`|`CODE`|POSIX shell code to be run to do some additional preparation before installing.
`PWD` is `$PACKAGE_BSCRIPT_DIR`|
|`install`|`CODE`|POSIX shell code to be run when user run `ndk-pkg install `.
If this mapping is not present, `ndk-pkg` will run default install code according to `bsystem`.
`PWD` is `$PACKAGE_BSCRIPT_DIR` if `binbstd` is `0`, otherwise it is `$PACKAGE_BCACHED_DIR`|
|`dotweak`|`CODE`|POSIX shell code to be run to do some tweaks immediately after installing.
`PWD` is `$PACKAGE_INSTALL_DIR`|
||||
|`bindenv`|`LIST`|A LF-delimited list of formatted TEXTs. each TEXT has format: `=`. `%s` in `` represents the install directory.
`ndk-pkg` will bind these environment variables to executables while you are running `ndk-pkg bundle`.|
||||
|`wrapper`|`LIST`|A LF-delimited list of formatted TEXTs. each TEXT has format: `\|`. e.g. `bear.c\|bin/` means that `ndk-pkg` will fetch `bear.c` from https://raw.githubusercontent.com/leleliu008/ndk-pkg-formula-repository-official-core/refs/heads/master/wrappers/bear.c then install it to `$PACKAGE_INSTALL_DIR/bin/` directory.
`ndk-pkg` will use these C source files to build the corresponding wrappers rather than a generic one while you are running `ndk-pkg bundle`.|
||||
|`caveats`|`TEXT`|plain text to be displayed after installing.|
||||
|`api-min`|`INT`|indicates which minimum [Android SDK API Level](https://apilevels.com/) is supported for this package.|
**Notes:**
- All mappings except `summary` are optional.
- At least one of `web-url` `git-url` `src-url` mappings should be present.
- Mappings not listed in the table above will be ignored.
**phases of a package's installation:**
```
process-0 process-1 process-2 process-3 process-0
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ dosetup │ -> │ dofetch │ -> │ do12345 │ -> │ dopatch │
└─────────┘ └─────────┘ └─────────┘ └─────────┘
⬇
┌─────────┐
│ prepare │
└─────────┘
⬇
┌─────────┐
│ install │
└─────────┘
⬇
┌─────────┐
│ dotweak │
└─────────┘
⬇
┌─────────┐ ┌─────────┐
│ docheck │ -> │ caveats │
└─────────┘ └─────────┘
```
**commands that can be used out of the box:**
|command|usage-example|
|-|-|
|`bash`|[Reference](https://www.gnu.org/software/bash/manual/bash.html)|
|`CoreUtils`|[Reference](https://www.gnu.org/software/coreutils/manual/coreutils.html)|
|`xargs`|[Reference](https://www.gnu.org/software/findutils/manual/html_node/find_html/Invoking-xargs.html)|
|`find`|[Reference](https://www.gnu.org/software/findutils/manual/html_mono/find.html)|
|`gawk`|[Reference](https://www.gnu.org/software/gawk/manual/gawk.html)|
|`gsed`|[Reference](https://www.gnu.org/software/sed/manual/sed.html)|
|`grep`|[Reference](https://www.gnu.org/software/grep/manual/grep.html)|
|`tree`|[Reference](https://linux.die.net/man/1/tree)|
|`jq`|[Reference](https://stedolan.github.io/jq/manual/)|
|`yq`|[Reference](https://mikefarah.gitbook.io/yq/)|
|`d2`|[Reference](https://github.com/terrastruct/d2)|
|`dot_static`|[Reference](https://graphviz.org/doc/info/command.html)|
|`bat`|[Reference](https://github.com/sharkdp/bat)|
|`xxd`|[Reference](https://raw.githubusercontent.com/vim/vim/master/runtime/doc/xxd.man)|
|`git`|[Reference](https://git-scm.com/docs/git)|
|`curl`|[Reference](https://curl.se/docs/manpage.html)|
|`bsdtar`|[Reference](https://man.archlinux.org/man/core/libarchive/bsdtar.1.en)|
|`pkg-config`|[Reference](https://people.freedesktop.org/~dbn/pkg-config-guide.html)|
|`patchelf`|[Reference](https://github.com/NixOS/patchelf)|
|||
|`echo`|`echo 'your message.'`|
|`info`|`info 'your information.'`|
|`warn`|`warn "no package manager found."`|
|`error`|`error 'error message.'`|
|`abort`|`abort 1 "please specify a package name."`|
|`success`|`success "build success."`|
|`isInteger`|`isInteger $x \|\| abort 1 "should be an integer."`|
|`isCrossBuild`|`isCrossBuild && abort 1 "This package is not supposed to be cross built."`|
|`wfetch`|`wfetch [--uri=] [--sha256=] [-o [-q]`|
|||
|`configure`|`configure --enable-pic`|
|`mesonw`|`mesonw -Dneon=disabled -Darm-simd=disabled`|
|`cmakew`|`cmakew -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON`|
|`gmakew`|`gmakew`|
|`xmakew`|`xmakew`|
|`cargow`|`cargow`|
|`gow`|`gow`|
**shell variables can be used directly:**
|variable|overview|
|-|-|
|`NDKPKG_ARG0`|the 1st arguments of `ndk-pkg` that you've supplied.|
|`NDKPKG_ARG1`|the 2nd arguments of `ndk-pkg` that you've supplied.|
|`NDKPKG_ARGV`|the all arguments of `ndk-pkg` that you've supplied.|
|`NDKPKG_PATH`|the full path of `ndk-pkg` that you're running.|
|`NDKPKG_HOME`|the home directory of `ndk-pkg` that you're running.|
|`NDKPKG_VERSION`|the version of `ndk-pkg` that you're running.|
|||
|`UPPM`|the executable filepath of [uppm](https://github.com/leleliu008/uppm)|
|||
|`TIMESTAMP_UNIX`|the unix timestamp of this action.|
|||
|`NATIVE_PLATFORM_KIND`|current running os kind. value might be `linux` or `darwin`|
|`NATIVE_PLATFORM_TYPE`|current running os type. value might be `linux` or `macos`|
|`NATIVE_PLATFORM_NAME`|current running os name. value might be `Ubuntu`, `macOS`, etc|
|`NATIVE_PLATFORM_VERS`|current running os version.|
|`NATIVE_PLATFORM_ARCH`|current running os arch. value might be any one of `x86_64`, `arm64`, etc|
|`NATIVE_PLATFORM_NCPU`|current running os's cpu core count.|
|`NATIVE_PLATFORM_EUID`|current running os's effective user ID.|
|`NATIVE_PLATFORM_EGID`|current running os's effective group ID.|
|||
|`TARGET_PLATFORM_VERS`|[android sdk api-level table](https://developer.android.google.cn/guide/topics/manifest/uses-sdk-element#api-level-table)|
|`TARGET_PLATFORM_NBIT`|value shall be any one of `32` `64`|
|`TARGET_PLATFORM_ARCH`|value shall be any one of `armv7a` `aarch64` `i686` `x86_64`|
|`TARGET_PLATFORM_ABI`|value shall be any one of `armeabi-v7a` `arm64-v8a` `x86` `x86_64`|
|`TARGET_TRIPLE`|value shall be any one of `armv7a-linux-androideabi` `aarch64-linux-android` `i686-linux-android` `x86_64-linux-android`|
|||
|`ANDROID_NDK_HOME`|the home directory of `Android NDK`.|
|`ANDROID_NDK_ROOT`|the home directory of `Android NDK`.|
|`ANDROID_NDK_VERSION`|the version of `Android NDK`.|
|`ANDROID_NDK_VERSION_MAJOR`|the major part of version of `Android NDK`.|
|`ANDROID_NDK_TOOLCHAIN_BIND`|the `bin` directory of `Android NDK`.|
|`ANDROID_NDK_SYSROOT`|the `sysroot` directory of `Android NDK`.|
|||
|`CC_FOR_BUILD`|the C Compiler for native build.|
|`CFLAGS_FOR_BUILD`|the flags of `CC_FOR_BUILD`.|
|`CXX_FOR_BUILD`|the C++ Compiler for native build.|
|`CXXFLAGS_FOR_BUILD`|the flags of `CXX_FOR_BUILD`.|
|`CPP_FOR_BUILD`|the C/C++ PreProcessor for native build.|
|`CPPFLAGS_FOR_BUILD`|the flags of `CPP_FOR_BUILD`.|
|`AS_FOR_BUILD`|the assembler for native build.|
|`AR_FOR_BUILD`|the archiver for native build.|
|`RANLIB_FOR_BUILD`|the archiver extra tool for native build.|
|`LD_FOR_BUILD`|the linker for native build.|
|`LDFLAGS_FOR_BUILD`|the flags of `LD_FOR_BUILD`.|
|`NM_FOR_BUILD`|a command line tool to list symbols from object files for native build.|
|`STRIP_FOR_BUILD`|a command line tool to discard symbols and other data from object files for native build.|
|||
|`CC`|the C Compiler.|
|`CFLAGS`|the flags of `CC`.|
|`CXX`|the C++ Compiler.|
|`CXXFLAGS`|the flags of `CXX`.|
|`CPP`|the C/C++ PreProcessor.|
|`CPPFLAGS`|the flags of `CPP`.|
|`AS`|the assembler.|
|`AR`|the archiver.|
|`RANLIB`|the archiver extra tool.|
|`LD`|the linker.|
|`LDFLAGS`|the flags of `LD`.|
|`NM`|a command line tool to list symbols from object files.|
|`STRIP`|a command line tool to discard symbols and other data from object files.|
|||
|`PACKAGE_WORKING_DIR`|the working directory for installing.|
|`PACKAGE_BSCRIPT_DIR`|the directory where the build script (e.g. `Makefile`, `configure`, `CMakeLists.txt`, `meson.build`, `Cargo.toml`, etc) is located.|
|`PACKAGE_BCACHED_DIR`|the directory where the temporary files are stored in when building.|
|`PACKAGE_INSTALL_DIR`|the directory where the final files will be installed to.|
|||
|`x_INSTALL_DIR`|the installation directory of x package.|
|`x_INCLUDE_DIR`|`$x_INSTALL_DIR/include`|
|`x_LIBRARY_DIR`|`$x_INSTALL_DIR/lib`|
## build system name and corresponding build script file name
|build system name|build script file name|
|-|-|
|`meson`|`meson.build`|
|`cmake`|`CMakeLists.txt`|
|`gmake`|`GNUMakefile` or `Makefile`|
|`ninja`|`build.ninja`|
|`xmake`|`xmake.lua`|
|`cargo`|`Cargo.toml`|
|`go`|`go.mod`|
|`gn`|`BUILD.gn`|
|`rake`|`Rakefile`|
|`autogen`|`autogen.sh`|
|`autotools`|`configure.ac`|
|`configure`|`configure`|
|`ndk-build`|`Android.mk`|
## ndk-pkg formula repository
A typical hierarchical structure of a ndk-pkg formula repository looks like below:
```
NDKPKGFormulaRepoName
├── formula
│ ├── packageA.yml
│ └── packageB.yml
├── LICENSE
└── README.md
```
## ndk-pkg formula repository local location
`${NDKPKG_HOME}/repos.d/${NDKPKGFormulaRepoName}`
## ndk-pkg formula repository local config
A ndk-pkg formula repository's config file is located at `${NDKPKG_HOME}/repos.d/${NDKPKGFormulaRepoName}/.ndk-pkg-formula-repo.yml`
A typical ndk-pkg formula repository's config file content looks like below:
```yaml
url: https://github.com/leleliu008/ndk-pkg-formula-repository-official-core
branch: master
pinned: 0
enabled: 1
created: 1673684639
updated: 1673684767
```
If a ndk-pkg formula repository is `pinned`, it would not be updated.
If a ndk-pkg formula repository is `disabled`, it would not be searched.
## ndk-pkg formula repository management
run `ndk-pkg formula-repo-add ` command to create a new formula repository locally.
## ndk-pkg official formula repository
ndk-pkg official formula repository is hosted at
It would be automatically fetched to your local repository as name `official-core` when you run `ndk-pkg update` command.
**Note:** If you find that a package is not in ndk-pkg official formula repository yet, PR is welcomed.
## Using my prefab aars that have been published to GitHub-Hosted Maven Repository alongside with Android Gradle Plugin
I have published some commonly used packages as google prefab aar to
## Using my prefab aars that have been published to Maven Central Repository alongside with Android Gradle Plugin
I have published some commonly used packages as google prefab aar to `Maven Central Repository`.
To get the full list of my published packages, please visit the following websites:
-
-
In the next two sections, I will show you how to configure with `Android Gradle Plugin` in `Kotlin DSL` and `Groovy DSL` respectively.
## configure with Android Gradle Plugin Kotlin DSL
**step1. enable prefab feature for Android Gradle Plugin**
```gradle
android {
buildFeatures {
prefab = true
}
}
```
**step2. enable `Maven Central Repository` for Gradle**
```gradle
allprojects {
repositories {
maven {
mavenCentral()
}
}
}
```
中国大陆的用户可使用如下配置:
```gradle
allprojects {
repositories {
maven {
maven { url = uri("https://maven.aliyun.com/repository/public") }
}
}
}
```
**step3. add dependencies in build.gradle.kts**
Every package's coordinate for Gradle is `com.fpliu.ndk.pkg.prefab.android.21::`, for example, `libpng` package has a version `1.6.37`, we could use it as follows:
```gradle
dependencies {
implementation ("com.fpliu.ndk.pkg.prefab.android.21:libpng:1.6.37")
}
```
**step4. invoke [find_package(PACKAGE-NAME [REQUIRED] CONFIG)](https://cmake.org/cmake/help/latest/command/find_package.html) command in your Android project's CMakeLists.txt**
Every package provides several cmake imported targets:
|TARGET-NAME|example|summary|
|-|-|-|
|`::headers`|`libpng::headers`|C/C++ header files only|
|`::lib*.a`|`libpng::libpng16.a`|static library|
|`::lib*.so`|`libpng::libpng16.so`|shared library|
|`::*`|`libpng::libpng`|base on .pc files|
Following is a piece of codes show you how to link `libpng.a` which is provided by `libpng` package:
```cmake
find_package(libpng REQUIRED CONFIG)
target_link_libraries(app libpng::libpng.a)
```
or
```cmake
find_package(libpng CONFIG)
if (libpng_FOUND)
target_link_libraries(app libpng::libpng.a)
endif()
```
**step5. configure C++ standard and STL in build.gradle.kts**
```gradle
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments += "-DANDROID_STL=c++_shared"
cppFlags += "-std=c++17"
}
}
}
}
```
**Note:**
- This step is only required for packages that use `libc++`.
- If you link a shared library that depends on `libc++_shared.so`, then your Android app should use `libc++_shared.so` too.
## configure with Android Gradle Plugin Groovy DSL
**step1. enable prefab feature for Android Gradle Plugin**
```gradle
android {
buildFeatures {
prefab true
}
}
```
**step2. enable `Maven Central Repository` for Gradle**
```gradle
allprojects {
repositories {
maven {
mavenCentral()
}
}
}
```
中国大陆的用户可使用如下配置:
```gradle
allprojects {
repositories {
maven {
url 'https://maven.aliyun.com/repository/public'
}
}
}
```
**step3. add dependencies in build.gradle**
Every package's coordinate for Gradle is `com.fpliu.ndk.pkg.prefab.android.21::`, for example, `libpng` package has a version `1.6.37`, we could use it as follows:
```gradle
dependencies {
implementation 'com.fpliu.ndk.pkg.prefab.android.21:libpng:1.6.37'
}
```
**step4. invoke [find_package(PACKAGE-NAME [REQUIRED] CONFIG)](https://cmake.org/cmake/help/latest/command/find_package.html) command in your Android project's CMakeLists.txt**
Every package provides several cmake imported targets:
|TARGET-NAME|example|summary|
|-|-|-|
|`::headers`|`libpng::headers`|C/C++ header files only|
|`::lib*.a`|`libpng::libpng16.a`|static library|
|`::lib*.so`|`libpng::libpng16.so`|shared library|
|`::*`|`libpng::libpng`|base on .pc files|
Following is a piece of codes show you how to link `libpng.a` which is provided by `libpng` package:
```cmake
find_package(libpng REQUIRED CONFIG)
target_link_libraries(app libpng::libpng.a)
```
or
```cmake
find_package(libpng CONFIG)
if (libpng_FOUND)
target_link_libraries(app libpng::libpng.a)
endif()
```
**step5. configure C++ standard and STL in build.gradle**
```gradle
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared'
cppFlags '-std=c++17'
}
}
}
}
```
**Note:**
- This step is only required for packages that use `libc++`.
- If you link a shared library that depends on `libc++_shared.so`, then your Android app should use `libc++_shared.so` too.
**References:**
-
-
-
**Examples:**
-
## Create the google prefab aar then deploy it to Maven Local Repository and use it alongside with Android Gradle Plugin
If my published packages don't meet your needs, you can use this software to install packages then deploy them to `Maven Local Repository`.
In the next two sections, I will show you how to configure with `Android Gradle Plugin` in `Kotlin DSL` and `Groovy DSL` respectively.
## configure with Android Gradle Plugin Kotlin DSL
**step1. build and install libpng**
Suppose you want to build and install `libpng`, the following command will build `libpng` with `android-35` API and build for `arm64-v8a` and `armeabi-v7a` ABI respectively.
```bash
ndk-pkg install android-35-arm64-v8a,armeabi-v7a/libpng
```
**step2. export the installed libpng package as the google prefab aar and deploy it to your Maven Local Repository**
```bash
ndk-pkg deploy android-35-arm64-v8a,armeabi-v7a/libpng
```
**step3. enable prefab feature for Android Gradle Plugin**
```gradle
android {
buildFeatures {
prefab = true
}
}
```
**step4. enable `Maven Local Repository` for Gradle**
```gradle
allprojects {
repositories {
maven {
mavenLocal()
}
}
}
```
**step5. add dependencies in build.gradle.kts**
Every package's coordinate for Gradle is `com.fpliu.ndk.pkg.prefab.android.21::`, for example, `libpng` package has a version `1.6.37`, we could use it as follows:
```gradle
dependencies {
implementation ("com.fpliu.ndk.pkg.prefab.android.21:libpng:1.6.37")
}
```
**step6. invoke [find_package(PACKAGE-NAME [REQUIRED] CONFIG)](https://cmake.org/cmake/help/latest/command/find_package.html) command in your Android project's CMakeLists.txt**
Every package provides several cmake imported targets:
|TARGET-NAME|example|summary|
|-|-|-|
|`::headers`|`libpng::headers`|C/C++ header files only|
|`::lib*.a`|`libpng::libpng16.a`|static library|
|`::lib*.so`|`libpng::libpng16.so`|shared library|
|`::*`|`libpng::libpng`|base on .pc files|
Following is a piece of codes show you how to link `libpng.a` which is provided by `libpng` package:
```cmake
find_package(libpng REQUIRED CONFIG)
target_link_libraries(app libpng::libpng.a)
```
or
```cmake
find_package(libpng CONFIG)
if (libpng_FOUND)
target_link_libraries(app libpng::libpng.a)
endif()
```
**step7. configure C++ standard and STL in build.gradle.kts**
```gradle
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments += "-DANDROID_STL=c++_shared"
cppFlags += "-std=c++17"
}
}
}
}
```
**Note:**
- This step is only required for packages that use `libc++`.
- If you link a shared library that depends on `libc++_shared.so`, then your Android app should use `libc++_shared.so` too.
## configure with Android Gradle Plugin Groovy DSL
**step1. build and install libpng**
Suppose you want to build and install `libpng`, the following command will build `libpng` with `android-35` API and build for `arm64-v8a` and `armeabi-v7a` ABI respectively.
```bash
ndk-pkg install android-35-arm64-v8a,armeabi-v7a/libpng
```
**step2. export the installed libpng package as the google prefab aar and deploy it to your Maven Local Repository**
```bash
ndk-pkg deploy android-35-arm64-v8a,armeabi-v7a/libpng
```
**step3. enable prefab feature for Android Gradle Plugin**
```gradle
android {
buildFeatures {
prefab true
}
}
```
**step4. enable `Maven Local Repository` for Gradle**
```gradle
allprojects {
repositories {
maven {
mavenLocal()
}
}
}
```
**step5. add dependencies in build.gradle**
Every package's coordinate for Gradle is `com.fpliu.ndk.pkg.prefab.android.21::`, for example, `libpng` package has a version `1.6.37`, we could use it as follows:
```gradle
dependencies {
implementation 'com.fpliu.ndk.pkg.prefab.android.21:libpng:1.6.37'
}
```
**step6. invoke [find_package(PACKAGE-NAME [REQUIRED] CONFIG)](https://cmake.org/cmake/help/latest/command/find_package.html) command in your Android project's CMakeLists.txt**
Every package provides several cmake imported targets:
|TARGET-NAME|example|summary|
|-|-|-|
|`::headers`|`libpng::headers`|C/C++ header files only|
|`::lib*.a`|`libpng::libpng16.a`|static library|
|`::lib*.so`|`libpng::libpng16.so`|shared library|
|`::*`|`libpng::libpng`|base on .pc files|
Following is a piece of codes show you how to link `libpng.a` which is provided by `libpng` package:
```cmake
find_package(libpng REQUIRED CONFIG)
target_link_libraries(app libpng::libpng.a)
```
or
```cmake
find_package(libpng CONFIG)
if (libpng_FOUND)
target_link_libraries(app libpng::libpng.a)
endif()
```
**step7. configure C++ standard and STL in build.gradle**
```gradle
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared'
cppFlags '-std=c++17'
}
}
}
}
```
**Note:**
- This step is only required for packages that use `libc++`.
- If you link a shared library that depends on `libc++_shared.so`, then your Android app should use `libc++_shared.so` too.
**References:**
-
-
-
**Examples:**
-
-