Awesome
<div align="center"> <a href="https://xmake.io"> <img width="200" heigth="200" src="https://tboox.org/static/img/xmake/logo256c.png"> </a> <h1>xmake-gradle</h1> <div> <a href="https://github.com/xmake-io/xmake-gradle/releases"> <img src="https://img.shields.io/github/release/xmake-io/xmake-gradle.svg?style=flat-square" alt="Github All Releases" /> </a> <a href="https://github.com/xmake-io/xmake-gradle/blob/master/LICENSE.md"> <img src="https://img.shields.io/github/license/xmake-io/xmake.svg?colorB=f48041&style=flat-square" alt="license" /> </a> </div> <div> <a href="https://www.reddit.com/r/tboox/"> <img src="https://img.shields.io/badge/chat-on%20reddit-ff3f34.svg?style=flat-square" alt="Reddit" /> </a> <a href="https://gitter.im/tboox/tboox?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"> <img src="https://img.shields.io/gitter/room/tboox/tboox.svg?style=flat-square&colorB=96c312" alt="Gitter" /> </a> <a href="https://t.me/tbooxorg"> <img src="https://img.shields.io/badge/chat-on%20telegram-blue.svg?style=flat-square" alt="Telegram" /> </a> <a href="https://jq.qq.com/?_wv=1027&k=5hpwWFv"> <img src="https://img.shields.io/badge/chat-on%20QQ-ff69b4.svg?style=flat-square" alt="QQ" /> </a> <a href="https://xmake.io/#/sponsor"> <img src="https://img.shields.io/badge/donate-us-orange.svg?style=flat-square" alt="Donate" /> </a> </div> <p>A gradle plugin that integrates xmake seamlessly</p> </div>Introduction (中文)
xmake-gradle is a gradle plugin that integrates xmake seamlessly.
If you want to know more, please refer to:
Prerequisites
XMake installed on the system. Available here.
Apply the plugin
plugins DSL
plugins {
id 'org.tboox.gradle-xmake-plugin' version '1.2.2'
}
Legacy plugin application
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.tboox:gradle-xmake-plugin:1.2.2'
}
repositories {
mavenCentral()
}
}
apply plugin: "org.tboox.gradle-xmake-plugin"
Configuation
Simplest Example
We add xmake.lua
to projectdir/jni/xmake.lua
and enable xmake in build.gradle.
build.gradle
android {
externalNativeBuild {
xmake {
path "jni/xmake.lua"
}
}
}
JNI
The JNI project structure:
projectdir
- src
- main
- java
- jni
- xmake.lua
- *.cpp
xmake.lua:
add_rules("mode.debug", "mode.release")
target("nativelib")
set_kind("shared")
add_files("nativelib.cc")
More Gradle Configuations
android {
defaultConfig {
externalNativeBuild {
xmake {
// append the global cflags (optional)
cFlags "-DTEST"
// append the global cppflags (optional)
cppFlags "-DTEST", "-DTEST2"
// switch the build mode to `debug` for `xmake f -m debug` (optional)
buildMode "debug"
// set abi filters (optional), e.g. armeabi, armeabi-v7a, arm64-v8a, x86, x86_64
// we can also get abiFilters from defaultConfig.ndk.abiFilters
abiFilters "armeabi-v7a", "arm64-v8a"
// set the built targets
//targets "xxx", "yyy"
}
}
}
externalNativeBuild {
xmake {
// enable xmake and set xmake.lua project file path
path "jni/xmake.lua"
// enable verbose output (optional), e.g. verbose, normal
logLevel "verbose"
// set c++stl (optional), e.g. c++_static/c++_shared, gnustl_static/gnustl_shared, stlport_static/stlport_shared
stl "c++_shared"
// set the given xmake program path (optional)
// program /usr/local/bin/xmake
// disable stdc++ library (optional)
// stdcxx false
// set the given ndk directory path (optional)
// ndk "/Users/ruki/files/android-ndk-r20b/"
// set sdk version of ndk (optional)
// sdkver 21
}
}
}
Build
Build JNI and generate apk
The xmakeBuild
will be injected to assemble
task automatically if the gradle-xmake-plugin has been applied.
$ ./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
Force to rebuild JNI
$ ./gradlew nativelib:xmakeRebuild
Development
Build Plugins
$ ./gradlew gradle-xmake-plugin:assemble
Publish Plugins
see https://guides.gradle.org/publishing-plugins-to-gradle-plugin-portal/
$ ./gradlew gradle-xmake-plugin:publishPlugins
Contacts
- Email:waruqi@gmail.com
- Homepage:xmake.io
- Community
- Chat on Reddit
- Chat on Telegram
- Chat on Discord
- Chat on QQ Group: 343118190, 662147501
- Source Code:GitHub, Gitee
- WeChat Public: tboox-os
Backers
Thank you to all our backers! 🙏 [Become a backer]
<a href="https://opencollective.com/xmake#backers" target="_blank"><img src="https://opencollective.com/xmake/backers.svg?width=890"></a>
Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
<a href="https://opencollective.com/xmake/sponsor/0/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/0/avatar.svg"></a> <a href="https://opencollective.com/xmake/sponsor/1/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/1/avatar.svg"></a> <a href="https://opencollective.com/xmake/sponsor/2/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/2/avatar.svg"></a> <a href="https://opencollective.com/xmake/sponsor/3/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/3/avatar.svg"></a> <a href="https://opencollective.com/xmake/sponsor/4/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/4/avatar.svg"></a> <a href="https://opencollective.com/xmake/sponsor/5/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/5/avatar.svg"></a> <a href="https://opencollective.com/xmake/sponsor/6/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/6/avatar.svg"></a> <a href="https://opencollective.com/xmake/sponsor/7/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/7/avatar.svg"></a> <a href="https://opencollective.com/xmake/sponsor/8/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/8/avatar.svg"></a> <a href="https://opencollective.com/xmake/sponsor/9/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/9/avatar.svg"></a>