5 个版本

0.1.4 2022年7月4日
0.1.3 2022年6月21日
0.1.2 2022年6月10日
0.1.1 2021年6月21日
0.1.0 2021年6月15日

#598Cargo 插件

每月下载量 33

MIT 许可证

100KB
2K SLoC

是旧 android-rs-glue crate 的分支,兼容构建基于 miniquad 的项目。

支持的 [package.metadata.android] 条目

# The target Android API level.
# "android_version" is the compile SDK version. It defaults to 29.
# (target_sdk_version defaults to the value of "android_version")
# (min_sdk_version defaults to 18) It defaults to 18 because this is the minimum supported by rustc.
android_version = 29
target_sdk_version = 29
min_sdk_version = 26

# Specifies the array of targets to build for.
# Defaults to "armv7-linux-androideabi", "aarch64-linux-android", "i686-linux-android".
build_targets = [ "armv7-linux-androideabi", "aarch64-linux-android", "i686-linux-android", "x86_64-linux-android" ]

# The following values can be customized on a per bin/example basis. See multiple_targets example
# If a value is not specified for a secondary target, it will inherit the value defined in the `package.metadata.android`
# section unless otherwise noted.
#

# The Java package name for your application.
# Hyphens are converted to underscores.
# Defaults to rust.<target_name> for binaries. 
# Defaults to rust.<package_name>.example.<target_name> for examples.
# For example: for a binary "my_app", the default package name will be "rust.my_app"
# Secondary targets will not inherit the value defined in the root android configuration.
package_name = "rust.cargo.apk.advanced"

# The user-friendly name for your app, as displayed in the applications menu.
# Defaults to the target name
# Secondary targets will not inherit the value defined in the root android configuration.
label = "My Android App"

# Internal version number used to determine whether one version is more recent than another. Must be an integer.
# Defaults to 1
# See https://developer.android.com.cn/guide/topics/manifest/manifest-element
version_code = 2

# The version number shown to users.
# Defaults to the cargo package version number
# See https://developer.android.com.cn/guide/topics/manifest/manifest-element
version_name = "2.0"

# Path to your application's resources folder.
# If not specified, resources will not be included in the APK
res = "path/to/res_folder"

# Virtual path your application's icon for any mipmap level.
# If not specified, an icon will not be included in the APK.
icon = "@mipmap/ic_launcher"

# Path to the folder containing your application's assets.
# If not specified, assets will not be included in the APK
assets = "path/to/assets_folder"

# If set to true, makes the app run in full-screen, by adding the following line
# as an XML attribute to the manifest's <application> tag :
#     android:theme="@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen
# Defaults to false.
fullscreen = false

# The maximum supported OpenGL ES version , as claimed by the manifest.
# Defaults to 2.0.
# See https://developer.android.com.cn/guide/topics/graphics/opengl.html#manifest
opengles_version_major = 3
opengles_version_minor = 2

# Adds extra arbitrary XML attributes to the <application> tag in the manifest.
# See https://developer.android.com.cn/guide/topics/manifest/application-element.html
[package.metadata.android.application_attributes]
"android:debuggable" = "true"
"android:hardwareAccelerated" = "true"

# Adds extra arbitrary XML attributes to the <activity> tag in the manifest.
# See https://developer.android.com.cn/guide/topics/manifest/activity-element.html
[package.metadata.android.activity_attributes]
"android:screenOrientation" = "unspecified"
"android:uiOptions" = "none"

# Adds a uses-feature element to the manifest
# Supported keys: name, required, version
# The glEsVersion attribute is not supported using this section. 
# It can be specified using the opengles_version_major and opengles_version_minor values
# See https://developer.android.com.cn/guide/topics/manifest/uses-feature-element
[[package.metadata.android.feature]]
name = "android.hardware.camera"

[[package.metadata.android.feature]]
name = "android.hardware.vulkan.level"
version = "1"
required = false

# Adds a uses-permission element to the manifest.
# Note that android_version 23 and higher, Android requires the application to request permissions at runtime.
# There is currently no way to do this using a pure NDK based application.
# See https://developer.android.com.cn/guide/topics/manifest/uses-permission-element
[[package.metadata.android.permission]]
name = "android.permission.WRITE_EXTERNAL_STORAGE"
max_sdk_version = 18

[[package.metadata.android.permission]]
name = "android.permission.CAMERA"

环境变量

Cargo-apk 设置环境变量,用于将适当的 C 和 C++ 编译工具暴露给构建脚本。主要目的是支持具有使用 cccmake crate 的构建脚本的 crate。

  • CC:NDK 提供的对应目标和 android 平台 clang 包装器的路径。
  • CXX:NDK 提供的对应目标和 android 平台 clang++ 包装器的路径。
  • AR:NDK 提供的 ar 的路径。
  • CXXSTDLIB:使用 NDK 提供的完整功能的 C++ 标准库。
  • CMAKE_TOOLCHAIN_FILE:生成 CMake 工具链的路径。此工具链设置 ABI,覆盖任何指定的目标,并包含 NDK 提供的工具链。
  • CMAKE_GENERATOR:默认为 Unix Makefiles,而不是使用可能不适合平台的 CMake 默认值。
  • CMAKE_MAKE_PROGRAM:NDK 提供的 make 的路径。

C++ 标准库兼容性问题

当 crate 链接到 C++ 标准库时,使用 NDK 提供的共享库版本。不幸的是,依赖项加载问题会导致应用程序在较旧的 android 版本上崩溃。一旦所有平台上解决 lld 链接器问题,cargo apk 将更新为链接到静态 C++ 库。这应该解决兼容性问题。

依赖项

~37–49MB
~1M SLoC