2020-05-14 07:42:13 +08:00
# Vcpkg: export Android prefab Archives (AAR files)
2020-04-07 05:36:17 +08:00
2020-05-14 07:42:13 +08:00
Vcpkg can export android archives ([AAR files](https://developer.android.com/studio/projects/android-library)). Once an archive is created, it can imported in Android Studio as a native dependent. The archive is automatically consumed using [android studio's prefab tool ](https://github.com/google/prefab ).
2020-04-07 05:36:17 +08:00
2020-05-14 07:42:13 +08:00
For more information on Prefab, refer to:
* The [official prefab documentation ](https://google.github.io/prefab ).
* a blog post from Android developers blog: [Native Dependencies in Android Studio 4.0 ](https://android-developers.googleblog.com/2020/02/native-dependencies-in-android-studio-40.html )
2020-04-07 05:36:17 +08:00
2020-05-14 07:42:13 +08:00
_Note for Android Studio users: prefab packages are supported on Android Studio 4+_
2020-04-07 05:36:17 +08:00
2020-05-14 07:42:13 +08:00
## Requirements
2020-04-07 05:36:17 +08:00
2020-05-14 07:42:13 +08:00
1. `ndk <required>`
2020-04-07 05:36:17 +08:00
2020-05-14 07:42:13 +08:00
Set environment variable `ANDROID_NDK_HOME` to your android ndk installation. For example:
````
export ANDROID_NDK_HOME=/home/your-account/Android/Sdk/ndk-bundle
````
2. `7zip <required on windows>` or `zip <required on linux>`
3. `maven <optional>`
4. Android triplets
See [android.md ](../users/android.md ) for instructions on how to install the triplets.
*Please note that in order to use "prefab" (see below), the four architectures are required. If any is missing the export will fail*
2020-04-07 05:36:17 +08:00
2020-05-14 07:42:13 +08:00
## Example exporting [jsoncpp]
2020-04-07 05:36:17 +08:00
2020-05-14 07:42:13 +08:00
First "vcpkg install" the 4 android architectures (it is mandatory to export all 4 of them)
````
./vcpkg install jsoncpp:arm-android jsoncpp:arm64-android jsoncpp:x64-android jsoncpp:x86-android
````
Then, export the prefab:
Note:
* The `--prefab-maven` flag is optional. Call it if you maven is installed.
* The `--prefab-debug` flag will output instructions on how to use the prefab archive via gradle.
2020-04-07 05:36:17 +08:00
```
2020-05-14 07:42:13 +08:00
./vcpkg export --triplet x64-android jsoncpp --prefab --prefab-maven --prefab-debug
2020-04-07 05:36:17 +08:00
```
2020-05-14 07:42:13 +08:00
You will see an ouput like this:
2020-04-07 05:36:17 +08:00
```
The following packages are already built and will be exported:
2020-05-14 07:42:13 +08:00
jsoncpp:arm64-android
2020-04-07 05:36:17 +08:00
Exporting package jsoncpp...
2020-05-14 07:42:13 +08:00
[DEBUG] Found 4 triplets
arm64-android
x64-android
x86-android
arm-android
...
... Lots of output...
...
2020-04-07 05:36:17 +08:00
[INFO] Scanning for projects...
2020-05-14 07:42:13 +08:00
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
...
... Lots of output...
...
2020-04-07 05:36:17 +08:00
[INFO] BUILD SUCCESS
2020-05-14 07:42:13 +08:00
[INFO] Total time: 2.207 s
[INFO] Finished at: 2020-05-10T14:42:28+02:00
...
... Lots of output...
...
[DEBUG] Configuration properties in Android Studio
2020-04-07 05:36:17 +08:00
In app/build.gradle
2020-05-14 07:42:13 +08:00
com.vcpkg.ndk.support:jsoncpp:1.9.2
2020-04-07 05:36:17 +08:00
And cmake flags
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared'
cppFlags "-std=c++17"
}
}
In gradle.properties
android.enablePrefab=true
android.enableParallelJsonGen=false
android.prefabVersion=${prefab.version}
2020-05-14 07:42:13 +08:00
Successfuly exported jsoncpp. Checkout .../vcpkg/prefab
2020-04-07 05:36:17 +08:00
```
#### The output directory after export
2020-05-14 07:42:13 +08:00
````
2020-04-07 05:36:17 +08:00
prefab
2020-05-14 07:42:13 +08:00
└── jsoncpp/
├── aar/
2020-04-07 05:36:17 +08:00
│ ├── AndroidManifest.xml
2020-05-14 07:42:13 +08:00
│ ├── META-INF/
│ │ └── LICENSE
│ └── prefab/
│ ├── modules/
│ │ └── jsoncpp/
│ │ ├── libs/
│ │ │ ├── android.arm64-v8a/
2020-04-07 05:36:17 +08:00
│ │ │ │ ├── abi.json
2020-05-14 07:42:13 +08:00
│ │ │ │ ├── include/
│ │ │ │ │ └── json/
│ │ │ │ │ ├── json.h
│ │ │ │ │ └── ....
2020-04-07 05:36:17 +08:00
│ │ │ │ └── libjsoncpp.so
2020-05-14 07:42:13 +08:00
│ │ │ ├── android.armeabi-v7a/
2020-04-07 05:36:17 +08:00
│ │ │ │ ├── abi.json
2020-05-14 07:42:13 +08:00
│ │ │ │ ├── include/
│ │ │ │ │ └── json/
│ │ │ │ │ ├── json.h
│ │ │ │ │ └── ....
2020-04-07 05:36:17 +08:00
│ │ │ │ └── libjsoncpp.so
2020-05-14 07:42:13 +08:00
│ │ │ ├── android.x86/
2020-04-07 05:36:17 +08:00
│ │ │ │ ├── abi.json
2020-05-14 07:42:13 +08:00
│ │ │ │ ├── include/
│ │ │ │ │ └── json/
│ │ │ │ │ ├── json.h
│ │ │ │ │ └── ....
2020-04-07 05:36:17 +08:00
│ │ │ │ └── libjsoncpp.so
2020-05-14 07:42:13 +08:00
│ │ │ └── android.x86_64/
2020-04-07 05:36:17 +08:00
│ │ │ ├── abi.json
2020-05-14 07:42:13 +08:00
│ │ │ ├── include/
│ │ │ │ └── json/
│ │ │ │ │ ├── json.h
│ │ │ │ │ └── ....
2020-04-07 05:36:17 +08:00
│ │ │ └── libjsoncpp.so
│ │ └── module.json
│ └── prefab.json
├── jsoncpp-1.9.2.aar
└── pom.xml
2020-05-14 07:42:13 +08:00
````
2020-04-07 05:36:17 +08:00
2020-05-14 07:42:13 +08:00
## Example consuming [jsoncpp] via vcpkg and prefab
See the example repo here:
https://github.com/atkawa7/prefab-vpkg-integration-sample