简介
xmake-gradle是一个插件xmake的gradle。
准备工作
我们需要安装好安装的xmake先行工具,关于安装xmake。
应用插件
通过插件DSL集成
plugins {
id 'org.tboox.gradle-xmake-plugin' version '1.1.5'
}
被废弃的插件集成方式
buildscript {
repositories {
maven {
url
}
}
dependencies {
classpath 'org.tboox:gradle-xmake-plugin:1.1.5'
}
repositories {
mavenCentral()
}
}
apply plugin: "org.tboox.gradle-xmake-plugin"
配置
最简单的配置示例
如果将文件添加xmake.lua到projectdir/jni/xmake.lua,那么我们只需要在 build.gradle 中启用了 xmake 指定下的 JNI 工程路径即可。
构建.gradle
android {
externalNativeBuild {
xmake {
path "jni/xmake.lua"
}
}
}
JNI
JNI工程结构
projectdir
- src
- jni
- xmake.lua
- *.cpp
xmake.lua:
add_rules("mode.debug", "mode.release")
target("nativelib")
set_kind("shared")
add_files("nativelib.cc")
更多Gradle配置说明
android {
defaultConfig {
externalNativeBuild {
xmake {
// 追加设置全局c编译flags
cFlags "-DTEST"
cppFlags "-DTEST", "-DTEST2"
buildMode "debug"
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
}
externalNativeBuild {
xmake {
path "jni/xmake.lua"
logLevel "verbose"
stl "c++_shared"
}
}
}
编译JNI
编译JNI并生成APK
当gradle-xmake-plugin被应用生效后,xmakeBuild任务会自动插入到现有的assemble任务中去,执行jni库编译和自动集成。
$ ./gradlew app:assembleDebug
Task :nativelib:xmakeConfigureForArm64
Task :nativelib:xmakeBuildForArm64
xmake build
[ 50%]: ccache compiling.debug nativelib.cc
[ 75%]: linking.debug libnativelib.so
[100%]: build ok!
install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/arm64-v8a
Task :nativelib:xmakeConfigureForArmv7
Task :nativelib:xmakeBuildForArmv7
xmake build
[ 50%]: ccache compiling.debug nativelib.cc
[ 75%]: linking.debug libnativelib.so
[100%]: build ok!
install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/armeabi-v7a
Task :nativelib:preBuild
Task :nativelib:assemble
Task :app:assembleDebug
强制重建JNI
$ ./gradlew nativelib:xmakeRebuild
发展
编译插件
$ ./gradlew gradle-xmake-plugin:assemble
发布插件
$ ./gradlew gradle-xmake-plugin:publishPlugins
原作者:xmake-io
|