-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Android Support: Exporting to Android Archive (AAR) #10271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dan-shaw
merged 15 commits into
microsoft:master
from
atkawa7:allen/feature/android-support
Apr 6, 2020
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fbbefac
added android triplets
atkawa7 73a42da
added android support to vcpkg
atkawa7 9180b99
added export directories to git ignore
atkawa7 188f55e
fix libraries naming
atkawa7 db08b93
added vckpg sources to visual studio project files
atkawa7 64493d2
rename file location
atkawa7 a0a58f4
issue with std::string fs:path copy initialization
atkawa7 1be40f4
format path on VStudio
atkawa7 6542bb8
fix checks format cannot work on fs::path
atkawa7 5abe619
support header only libraries
atkawa7 45c51b9
merge current master
atkawa7 a9e267c
support using architecture instead of triplets
atkawa7 2dc6600
added prefab support
atkawa7 58bda31
added debug logs and prefab debug flag
atkawa7 1e1ccd9
added support for empty packages i.e openssl
atkawa7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| ## Exporting to Android Archives (AAR files) | ||
|
|
||
| Vcpkg current supports exporting to android archive files([AAR files](https://developer.android.com/studio/projects/android-library)). Once the 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). For more information on Prefab checkout the following article ["Native Dependencies in Android Studio 4.0"](https://android-developers.googleblog.com/2020/02/native-dependencies-in-android-studio-40.html) and the documentation on how to use prefab on [https://google.github.io/prefab/](https://google.github.io/prefab). | ||
|
|
||
| #### To support export to android the following tools should be available; | ||
|
|
||
| - `maven <optional>` | ||
| - `ndk <required>` | ||
| - `7zip <required on windows>` or `zip <required on linux>` | ||
|
|
||
| **Android triplets that support the following architectures arm64-v8a, armeabi-v7a, x86_64 x86 must be present** | ||
|
|
||
| #### An example of a triplet configuration targeting android would be | ||
|
|
||
| ```cmake | ||
| set(VCPKG_TARGET_ARCHITECTURE arm64) | ||
| set(VCPKG_CRT_LINKAGE dynamic) | ||
| set(VCPKG_LIBRARY_LINKAGE dynamic) | ||
| set(VCPKG_CMAKE_SYSTEM_NAME Android) | ||
| ``` | ||
|
|
||
| The following table outlines the mapping from vcpkg architectures to android architectures | ||
|
|
||
| |vcpkg architecture | android architecture | | ||
| |-------------------|----------------------| | ||
| |arm64 | arm64-v8a | | ||
| |arm | armeabi-v7a | | ||
| |x64 | x86_64 | | ||
| |x86 | x86 | | ||
|
|
||
| **Please note the four architectures are required. If any is missing the export will fail** | ||
| **To export the following environment `ANDROID_NDK_HOME` variable is required for exporting** | ||
|
|
||
| #### Example exporting [jsoncpp] | ||
| The `--prefab-maven` flag is option. Only call it when you have maven installed | ||
| ``` | ||
| ./vcpkg export --triplet x64-android jsoncpp --prefab --prefab-maven | ||
| ``` | ||
|
|
||
| ``` | ||
| The following packages are already built and will be exported: | ||
| jsoncpp:x86-android | ||
| Exporting package jsoncpp... | ||
| [INFO] Scanning for projects... | ||
| [INFO] | ||
| [INFO] ------------------< org.apache.maven:standalone-pom >------------------- | ||
| [INFO] Building Maven Stub Project (No POM) 1 | ||
| [INFO] --------------------------------[ pom ]--------------------------------- | ||
| [INFO] | ||
| [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom --- | ||
| [INFO] Installing<root>/prefab/jsoncpp/jsoncpp-1.9.2.aar to /.m2/repository/com/vcpkg/ndk/support/jsoncpp/1.9.2/jsoncpp-1.9.2.aar | ||
| [INFO] Installing <vcpkg_root>/prefab/jsoncpp/pom.xml to /.m2/repository/com/vcpkg/ndk/support/jsoncpp/1.9.2/jsoncpp-1.9.2.pom | ||
| [INFO] ------------------------------------------------------------------------ | ||
| [INFO] BUILD SUCCESS | ||
| [INFO] ------------------------------------------------------------------------ | ||
| [INFO] Total time: 0.301 s | ||
| [INFO] Finished at: 2020-03-01T10:18:15Z | ||
| [INFO] ------------------------------------------------------------------------ | ||
| In app/build.gradle | ||
|
|
||
| com.vcpkg.ndk.support:jsoncpp:1.9.2 | ||
|
|
||
| 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} | ||
|
|
||
| Successfuly exported jsoncpp. Checkout <vcpkg_root>/prefab/jsoncpp/aar | ||
| ``` | ||
|
|
||
| #### The output directory after export | ||
| ``` | ||
| prefab | ||
| └── jsoncpp | ||
| ├── aar | ||
| │ ├── AndroidManifest.xml | ||
| │ ├── META-INF | ||
| │ │ └── LICENCE | ||
| │ └── prefab | ||
| │ ├── modules | ||
| │ │ └── jsoncpp | ||
| │ │ ├── include | ||
| │ │ │ └── json | ||
| │ │ │ ├── allocator.h | ||
| │ │ │ ├── assertions.h | ||
| │ │ │ ├── autolink.h | ||
| │ │ │ ├── config.h | ||
| │ │ │ ├── forwards.h | ||
| │ │ │ ├── json.h | ||
| │ │ │ ├── json_features.h | ||
| │ │ │ ├── reader.h | ||
| │ │ │ ├── value.h | ||
| │ │ │ ├── version.h | ||
| │ │ │ └── writer.h | ||
| │ │ ├── libs | ||
| │ │ │ ├── android.arm64-v8a | ||
| │ │ │ │ ├── abi.json | ||
| │ │ │ │ └── libjsoncpp.so | ||
| │ │ │ ├── android.armeabi-v7a | ||
| │ │ │ │ ├── abi.json | ||
| │ │ │ │ └── libjsoncpp.so | ||
| │ │ │ ├── android.x86 | ||
| │ │ │ │ ├── abi.json | ||
| │ │ │ │ └── libjsoncpp.so | ||
| │ │ │ └── android.x86_64 | ||
| │ │ │ ├── abi.json | ||
| │ │ │ └── libjsoncpp.so | ||
| │ │ └── module.json | ||
| │ └── prefab.json | ||
| ├── jsoncpp-1.9.2.aar | ||
| └── pom.xml | ||
|
|
||
| 13 directories, 25 files | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #pragma once | ||
|
|
||
| #include <vcpkg/base/system.h> | ||
| #include <vcpkg/dependencies.h> | ||
| #include <vcpkg/vcpkgpaths.h> | ||
|
|
||
|
|
||
| #include <vector> | ||
|
|
||
| namespace vcpkg::Export::Prefab | ||
| { | ||
| constexpr int kFragmentSize = 3; | ||
|
|
||
| struct Options | ||
| { | ||
| Optional<std::string> maybe_group_id; | ||
| Optional<std::string> maybe_artifact_id; | ||
| Optional<std::string> maybe_version; | ||
| Optional<std::string> maybe_min_sdk; | ||
| Optional<std::string> maybe_target_sdk; | ||
| bool enable_maven; | ||
| bool enable_debug; | ||
| }; | ||
| struct NdkVersion | ||
| { | ||
| NdkVersion(int _major, int _minor, int _patch) : m_major{_major}, | ||
| m_minor{_minor}, | ||
| m_patch{_patch}{ | ||
| } | ||
| int major() { return this->m_major; } | ||
| int minor() { return this->m_minor; } | ||
| int patch() { return this->m_patch; } | ||
| std::string to_string(); | ||
| void to_string(std::string& out); | ||
|
|
||
| private: | ||
| int m_major; | ||
| int m_minor; | ||
| int m_patch; | ||
| }; | ||
|
|
||
| struct ABIMetadata | ||
| { | ||
| std::string abi; | ||
| int api; | ||
| int ndk; | ||
| std::string stl; | ||
| std::string to_string(); | ||
| }; | ||
|
|
||
| struct PlatformModuleMetadata | ||
| { | ||
| std::vector<std::string> export_libraries; | ||
| std::string library_name; | ||
| std::string to_json(); | ||
| }; | ||
|
|
||
| struct ModuleMetadata | ||
| { | ||
| std::vector<std::string> export_libraries; | ||
| std::string library_name; | ||
| PlatformModuleMetadata android; | ||
| std::string to_json(); | ||
| }; | ||
|
|
||
| struct PackageMetadata | ||
| { | ||
| std::string name; | ||
| int schema; | ||
| std::vector<std::string> dependencies; | ||
| std::string version; | ||
| std::string to_json(); | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| void do_export(const std::vector<Dependencies::ExportPlanAction>& export_plan, | ||
| const VcpkgPaths& paths, | ||
| const Options& prefab_options, const Triplet& triplet); | ||
| Optional<std::string> find_ndk_version(const std::string &content); | ||
| Optional<NdkVersion> to_version(const std::string &version); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.