├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── org │ │ │ │ └── tboox │ │ │ │ └── xmake │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── org │ │ │ └── tboox │ │ │ └── xmake │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── org │ │ └── tboox │ │ └── xmake │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── nativelib ├── consumer-rules.pro ├── .gitignore ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── cpp │ │ │ ├── .gitignore │ │ │ ├── Application.mk │ │ │ ├── CMakeLists.txt │ │ │ ├── Android.mk │ │ │ ├── nativelib.cc │ │ │ └── xmake.lua │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ └── java │ │ │ └── org │ │ │ └── tboox │ │ │ └── xmake │ │ │ └── nativelib │ │ │ └── Test.java │ ├── test │ │ └── java │ │ │ └── org │ │ │ └── tboox │ │ │ └── xmake │ │ │ └── nativelib │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── org │ │ └── tboox │ │ └── xmake │ │ └── nativelib │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── gradle-xmake-plugin ├── .gitignore ├── build.gradle └── src │ └── main │ ├── groovy │ └── org │ │ └── tboox │ │ └── gradle │ │ ├── XMakeLogger.groovy │ │ ├── XMakeExecutor.groovy │ │ ├── XMakeInstallTask.groovy │ │ ├── XMakePluginExtension.groovy │ │ ├── XMakeRebuildTask.groovy │ │ ├── XMakeBuildTask.groovy │ │ ├── XMakeCleanTask.groovy │ │ ├── XMakeConfigureTask.groovy │ │ ├── XMakeTaskContext.groovy │ │ └── XMakePlugin.groovy │ └── resources │ └── lua │ └── install_artifacts.lua ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── CHANGELOG.md ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── CONTRIBUTING.md ├── README_zh.md ├── README.md ├── gradlew └── LICENSE.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /nativelib/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /nativelib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':nativelib', ':gradle-xmake-plugin' 2 | rootProject.name='xmake-gradle' 3 | -------------------------------------------------------------------------------- /nativelib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | xmake-gradle 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /nativelib/src/main/cpp/.gitignore: -------------------------------------------------------------------------------- 1 | # Xmake cache 2 | .xmake/ 3 | build/ 4 | 5 | # MacOS Cache 6 | .DS_Store 7 | 8 | 9 | -------------------------------------------------------------------------------- /nativelib/src/main/cpp/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := armeabi-v7a arm64-v8a 2 | APP_STL := c++_shared 3 | APP_OPTIM := release 4 | -------------------------------------------------------------------------------- /nativelib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | NativeLib 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-io/xmake-gradle/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /nativelib/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # project 2 | cmake_minimum_required(VERSION 3.6.0) 3 | 4 | # target 5 | add_library(nativelib SHARED "") 6 | target_compile_options(nativelib PRIVATE -O0 -g) 7 | target_sources(nativelib PRIVATE 8 | nativelib.cc 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog ([中文](#中文)) 2 | 3 | ## master (unreleased) 4 | 5 | ### New features 6 | 7 | ### Change 8 | 9 | ### Bugs fixed 10 | 11 |

12 | 13 | # 更新日志 14 | 15 | ## master (开发中) 16 | 17 | ### 新特性 18 | 19 | ### 改进 20 | 21 | ### Bugs修复 22 | 23 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /nativelib/src/main/java/org/tboox/xmake/nativelib/Test.java: -------------------------------------------------------------------------------- 1 | package org.tboox.xmake.nativelib; 2 | 3 | public class Test { 4 | 5 | public static String loadTests() { 6 | //System.loadLibrary("c++_shared"); 7 | System.loadLibrary("nativelib"); 8 | return getNativeInfo(); 9 | } 10 | public static native String getNativeInfo(); 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # MacOS Cache 2 | .DS_Store 3 | 4 | # Xmake cache 5 | .xmake/ 6 | build/ 7 | 8 | # for VS Code 9 | .vscode/ 10 | 11 | # for vim 12 | *.swp 13 | *.swo 14 | tags 15 | !tags/ 16 | 17 | # For gradle & idea 18 | local.properties 19 | .gradle 20 | .idea 21 | *.iml 22 | 23 | # for build 24 | *.so 25 | .cxx 26 | libs 27 | 28 | # Ignore packaging files 29 | *.exe 30 | *.zip 31 | *.gz 32 | *.bz2 33 | *.xz 34 | *.7z 35 | *.run 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/org/tboox/xmake/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package org.tboox.xmake; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /nativelib/src/test/java/org/tboox/xmake/nativelib/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package org.tboox.xmake.nativelib; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/java/org/tboox/xmake/MainActivity.java: -------------------------------------------------------------------------------- 1 | package org.tboox.xmake; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.widget.TextView; 6 | import org.tboox.xmake.nativelib.Test; 7 | 8 | 9 | public class MainActivity extends AppCompatActivity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_main); 15 | String content = Test.loadTests(); 16 | if (content != null) { 17 | TextView textView = (TextView) findViewById(R.id.content); 18 | textView.setText(content); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /nativelib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/org/tboox/xmake/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package org.tboox.xmake; 2 | 3 | import android.content.Context; 4 | import androidx.test.platform.app.InstrumentationRegistry; 5 | import androidx.test.ext.junit.runners.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 23 | 24 | assertEquals("org.tboox.xmake", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 19 | 20 | -------------------------------------------------------------------------------- /nativelib/src/androidTest/java/org/tboox/xmake/nativelib/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package org.tboox.xmake.nativelib; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | 25 | assertEquals("org.tboox.xmake.nativelib.test", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /nativelib/src/main/cpp/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | DEBUG := n 19 | CRYPT := n 20 | LOCAL_MODULE := nativelib 21 | LOCAL_SRC_FILES := nativelib.cc 22 | LOCAL_CXXFLAGS := -g -O0 23 | LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -L$(LOCAL_PATH) -llog -lz 24 | include $(BUILD_SHARED_LIBRARY) 25 | 26 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | 19 | # AndroidX package structure to make it clearer which packages are bundled with the 20 | # Android operating system, and which are packaged with your app's APK 21 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 22 | android.useAndroidX=true 23 | # Automatically convert third-party libraries to use AndroidX 24 | android.enableJetifier=true 25 | 26 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | namespace "org.tboox.xmake" 5 | compileSdkVersion 36 6 | defaultConfig { 7 | applicationId "org.tboox.xmake" 8 | minSdkVersion 30 9 | targetSdkVersion 36 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | java { 24 | toolchain { 25 | languageVersion = JavaLanguageVersion.of(17) 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation fileTree(dir: 'libs', include: ['*.jar']) 31 | implementation 'androidx.appcompat:appcompat:1.0.2' 32 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 33 | testImplementation 'junit:junit:4.12' 34 | androidTestImplementation 'androidx.test.ext:junit:1.1.0' 35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' 36 | implementation project(path: ':nativelib') 37 | } 38 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | // to publish the plugin at the gradle plugin portal 3 | id "com.gradle.plugin-publish" version "1.3.1" 4 | // Apply the java-library plugin to add support for Java Library 5 | id 'java-gradle-plugin' 6 | id 'maven-publish' 7 | } 8 | apply plugin: 'groovy' 9 | 10 | group = "org.tboox" 11 | version = "1.2.3" 12 | 13 | repositories { 14 | // Use mavenCentral for resolving your dependencies. 15 | // You can declare any Maven/Ivy/file repository here. 16 | mavenCentral() 17 | } 18 | 19 | dependencies { 20 | implementation localGroovy() 21 | implementation gradleApi() 22 | // Use JUnit test framework 23 | testImplementation 'junit:junit:4.12' 24 | compileOnly "com.android.tools.build:gradle:8.10.0" 25 | } 26 | 27 | gradlePlugin { 28 | plugins { 29 | xmakePlugin { 30 | description = 'A gradle plugin that integrates xmake seamlessly' 31 | displayName = 'Gradle XMake plugin' 32 | id = 'org.tboox.gradle-xmake-plugin' 33 | implementationClass = 'org.tboox.gradle.XMakePlugin' 34 | tags = ['xmake', 'c++', 'lua'] 35 | vcsUrl = 'https://github.com/xmake-io/xmake-gradle' 36 | website = 'https://github.com/xmake-io/xmake-gradle' 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /nativelib/src/main/cpp/nativelib.cc: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file nativelib.c 19 | * 20 | */ 21 | 22 | /* ////////////////////////////////////////////////////////////////////////////////////// 23 | * includes 24 | */ 25 | #include 26 | #include 27 | #include 28 | 29 | /* ////////////////////////////////////////////////////////////////////////////////////// 30 | * private implementation 31 | */ 32 | 33 | /* ////////////////////////////////////////////////////////////////////////////////////// 34 | * interfaces 35 | */ 36 | extern "C" 37 | { 38 | JNIEXPORT jstring Java_org_tboox_xmake_nativelib_Test_getNativeInfo(JNIEnv* env, jclass jthis, jobject context) 39 | { 40 | return env->NewStringUTF("hello xmake!"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/groovy/org/tboox/gradle/XMakeLogger.groovy: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file XMakeLogger.groovy 19 | * 20 | */ 21 | package org.tboox.gradle 22 | 23 | import org.gradle.api.logging.Logger 24 | import org.gradle.api.logging.Logging 25 | 26 | class XMakeLogger { 27 | 28 | // the logger 29 | private final Logger logger = Logging.getLogger("xmake") 30 | 31 | // enable verbose output? 32 | private XMakePluginExtension extension 33 | 34 | // the constructor 35 | XMakeLogger(XMakePluginExtension extension) { 36 | this.extension = extension 37 | } 38 | 39 | // print the verbose output 40 | void v(String msg) { 41 | if (extension.logLevel != null && extension.logLevel == "verbose") { 42 | logger.warn(msg) 43 | } 44 | } 45 | 46 | // print the verbose output 47 | void v(String tag, String msg) { 48 | v("[xmake/" + tag + "]: " + msg) 49 | } 50 | 51 | // print the info output 52 | void i(String msg) { 53 | logger.warn(msg) 54 | } 55 | 56 | // print the info output 57 | void i(String tag, String msg) { 58 | i("[xmake/" + tag + "]: " + msg) 59 | } 60 | 61 | // print the error output 62 | void e(String msg) { 63 | logger.warn(msg) 64 | } 65 | 66 | // print the error output 67 | void e(String tag, String msg) { 68 | e("[xmake/" + tag + "]: " + msg) 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /nativelib/src/main/cpp/xmake.lua: -------------------------------------------------------------------------------- 1 | add_rules("mode.debug", "mode.release") 2 | 3 | add_requires("libpng", {configs = {shared = true}}) 4 | 5 | target("nativelib") 6 | set_kind("shared") 7 | add_files("nativelib.cc") 8 | add_packages("libpng") 9 | 10 | -- 11 | -- FAQ 12 | -- 13 | -- You can enter the project directory firstly before building project. 14 | -- 15 | -- $ cd projectdir 16 | -- 17 | -- 1. How to build project? 18 | -- 19 | -- $ xmake 20 | -- 21 | -- 2. How to configure project? 22 | -- 23 | -- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] 24 | -- 25 | -- 3. Where is the build output directory? 26 | -- 27 | -- The default output directory is `./build` and you can configure the output directory. 28 | -- 29 | -- $ xmake f -o outputdir 30 | -- $ xmake 31 | -- 32 | -- 4. How to run and debug target after building project? 33 | -- 34 | -- $ xmake run [targetname] 35 | -- $ xmake run -d [targetname] 36 | -- 37 | -- 5. How to install target to the system directory or other output directory? 38 | -- 39 | -- $ xmake install 40 | -- $ xmake install -o installdir 41 | -- 42 | -- 6. Add some frequently-used compilation flags in xmake.lua 43 | -- 44 | -- @code 45 | -- -- add debug and release modes 46 | -- add_rules("mode.debug", "mode.release") 47 | -- 48 | -- -- add macro defination 49 | -- add_defines("NDEBUG", "_GNU_SOURCE=1") 50 | -- 51 | -- -- set warning all as error 52 | -- set_warnings("all", "error") 53 | -- 54 | -- -- set language: c99, c++11 55 | -- set_languages("c99", "c++11") 56 | -- 57 | -- -- set optimization: none, faster, fastest, smallest 58 | -- set_optimize("fastest") 59 | -- 60 | -- -- add include search directories 61 | -- add_includedirs("/usr/include", "/usr/local/include") 62 | -- 63 | -- -- add link libraries and search directories 64 | -- add_links("tbox") 65 | -- add_linkdirs("/usr/local/lib", "/usr/lib") 66 | -- 67 | -- -- add system link libraries 68 | -- add_syslinks("z", "pthread") 69 | -- 70 | -- -- add compilation and link flags 71 | -- add_cxflags("-stdnolib", "-fno-strict-aliasing") 72 | -- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) 73 | -- 74 | -- @endcode 75 | -- 76 | -- 7. If you want to known more usage about xmake, please see https://xmake.io 77 | -- 78 | 79 | -------------------------------------------------------------------------------- /nativelib/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.tboox.gradle-xmake-plugin' version '1.2.3' 3 | } 4 | apply plugin: 'com.android.library' 5 | //apply plugin: "org.tboox.gradle-xmake-plugin" 6 | 7 | android { 8 | namespace "org.tboox.xmake.nativelib" 9 | compileSdkVersion 36 10 | 11 | defaultConfig { 12 | minSdkVersion 30 13 | targetSdkVersion 36 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | consumerProguardFiles 'consumer-rules.pro' 17 | 18 | ndk { 19 | abiFilters "armeabi-v7a", "arm64-v8a", "x86_64", "x86" 20 | } 21 | 22 | externalNativeBuild { 23 | 24 | /* 25 | cmake { 26 | cppFlags "-DTEST" 27 | abiFilters "armeabi-v7a", "arm64-v8a", "x86_64" 28 | }*/ 29 | 30 | /* 31 | xmake { 32 | cppFlags "-DTEST", "-DTEST2" 33 | abiFilters "armeabi-v7a", "arm64-v8a", "x86_64" 34 | }*/ 35 | } 36 | } 37 | 38 | externalNativeBuild { 39 | 40 | /* 41 | ndkBuild { 42 | path "jni/Android.mk" 43 | } 44 | */ 45 | 46 | /* 47 | cmake { 48 | version "3.22.1" 49 | path "src/main/cpp/CMakeLists.txt" 50 | }*/ 51 | 52 | /* 53 | xmake { 54 | logLevel "verbose" 55 | path "src/main/cpp/xmake.lua" 56 | buildMode "debug" 57 | //arguments "--test=y" 58 | //program /usr/local/bin/xmake 59 | stl "c++_shared" 60 | //stdcxx false 61 | //ndk "/Users/ruki/files/android-ndk-r20b/" 62 | //sdkver 21 63 | }*/ 64 | } 65 | 66 | buildTypes { 67 | 68 | release { 69 | minifyEnabled false 70 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 71 | } 72 | } 73 | } 74 | 75 | java { 76 | toolchain { 77 | languageVersion = JavaLanguageVersion.of(17) 78 | } 79 | } 80 | 81 | dependencies { 82 | implementation fileTree(dir: 'libs', include: ['*.jar']) 83 | implementation 'androidx.appcompat:appcompat:1.0.2' 84 | testImplementation 'junit:junit:4.12' 85 | androidTestImplementation 'androidx.test.ext:junit:1.1.0' 86 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' 87 | } 88 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH= 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/groovy/org/tboox/gradle/XMakeExecutor.groovy: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License") 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file XMakeExecutor.groovy 19 | * 20 | */ 21 | package org.tboox.gradle 22 | 23 | import org.gradle.api.GradleException 24 | import org.gradle.api.GradleScriptException 25 | 26 | class XMakeExecutor { 27 | 28 | // tag 29 | private final String TAG = "executor" 30 | 31 | // show command? 32 | private boolean showCommand = true 33 | 34 | // the logger 35 | XMakeLogger logger 36 | 37 | // the constructor 38 | XMakeExecutor(XMakeLogger logger) { 39 | this.logger = logger 40 | } 41 | XMakeExecutor(XMakeLogger logger, boolean showCommand) { 42 | this.logger = logger 43 | this.showCommand = showCommand 44 | } 45 | 46 | // execute process 47 | protected void exec(List cmdLine, File workingFolder) throws GradleException { 48 | 49 | // log command line parameters 50 | StringBuilder sb = new StringBuilder(">> ") 51 | for (String s : cmdLine) { 52 | sb.append(s).append(" ") 53 | } 54 | if (showCommand) { 55 | logger.i(sb.toString()) 56 | } 57 | 58 | // build process 59 | ProcessBuilder pb = new ProcessBuilder(cmdLine) 60 | pb.directory(workingFolder) 61 | try { 62 | 63 | // make sure working folder exists 64 | workingFolder.mkdirs() 65 | 66 | // start process 67 | Process process = pb.start() 68 | 69 | // get process output 70 | BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())) 71 | BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())) 72 | String line 73 | while ((line = reader.readLine()) != null) { 74 | logger.i(line) 75 | } 76 | if ( null != (line = errorReader.readLine()) ) { 77 | logger.e("errors: ") 78 | while (line != null) { 79 | logger.e(line) 80 | line = errorReader.readLine() 81 | } 82 | } 83 | 84 | // wait for process exit 85 | int retCode = process.waitFor() 86 | if (retCode != 0) 87 | throw new GradleException("exec failed( " + retCode + ")") 88 | } 89 | catch (IOException e) { 90 | throw new GradleScriptException(TAG, e) 91 | } 92 | catch (InterruptedException e) { 93 | throw new GradleScriptException(TAG, e) 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/groovy/org/tboox/gradle/XMakeInstallTask.groovy: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file XMakeInstallTask.groovy 19 | * 20 | */ 21 | package org.tboox.gradle 22 | 23 | import org.gradle.api.DefaultTask 24 | import org.gradle.api.tasks.TaskAction 25 | import org.gradle.api.tasks.Internal 26 | 27 | class XMakeInstallTask extends DefaultTask { 28 | 29 | // the task context 30 | @Internal 31 | XMakeTaskContext taskContext 32 | 33 | // the constructor 34 | XMakeInstallTask() { 35 | setGroup("xmake") 36 | setDescription("Do install artifacts with XMake") 37 | } 38 | 39 | // build command line 40 | private List buildCmdLine(File installArtifactsScriptFile) { 41 | List parameters = new ArrayList<>() 42 | parameters.add(taskContext.program) 43 | parameters.add("lua") 44 | switch (taskContext.logLevel) { 45 | case "verbose": 46 | parameters.add("-v") 47 | break 48 | case "debug": 49 | parameters.add("-vD") 50 | break 51 | default: 52 | break 53 | } 54 | parameters.add(installArtifactsScriptFile.absolutePath) 55 | 56 | // pass app/libs directory 57 | parameters.add("-o") 58 | parameters.add(taskContext.nativeLibsDir.absolutePath) 59 | 60 | // pass arch 61 | parameters.add("-a") 62 | parameters.add(taskContext.buildArch) 63 | 64 | // pass targets 65 | Set targets = taskContext.targets 66 | if (targets != null && targets.size() > 0) { 67 | for (String target: targets) { 68 | parameters.add(target) 69 | } 70 | } 71 | return parameters 72 | } 73 | 74 | @TaskAction 75 | void install() { 76 | 77 | // phony task? we need only return it 78 | if (taskContext == null) { 79 | return 80 | } 81 | 82 | // trace 83 | taskContext.logger.i(">> install artifacts to " + taskContext.nativeLibsDir.absolutePath) 84 | 85 | // install artifacts to the native libs directory 86 | File installArtifactsScriptFile = new File(taskContext.buildDirectory, "install_artifacts.lua") 87 | installArtifactsScriptFile.withWriter { out -> 88 | String text = getClass().getClassLoader().getResourceAsStream("lua/install_artifacts.lua").getText() 89 | out.write(text) 90 | } 91 | 92 | // do install 93 | XMakeExecutor executor = new XMakeExecutor(taskContext.logger, false) 94 | executor.exec(buildCmdLine(installArtifactsScriptFile), taskContext.projectDirectory) 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/groovy/org/tboox/gradle/XMakePluginExtension.groovy: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file XMakePluginExtension.groovy 19 | * 20 | */ 21 | package org.tboox.gradle 22 | 23 | import com.sun.org.apache.xpath.internal.operations.Bool 24 | 25 | class XMakePluginExtension { 26 | 27 | // xmake program 28 | String program 29 | 30 | // the project path (e.g. jni/xmake.lua) 31 | String path 32 | 33 | // the ndk path 34 | String ndk 35 | 36 | // the ndk sdk version 37 | Integer sdkver 38 | 39 | // the c++ stl library, e.g. stlport_static, stlport_shared, c++_shared, c++_static, gnustl_shared, gnustl_static 40 | String stl 41 | 42 | // use stdc++ library? enabled by default 43 | Boolean stdcxx 44 | 45 | // the build directory 46 | String buildDir 47 | 48 | // the build mode, e.g. debug, release, .. 49 | String buildMode 50 | 51 | // the log level, e.g. normal, verbose, debug 52 | String logLevel 53 | 54 | // the configuration arguments 55 | List arguments = new ArrayList<>() 56 | 57 | // the c compile flags 58 | List cFlags = new ArrayList<>() 59 | 60 | // the c++ compile flags 61 | List cppFlags = new ArrayList<>() 62 | 63 | // the abi filters 64 | Set abiFilters = new HashSet<>() 65 | 66 | // the targets 67 | Set targets = new HashSet<>() 68 | 69 | void arguments(String arg) { 70 | arguments.add(arg) 71 | } 72 | 73 | void arguments(String... args) { 74 | arguments.addAll(args.toList()) 75 | } 76 | 77 | void setArguments(Collection args) { 78 | arguments.addAll(args) 79 | } 80 | 81 | void cFlags(String flag) { 82 | cFlags.add(flag) 83 | } 84 | 85 | void cFlags(String... flags) { 86 | cFlags.addAll(flags.toList()) 87 | } 88 | 89 | void setCFlags(Collection flags) { 90 | cFlags.addAll(flags) 91 | } 92 | 93 | void cppFlags(String flag) { 94 | cppFlags.add(flag) 95 | } 96 | 97 | void cppFlags(String... flags) { 98 | cppFlags.addAll(flags.toList()) 99 | } 100 | 101 | void setCppFlags(Collection flags) { 102 | cppFlags.addAll(flags) 103 | } 104 | 105 | void abiFilters(String filter) { 106 | abiFilters.add(filter) 107 | } 108 | 109 | void abiFilters(String... filters) { 110 | abiFilters.addAll(filters.toList()) 111 | } 112 | 113 | void setAbiFilters(Collection filters) { 114 | abiFilters.addAll(filters) 115 | } 116 | 117 | void targets(String target) { 118 | targets.add(target) 119 | } 120 | 121 | void targets(String... targets) { 122 | targets.addAll(targets.toList()) 123 | } 124 | 125 | void setTargets(Collection targets) { 126 | abiFilters.addAll(targets) 127 | } 128 | } 129 | 130 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/groovy/org/tboox/gradle/XMakeRebuildTask.groovy: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file XMakeRebuildTask.groovy 19 | * 20 | */ 21 | package org.tboox.gradle 22 | 23 | import org.gradle.api.DefaultTask 24 | import org.gradle.api.GradleException 25 | import org.gradle.api.tasks.TaskAction 26 | import org.gradle.api.tasks.Internal 27 | 28 | class XMakeRebuildTask extends DefaultTask { 29 | 30 | // the task context 31 | @Internal 32 | XMakeTaskContext taskContext 33 | 34 | // the constructor 35 | XMakeRebuildTask() { 36 | setGroup("xmake") 37 | setDescription("Rebuild a configured Build with XMake") 38 | } 39 | 40 | // build command line 41 | private List buildCmdLine() { 42 | List parameters = new ArrayList<>(); 43 | parameters.add(taskContext.program) 44 | parameters.add("-r") 45 | switch (taskContext.logLevel) { 46 | case "verbose": 47 | parameters.add("-v") 48 | break 49 | case "debug": 50 | parameters.add("-vD") 51 | break 52 | default: 53 | break 54 | } 55 | Set targets = taskContext.targets 56 | if (targets != null && targets.size() > 0) { 57 | for (String target: targets) { 58 | parameters.add(target) 59 | } 60 | } 61 | return parameters; 62 | } 63 | 64 | // build install command line 65 | private List buildInstallCmdLine() { 66 | List parameters = new ArrayList<>(); 67 | parameters.add(taskContext.program) 68 | parameters.add("install") 69 | switch (taskContext.logLevel) { 70 | case "verbose": 71 | parameters.add("-v") 72 | break 73 | case "debug": 74 | parameters.add("-vD") 75 | break 76 | default: 77 | parameters.add("-q") 78 | break 79 | } 80 | File libsDir = new File(taskContext.buildDirectory, String.join(File.separator, "libs", taskContext.buildArch)) 81 | parameters.add("-o") 82 | parameters.add(libsDir.path) 83 | Set targets = taskContext.targets 84 | if (targets != null && targets.size() > 0) { 85 | for (String target: targets) { 86 | parameters.add(target) 87 | } 88 | } 89 | return parameters; 90 | } 91 | 92 | @TaskAction 93 | void rebuild() { 94 | 95 | // phony task? we need only return it 96 | if (taskContext == null) { 97 | return 98 | } 99 | 100 | // check 101 | if (!taskContext.projectFile.isFile()) { 102 | throw new GradleException(TAG + taskContext.projectFile.absolutePath + " not found!") 103 | } 104 | 105 | // do build 106 | XMakeExecutor buildExecutor = new XMakeExecutor(taskContext.logger) 107 | buildExecutor.exec(buildCmdLine(), taskContext.projectDirectory) 108 | 109 | // do install 110 | XMakeExecutor installExecutor = new XMakeExecutor(taskContext.logger, false) 111 | installExecutor.exec(buildInstallCmdLine(), taskContext.projectDirectory) 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/groovy/org/tboox/gradle/XMakeBuildTask.groovy: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file XMakeBuildTask.groovy 19 | * 20 | */ 21 | package org.tboox.gradle 22 | 23 | import org.gradle.api.DefaultTask 24 | import org.gradle.api.GradleException 25 | import org.gradle.api.tasks.TaskAction 26 | import org.gradle.api.tasks.Internal 27 | 28 | class XMakeBuildTask extends DefaultTask { 29 | 30 | // the task context 31 | @Internal 32 | XMakeTaskContext taskContext 33 | 34 | // the constructor 35 | XMakeBuildTask() { 36 | setGroup("xmake") 37 | setDescription("Build a configured Build with XMake") 38 | } 39 | 40 | // build command line 41 | private List buildCmdLine() { 42 | List parameters = new ArrayList<>() 43 | parameters.add(taskContext.program) 44 | parameters.add("build") 45 | switch (taskContext.logLevel) { 46 | case "verbose": 47 | parameters.add("-v") 48 | break 49 | case "debug": 50 | parameters.add("-vD") 51 | break 52 | default: 53 | break 54 | } 55 | Set targets = taskContext.targets 56 | if (targets != null && targets.size() > 0) { 57 | for (String target: targets) { 58 | parameters.add(target) 59 | } 60 | } 61 | return parameters 62 | } 63 | 64 | // build install command line 65 | private List buildInstallCmdLine() { 66 | List parameters = new ArrayList<>() 67 | parameters.add(taskContext.program) 68 | parameters.add("install") 69 | switch (taskContext.logLevel) { 70 | case "verbose": 71 | parameters.add("-v") 72 | break 73 | case "debug": 74 | parameters.add("-vD") 75 | break 76 | default: 77 | parameters.add("-q") 78 | break 79 | } 80 | File libsDir = new File(taskContext.buildDirectory, String.join(File.separator, "src", "main", "jniLibs", taskContext.buildArch)) 81 | parameters.add("-o") 82 | parameters.add(libsDir.path) 83 | Set targets = taskContext.targets 84 | if (targets != null && targets.size() > 0) { 85 | for (String target: targets) { 86 | parameters.add(target) 87 | } 88 | } 89 | return parameters 90 | } 91 | 92 | @TaskAction 93 | void build() { 94 | 95 | // phony task? we need only return it 96 | if (taskContext == null) { 97 | return 98 | } 99 | 100 | // check 101 | if (!taskContext.projectFile.isFile()) { 102 | throw new GradleException(TAG + taskContext.projectFile.absolutePath + " not found!") 103 | } 104 | 105 | // do build 106 | XMakeExecutor buildExecutor = new XMakeExecutor(taskContext.logger) 107 | buildExecutor.exec(buildCmdLine(), taskContext.projectDirectory) 108 | 109 | // do install 110 | XMakeExecutor installExecutor = new XMakeExecutor(taskContext.logger, false) 111 | installExecutor.exec(buildInstallCmdLine(), taskContext.projectDirectory) 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/groovy/org/tboox/gradle/XMakeCleanTask.groovy: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file XMakeCleanTask.groovy 19 | * 20 | */ 21 | package org.tboox.gradle 22 | 23 | import org.gradle.api.DefaultTask 24 | import org.gradle.api.GradleException 25 | import org.gradle.api.tasks.TaskAction 26 | import org.gradle.api.tasks.Internal 27 | 28 | class XMakeCleanTask extends DefaultTask { 29 | 30 | // the task context 31 | @Internal 32 | XMakeTaskContext taskContext 33 | 34 | // the constructor 35 | XMakeCleanTask() { 36 | setGroup("xmake") 37 | setDescription("Clean generated files with XMake") 38 | } 39 | 40 | // build command line 41 | private List buildCmdLine() { 42 | List parameters = new ArrayList<>() 43 | parameters.add(taskContext.program) 44 | parameters.add("clean") 45 | switch (taskContext.logLevel) { 46 | case "verbose": 47 | parameters.add("-v") 48 | break 49 | case "debug": 50 | parameters.add("-vD") 51 | break 52 | default: 53 | break 54 | } 55 | Set targets = taskContext.targets 56 | if (targets != null && targets.size() > 0) { 57 | for (String target: targets) { 58 | parameters.add(target) 59 | } 60 | } 61 | return parameters 62 | } 63 | 64 | private void uninstallArtifacts() { 65 | 66 | // uninstall artifacts to the native libs directory 67 | File installArtifactsScriptFile = new File(taskContext.buildDirectory, "install_artifacts.lua") 68 | installArtifactsScriptFile.withWriter { out -> 69 | String text = getClass().getClassLoader().getResourceAsStream("lua/install_artifacts.lua").getText() 70 | out.write(text) 71 | } 72 | 73 | List parameters = new ArrayList<>() 74 | parameters.add(taskContext.program) 75 | parameters.add("lua") 76 | switch (taskContext.logLevel) { 77 | case "verbose": 78 | parameters.add("-v") 79 | break 80 | case "debug": 81 | parameters.add("-vD") 82 | break 83 | default: 84 | break 85 | } 86 | parameters.add(installArtifactsScriptFile.absolutePath) 87 | 88 | // pass app/libs directory 89 | parameters.add("-o") 90 | parameters.add(taskContext.nativeLibsDir.absolutePath) 91 | 92 | // pass arch 93 | parameters.add("-a") 94 | parameters.add(taskContext.buildArch) 95 | 96 | // pass clean 97 | parameters.add("-c") 98 | 99 | // pass targets 100 | Set targets = taskContext.targets 101 | if (targets != null && targets.size() > 0) { 102 | for (String target: targets) { 103 | parameters.add(target) 104 | } 105 | } 106 | 107 | // do uninstall 108 | XMakeExecutor executor = new XMakeExecutor(taskContext.logger) 109 | executor.exec(parameters, taskContext.projectDirectory) 110 | } 111 | 112 | @TaskAction 113 | void clean() { 114 | 115 | // phony task? we need only return it 116 | if (taskContext == null) { 117 | return 118 | } 119 | 120 | // check 121 | if (!taskContext.projectFile.isFile()) { 122 | throw new GradleException(TAG + taskContext.projectFile.absolutePath + " not found!") 123 | } 124 | 125 | // do clean 126 | XMakeExecutor executor = new XMakeExecutor(taskContext.logger) 127 | executor.exec(buildCmdLine(), taskContext.projectDirectory) 128 | 129 | uninstallArtifacts() 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/groovy/org/tboox/gradle/XMakeConfigureTask.groovy: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file XMakeConfigureTask.groovy 19 | * 20 | */ 21 | package org.tboox.gradle 22 | 23 | import org.gradle.api.DefaultTask 24 | import org.gradle.api.GradleException 25 | import org.gradle.api.tasks.TaskAction 26 | import org.gradle.api.tasks.Internal 27 | 28 | class XMakeConfigureTask extends DefaultTask { 29 | 30 | // the task context 31 | @Internal 32 | XMakeTaskContext taskContext 33 | 34 | // the constructor 35 | XMakeConfigureTask() { 36 | setGroup("xmake") 37 | setDescription("Configure a Build with XMake") 38 | } 39 | 40 | // build command line 41 | private List buildCmdLine() { 42 | List parameters = new ArrayList<>() 43 | parameters.add(taskContext.program) 44 | parameters.add("f") 45 | parameters.add("-c") 46 | parameters.add("-y") 47 | switch (taskContext.logLevel) { 48 | case "verbose": 49 | parameters.add("-v") 50 | break 51 | case "debug": 52 | parameters.add("-vD") 53 | break 54 | default: 55 | break 56 | } 57 | parameters.add("-p") 58 | parameters.add("android") 59 | if (taskContext.buildArch != null) { 60 | parameters.add("-a") 61 | parameters.add(taskContext.buildArch) 62 | } 63 | if (taskContext.buildMode != null) { 64 | parameters.add("-m") 65 | parameters.add(taskContext.buildMode) 66 | } 67 | List arguments = taskContext.arguments 68 | if (arguments != null && arguments.size() > 0) { 69 | for (String arg: arguments) { 70 | parameters.add(arg) 71 | } 72 | } 73 | List cFlags = taskContext.cFlags 74 | if (cFlags != null && cFlags.size() > 0) { 75 | int i = 0 76 | StringBuilder sb = new StringBuilder() 77 | for (String flag: cFlags) { 78 | if (i != 0) { 79 | sb.append(" ") 80 | } 81 | sb.append(flag) 82 | i++ 83 | } 84 | parameters.add("--cflags=\"" + sb.toString() + "\"") 85 | } 86 | List cppFlags = taskContext.cppFlags 87 | if (cppFlags != null && cppFlags.size() > 0) { 88 | int i = 0 89 | StringBuilder sb = new StringBuilder() 90 | for (String flag: cppFlags) { 91 | if (i != 0) { 92 | sb.append(" ") 93 | } 94 | sb.append(flag) 95 | i++ 96 | } 97 | parameters.add("--cxxflags=\"" + sb.toString() + "\"") 98 | } 99 | File ndkDir = taskContext.getNDKDirectory() 100 | if (ndkDir != null) { 101 | parameters.add("--ndk=" + ndkDir.path) 102 | } 103 | String sdkver = taskContext.getSDKVersion() 104 | if (sdkver != null) { 105 | parameters.add("--ndk_sdkver=" + sdkver) 106 | } 107 | Boolean stdcxx = taskContext.stdcxx 108 | if (stdcxx != null && stdcxx == false) { 109 | parameters.add("--ndk_stdcxx=n") 110 | } else { 111 | String stl = taskContext.stl 112 | if (stl != null) { 113 | parameters.add("--runtimes=" + stl) 114 | } 115 | } 116 | parameters.add("--buildir=" + taskContext.buildDirectory.path) 117 | return parameters 118 | } 119 | 120 | @TaskAction 121 | void configure() { 122 | 123 | // check 124 | if (!taskContext.projectFile.isFile()) { 125 | throw new GradleException(TAG + taskContext.projectFile.absolutePath + " not found!") 126 | } 127 | 128 | // do configure 129 | XMakeExecutor executor = new XMakeExecutor(taskContext.logger) 130 | executor.exec(buildCmdLine(), taskContext.projectDirectory) 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | If you discover issues, have ideas for improvements or new features, or 4 | want to contribute a new module, please report them to the 5 | [issue tracker][1] of the repository or submit a pull request. Please, 6 | try to follow these guidelines when you do so. 7 | 8 | ## Issue reporting 9 | 10 | * Check that the issue has not already been reported. 11 | * Check that the issue has not already been fixed in the latest code 12 | (a.k.a. `master`). 13 | * Be clear, concise and precise in your description of the problem. 14 | * Open an issue with a descriptive title and a summary in grammatically correct, 15 | complete sentences. 16 | * Include any relevant code to the issue summary. 17 | 18 | ## Pull requests 19 | 20 | * Use a topic branch to easily amend a pull request later, if necessary. 21 | * Write good commit messages. 22 | * Use the same coding conventions as the rest of the project. 23 | * Ensure your edited codes with four spaces instead of TAB. 24 | * Please commit code to `dev` branch and we will merge into `master` branch in future. 25 | 26 | ## Financial contributions 27 | 28 | We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/xmake). 29 | Anyone can file an expense. If the expense makes sense for the development of the community, it will be "merged" in the ledger of our open collective by the core contributors and the person who filed the expense will be reimbursed. 30 | 31 | ## Credits 32 | 33 | ### Backers 34 | 35 | Thank you to all our backers! [[Become a backer](https://opencollective.com/xmake#backer)] 36 | 37 | 38 | 39 | ### Sponsors 40 | 41 | Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/xmake#sponsor)) 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | # 贡献代码 55 | 56 | 如果你发现一些问题,或者想新增或者改进某些新特性,或者想贡献一个新的模块 57 | 那么你可以在[issues][1]上提交反馈,或者发起一个提交代码的请求(pull request). 58 | 59 | ## 问题反馈 60 | 61 | * 确认这个问题没有被反馈过 62 | * 确认这个问题最近还没有被修复,请先检查下 `master` 的最新提交 63 | * 请清晰详细地描述你的问题 64 | * 如果发现某些代码存在问题,请在issue上引用相关代码 65 | 66 | ## 提交代码 67 | 68 | * 请先更新你的本地分支到最新,再进行提交代码请求,确保没有合并冲突 69 | * 编写友好可读的提交信息 70 | * 请使用与工程代码相同的代码规范 71 | * 确保提交的代码缩进是四个空格,而不是tab 72 | * 请提交代码到`dev`分支,如果通过,我们会在特定时间合并到`master`分支上 73 | * 为了规范化提交日志的格式,commit消息,不要用中文,请用英文描述 74 | 75 | [1]: https://github.com/xmake-io/xmake-gradle/issues 76 | 77 | ## 支持项目 78 | 79 | xmake-gradle项目属于个人开源项目,它的发展需要您的帮助,如果您愿意支持xmake-gradle项目的开发,欢迎为其捐赠,支持它的发展。 🙏 [[支持此项目](https://opencollective.com/xmake#backer)] 80 | 81 | 82 | 83 | ## 赞助项目 84 | 85 | 通过赞助支持此项目,您的logo和网站链接将显示在这里。[[赞助此项目](https://opencollective.com/xmake#sponsor)] 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/resources/lua/install_artifacts.lua: -------------------------------------------------------------------------------- 1 | -- imports 2 | import("core.base.option") 3 | import("core.project.config") 4 | import("core.project.project") 5 | import("core.tool.toolchain") 6 | import("target.action.install") 7 | import("target.action.uninstall") 8 | 9 | local options = { 10 | {'o', "installdir", "kv", nil, "Set the install directory"}, 11 | {'a', "arch", "kv", nil, "Set the installed target architecture"}, 12 | {'c', "clean", "k", false, "Clean artifacts"}, 13 | {nil, "targets", "vs", nil, "Set the targets"} 14 | } 15 | 16 | -- get targets 17 | function _get_targets(targetNames) 18 | local targets = {} 19 | targetNames = targetNames or {} 20 | if #targetNames > 0 then 21 | for _, targetName in ipairs(targetNames) do 22 | local target = project.target(targetName) 23 | if target:get("enabled") ~= false and target:is_shared() then 24 | table.insert(targets, target) 25 | else 26 | raise("invalid target(%s)!", targetName) 27 | end 28 | end 29 | else 30 | for _, target in ipairs(project.ordertargets()) do 31 | local default = target:get("default") 32 | if (default == nil or default == true) and target:is_shared() then 33 | table.insert(targets, target) 34 | end 35 | end 36 | end 37 | return targets 38 | end 39 | 40 | -- install artifacts 41 | function _install_artifacts(targets, opt) 42 | local arch = opt.arch 43 | local installdir = opt.installdir 44 | assert(xmake.version():ge("2.9.6"), "please update xmake to >= 2.9.6") 45 | for _, target in ipairs(targets) do 46 | install(target, {installdir = installdir, libdir = arch, includedir = "include"}) 47 | end 48 | end 49 | 50 | -- install cxxstl for ndk >= r25 51 | function _install_cxxstl_newer_ndk(opt) 52 | local arch = opt.arch 53 | local installdir = path.join(opt.installdir, arch) 54 | local ndk = get_config("ndk") 55 | local ndk_cxxstl = get_config("runtimes") or get_config("ndk_cxxstl") 56 | if ndk and ndk_cxxstl and ndk_cxxstl:endswith("_shared") and arch then 57 | 58 | -- get the toolchains arch 59 | local toolchains_archs = { 60 | ["armeabi-v7a"] = "arm-linux-androideabi", 61 | ["arm64-v8a"] = "aarch64-linux-android", 62 | ["riscv64"] = "riscv64-linux-android", 63 | ["x86"] = "i686-linux-android", 64 | ["x86_64"] = "x86_64-linux-android" 65 | } 66 | 67 | -- get stl library 68 | local cxxstl_filename 69 | if ndk_cxxstl == "c++_shared" then 70 | cxxstl_filename = "libc++_shared.so" 71 | end 72 | 73 | if toolchains_archs[arch] ~= nil and cxxstl_filename then 74 | local ndk_toolchain = toolchain.load("ndk", {plat = config.plat(), arch = config.arch()}) 75 | local ndk_sysroot = ndk_toolchain:config("ndk_sysroot") 76 | local cxxstl_sdkdir_llvmstl = path.translate(format("%s/usr/lib/%s", ndk_sysroot, toolchains_archs[arch])) 77 | 78 | os.vcp(path.join(cxxstl_sdkdir_llvmstl, cxxstl_filename), path.join(installdir, cxxstl_filename)) 79 | end 80 | 81 | end 82 | end 83 | 84 | -- install c++ stl shared library 85 | function _install_cxxstl(opt) 86 | local arch = opt.arch 87 | local installdir = path.join(opt.installdir, arch) 88 | local ndk = get_config("ndk") 89 | local ndk_cxxstl = get_config("runtimes") or get_config("ndk_cxxstl") 90 | if ndk and ndk_cxxstl and ndk_cxxstl:endswith("_shared") and arch then 91 | 92 | -- get llvm c++ stl sdk directory 93 | local cxxstl_sdkdir_llvmstl = path.translate(format("%s/sources/cxx-stl/llvm-libc++", ndk)) 94 | 95 | -- get gnu c++ stl sdk directory 96 | local cxxstl_sdkdir_gnustl = nil 97 | if get_config("ndk_toolchains_ver") then 98 | cxxstl_sdkdir_gnustl = path.translate(format("%s/sources/cxx-stl/gnu-libstdc++/%s", ndk, get_config("ndk_toolchains_ver"))) 99 | end 100 | 101 | -- get stlport c++ sdk directory 102 | local cxxstl_sdkdir_stlport = path.translate(format("%s/sources/cxx-stl/stlport", ndk)) 103 | 104 | -- get c++ sdk directory 105 | local cxxstl_sdkdir 106 | if ndk_cxxstl:startswith("c++") then 107 | cxxstl_sdkdir = cxxstl_sdkdir_llvmstl 108 | elseif ndk_cxxstl:startswith("gnustl") then 109 | cxxstl_sdkdir = cxxstl_sdkdir_gnustl 110 | elseif ndk_cxxstl:startswith("stlport") then 111 | cxxstl_sdkdir = cxxstl_sdkdir_stlport 112 | end 113 | 114 | -- get the toolchains arch 115 | local toolchains_archs = 116 | { 117 | ["armv5te"] = "armeabi" -- deprecated 118 | , ["armv7-a"] = "armeabi-v7a" -- deprecated 119 | , ["armeabi"] = "armeabi" -- removed in ndk r17 120 | , ["armeabi-v7a"] = "armeabi-v7a" 121 | , ["arm64-v8a"] = "arm64-v8a" 122 | , ["riscv64"] = "riscv64" 123 | , i386 = "x86" -- deprecated 124 | , x86 = "x86" 125 | , x86_64 = "x86_64" 126 | , mips = "mips" -- removed in ndk r17 127 | , mips64 = "mips64" -- removed in ndk r17 128 | } 129 | local toolchains_arch = toolchains_archs[arch] 130 | 131 | -- get stl library 132 | local cxxstl_filename 133 | if ndk_cxxstl == "c++_shared" then 134 | cxxstl_filename = "libc++_shared.so" 135 | elseif ndk_cxxstl == "gnustl_shared" then 136 | cxxstl_filename = "libgnustl_shared.so" 137 | elseif ndk_cxxstl == "stlport_shared" then 138 | cxxstl_filename = "libstlport_shared.so" 139 | end 140 | 141 | -- do copy 142 | if cxxstl_sdkdir and toolchains_arch and cxxstl_filename then 143 | os.vcp(path.join(cxxstl_sdkdir, "libs", toolchains_arch, cxxstl_filename), path.join(installdir, cxxstl_filename)) 144 | end 145 | end 146 | end 147 | 148 | -- clean artifacts 149 | function _clean_artifacts(targets, opt) 150 | local arch = opt.arch 151 | local installdir = opt.installdir 152 | assert(xmake.version():ge("2.9.6"), "please update xmake to >= 2.9.6") 153 | for _, target in ipairs(targets) do 154 | uninstall(target, {installdir = installdir, libdir = arch, includedir = "include"}) 155 | end 156 | 157 | -- clean cxxstl 158 | installdir = path.join(installdir, arch) 159 | local ndk_cxxstl = get_config("ndk_cxxstl") 160 | if ndk_cxxstl then 161 | local cxxstl_filename 162 | if ndk_cxxstl == "c++_shared" then 163 | cxxstl_filename = "libc++_shared.so" 164 | elseif ndk_cxxstl == "gnustl_shared" then 165 | cxxstl_filename = "libgnustl_shared.so" 166 | elseif ndk_cxxstl == "stlport_shared" then 167 | cxxstl_filename = "libstlport_shared.so" 168 | end 169 | os.tryrm(installdir) 170 | end 171 | 172 | if os.emptydir(installdir) then 173 | os.rmdir(installdir) 174 | end 175 | end 176 | 177 | function main(...) 178 | local argv = table.pack(...) 179 | local opt = option.parse(argv, options, "Install the target artifacts." 180 | , "" 181 | , "Usage: xmake l install_artifacts.lua [options]") 182 | assert(opt.installdir) 183 | 184 | -- load config 185 | config.load() 186 | 187 | -- do install or clean 188 | local targets = _get_targets(opt.targets) 189 | assert(targets and #targets > 0, "no targets provided, make sure to have at least one shared target in your xmake.lua or to provide one") 190 | 191 | opt.arch = opt.arch or get_config("arch") 192 | if not opt.clean then 193 | _install_artifacts(targets, opt) 194 | if get_config("ndkver") >= 25 then 195 | _install_cxxstl_newer_ndk(opt) 196 | else 197 | _install_cxxstl(opt) 198 | end 199 | else 200 | _clean_artifacts(targets, opt) 201 | end 202 | end 203 | 204 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/groovy/org/tboox/gradle/XMakeTaskContext.groovy: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file XMakeTaskContext.groovy 19 | * 20 | */ 21 | package org.tboox.gradle 22 | 23 | import com.android.build.gradle.AppExtension 24 | import com.android.build.gradle.LibraryExtension 25 | import org.gradle.api.Project 26 | 27 | class XMakeTaskContext { 28 | 29 | // the project 30 | Project project 31 | 32 | // the plugin extension 33 | XMakePluginExtension extension 34 | 35 | // the logger 36 | XMakeLogger logger 37 | 38 | // the build architecture 39 | String buildArch 40 | 41 | // the constructor 42 | XMakeTaskContext(XMakePluginExtension extension, Project project, XMakeLogger logger) { 43 | this.logger = logger 44 | this.project = project 45 | this.extension = extension 46 | } 47 | XMakeTaskContext(XMakePluginExtension extension, Project project, XMakeLogger logger, String buildArch) { 48 | this.logger = logger 49 | this.project = project 50 | this.extension = extension 51 | this.buildArch = buildArch 52 | } 53 | 54 | // get xmake program 55 | String getProgram() { 56 | String program = extension.program 57 | if (program == null) { 58 | program = "xmake" 59 | } 60 | return program 61 | } 62 | 63 | // get project file 64 | File getProjectFile() { 65 | String path = extension.path 66 | if (path == null) { 67 | return null 68 | } 69 | return new File(project.buildscript.sourceFile.parentFile, path).absoluteFile 70 | } 71 | 72 | // get ndk directory 73 | File getNDKDirectory() { 74 | String ndk = extension.ndk 75 | if (ndk != null) { 76 | return new File(ndk).absoluteFile 77 | } 78 | 79 | def androidExtension = project.getProperties().get("android") 80 | if (androidExtension != null) { 81 | if (androidExtension instanceof LibraryExtension) { 82 | LibraryExtension libraryExtension = androidExtension 83 | if (libraryExtension.ndkDirectory != null && libraryExtension.ndkDirectory.exists()) { 84 | return libraryExtension.ndkDirectory.absoluteFile 85 | } 86 | } else if (androidExtension instanceof AppExtension) { 87 | AppExtension appExtension = androidExtension 88 | if (appExtension.ndkDirectory != null && appExtension.ndkDirectory.exists()) { 89 | return appExtension.ndkDirectory.absoluteFile 90 | } 91 | } 92 | } 93 | return null 94 | } 95 | 96 | // get ndk sdk version 97 | String getSDKVersion() { 98 | Integer sdkver = extension.sdkver 99 | /* 100 | if (sdkver == null) { 101 | // get abiFilters from android.defaultConfig{minSdkVersion} 102 | def androidExtension = project.getProperties().get("android") 103 | if (androidExtension != null) { 104 | if (androidExtension instanceof LibraryExtension) { 105 | LibraryExtension libraryExtension = androidExtension 106 | def defaultConfig = libraryExtension.getDefaultConfig() 107 | if (defaultConfig != null && defaultConfig.minSdkVersion != null) { 108 | sdkver = defaultConfig.minSdkVersion.apiLevel 109 | } 110 | } else if (androidExtension instanceof AppExtension) { 111 | AppExtension appExtension = androidExtension 112 | def defaultConfig = appExtension.getDefaultConfig() 113 | if (defaultConfig != null && defaultConfig.minSdkVersion != null) { 114 | sdkver = defaultConfig.minSdkVersion.apiLevel 115 | } 116 | } 117 | } 118 | }*/ 119 | if (sdkver != null) { 120 | return sdkver.toString() 121 | } 122 | return null 123 | } 124 | 125 | // enable stdc++? 126 | Boolean getStdcxx() { 127 | return extension.stdcxx 128 | } 129 | 130 | // get c++ stl library 131 | String getStl() { 132 | return extension.stl 133 | } 134 | 135 | // get project directory 136 | File getProjectDirectory() { 137 | return projectFile.parentFile 138 | } 139 | 140 | // get build directory 141 | File getBuildDirectory() { 142 | String buildDir = extension.buildDir 143 | if (buildDir != null) { 144 | File file = new File(buildDir) 145 | if (file.isAbsolute()) { 146 | return file.absoluteFile 147 | } else { 148 | return new File(project.buildscript.sourceFile.parentFile, buildDir).absoluteFile 149 | } 150 | } 151 | return new File(project.layout.buildDirectory.asFile.get().absoluteFile, "xmake") 152 | } 153 | 154 | // get native libs directory 155 | File getNativeLibsDir() { 156 | return new File(project.buildscript.sourceFile.parentFile, String.join(File.separator, "src", "main", "jniLibs")).absoluteFile 157 | } 158 | 159 | // get cflags 160 | List getcFlags() { 161 | return extension.cFlags 162 | } 163 | 164 | // get cppflags 165 | List getCppFlags() { 166 | return extension.cppFlags 167 | } 168 | 169 | // get arguments 170 | List getArguments() { 171 | return extension.arguments 172 | } 173 | 174 | // get targets 175 | Set getTargets() { 176 | return extension.targets 177 | } 178 | 179 | // get abi filters 180 | Set getAbiFilters() { 181 | Set abiFilters = extension.abiFilters 182 | if (abiFilters == null || abiFilters.size() == 0) { 183 | // get abiFilters from android.defaultConfig{ndk{abiFilters}} 184 | def androidExtension = project.getProperties().get("android") 185 | if (androidExtension != null) { 186 | if (androidExtension instanceof LibraryExtension) { 187 | LibraryExtension libraryExtension = androidExtension 188 | def defaultConfig = libraryExtension.getDefaultConfig() 189 | if (defaultConfig != null && defaultConfig.getNdk() != null) { 190 | abiFilters = defaultConfig.getNdk().abiFilters 191 | } 192 | } else if (androidExtension instanceof AppExtension) { 193 | AppExtension appExtension = androidExtension 194 | def defaultConfig = appExtension.getDefaultConfig() 195 | if (defaultConfig != null && defaultConfig.getNdk() != null) { 196 | abiFilters = defaultConfig.getNdk().abiFilters 197 | } 198 | } 199 | } 200 | } 201 | if (abiFilters == null || abiFilters.size() == 0) { 202 | Set filters = new HashSet<>() 203 | filters.add("armeabi-v7a") 204 | return filters 205 | } 206 | return abiFilters 207 | } 208 | 209 | // get log level 210 | String getLogLevel() { 211 | String level = extension.logLevel 212 | if (level == null) { 213 | level = "normal" 214 | } 215 | return level 216 | } 217 | 218 | // get build mode 219 | String getBuildMode() { 220 | return extension.buildMode 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /README_zh.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 |

xmake-gradle

7 | 8 | 16 | 33 | 34 |

A gradle plugin that integrates xmake seamlessly

35 |
36 | 37 | ## 简介 38 | 39 | xmake-gradle是一个无缝整合xmake的gradle插件。 40 | 41 | 如果你想要了解更多,请参考: 42 | 43 | * [在线文档](https://xmake.io/#/zh-cn/getting_started) 44 | * [项目主页](https://xmake.io/#/zh-cn/) 45 | * [Github](https://github.com/xmake-io/xmake-gradle) 46 | * [Gitee](https://gitee.com/tboox/xmake-gradle) 47 | * [Gradle插件](https://plugins.gradle.org/plugin/org.tboox.gradle-xmake-plugin) 48 | 49 | ## 准备工作 50 | 51 | 我们需要先安装好对应的xmake命令行工具,关于安装说明见:[xmake](https://github.com/xmake-io/xmake)。 52 | 53 | ## 应用插件 54 | 55 | ### 通过插件DSL集成 56 | 57 | ``` 58 | plugins { 59 | id 'org.tboox.gradle-xmake-plugin' version '1.2.2' 60 | } 61 | ``` 62 | 63 | ### 被废弃的插件集成方式 64 | 65 | ``` 66 | buildscript { 67 | repositories { 68 | maven { 69 | url "https://plugins.gradle.org/m2/" 70 | } 71 | } 72 | dependencies { 73 | classpath 'org.tboox:gradle-xmake-plugin:1.2.2' 74 | } 75 | repositories { 76 | mavenCentral() 77 | } 78 | } 79 | 80 | apply plugin: "org.tboox.gradle-xmake-plugin" 81 | ``` 82 | 83 | ## 配置 84 | 85 | ### 最简单的配置示例 86 | 87 | 如果我们添加`xmake.lua`文件到`projectdir/jni/xmake.lua`,那么我们只需要在build.gradle中启用生效了xmake指定下对应的JNI工程路径即可。 88 | 89 | #### build.gradle 90 | 91 | ``` 92 | android { 93 | externalNativeBuild { 94 | xmake { 95 | path "jni/xmake.lua" 96 | } 97 | } 98 | } 99 | ``` 100 | 101 | #### JNI 102 | 103 | JNI工程结构 104 | 105 | ``` 106 | projectdir 107 | - src 108 | - main 109 | - java 110 | - jni 111 | - xmake.lua 112 | - *.cpp 113 | ``` 114 | 115 | xmake.lua: 116 | 117 | ```lua 118 | add_rules("mode.debug", "mode.release") 119 | target("nativelib") 120 | set_kind("shared") 121 | add_files("nativelib.cc") 122 | ``` 123 | 124 | ### 更多Gradle配置说明 125 | 126 | ``` 127 | android { 128 | defaultConfig { 129 | externalNativeBuild { 130 | xmake { 131 | // 追加设置全局c编译flags 132 | cFlags "-DTEST" 133 | 134 | // 追加设置全局c++编译flags 135 | cppFlags "-DTEST", "-DTEST2" 136 | 137 | // 设置切换编译模式,与`xmake f -m debug`的配置对应,具体模式值根据自己的xmake.lua设置而定 138 | buildMode "debug" 139 | 140 | // 设置需要编译的abi列表,支持:armeabi, armeabi-v7a, arm64-v8a, x86, x86_64 141 | // 如果没有设置的话,我们也支持从defaultConfig.ndk.abiFilters中获取abiFilters 142 | abiFilters "armeabi-v7a", "arm64-v8a" 143 | 144 | // 设置需要被编译的targets 145 | // targets "xxx", "yyy" 146 | } 147 | } 148 | } 149 | 150 | externalNativeBuild { 151 | xmake { 152 | // 设置jni工程中xmake.lua根文件路径,这是必须的,不设置就不会启用jni编译 153 | path "jni/xmake.lua" 154 | 155 | // 启用详细输出,会显示完整编译命令行参数,其他值:verbose, normal 156 | logLevel "verbose" 157 | 158 | // 指定c++ stl库,默认不指定会使用c++_static,其他值:c++_static/c++_shared, gnustl_static/gnustl_shared, stlport_static/stlport_shared 159 | stl "c++_shared" 160 | 161 | // 设置xmake可执行程序路径(通常不用设置) 162 | // program /usr/local/bin/xmake 163 | 164 | // 禁用stdc++库,默认是启用的 165 | // stdcxx false 166 | 167 | // 设置其他指定的ndk目录路径 (这是可选的,默认xmake会自动从$ANDROID_NDK_HOME或者`~/Library/Android/sdk/ndk-bundle`中检测) 168 | // 当然如果用户通过`xmake g --ndk=xxx`配置了全局设置,也会自动从这个里面检测 169 | // ndk "/Users/ruki/files/android-ndk-r20b/" 170 | 171 | // 设置ndk中sdk版本 172 | // sdkver 21 173 | } 174 | } 175 | } 176 | ``` 177 | 178 | ## 编译JNI 179 | 180 | ### 编译JNI并且生成APK 181 | 182 | 当`gradle-xmake-plugin`插件被应用生效后,`xmakeBuild`任务会自动注入到现有的`assemble`任务中去,自动执行jni库编译和集成。 183 | 184 | ```console 185 | $ ./gradlew app:assembleDebug 186 | > Task :nativelib:xmakeConfigureForArm64 187 | > Task :nativelib:xmakeBuildForArm64 188 | >> xmake build 189 | [ 50%]: ccache compiling.debug nativelib.cc 190 | [ 75%]: linking.debug libnativelib.so 191 | [100%]: build ok! 192 | >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/arm64-v8a 193 | > Task :nativelib:xmakeConfigureForArmv7 194 | > Task :nativelib:xmakeBuildForArmv7 195 | >> xmake build 196 | [ 50%]: ccache compiling.debug nativelib.cc 197 | [ 75%]: linking.debug libnativelib.so 198 | [100%]: build ok! 199 | >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/armeabi-v7a 200 | > Task :nativelib:preBuild 201 | > Task :nativelib:assemble 202 | > Task :app:assembleDebug 203 | ``` 204 | 205 | ### 强制重建JNI 206 | 207 | ```console 208 | $ ./gradlew nativelib:xmakeRebuild 209 | ``` 210 | 211 | ## Development 212 | 213 | ### 编译插件 214 | 215 | ```console 216 | $ ./gradlew gradle-xmake-plugin:assemble 217 | ``` 218 | 219 | ### 发布插件 220 | 221 | 请参考:[https://guides.gradle.org/publishing-plugins-to-gradle-plugin-portal/](https://guides.gradle.org/publishing-plugins-to-gradle-plugin-portal/) 222 | 223 | ```console 224 | $ ./gradlew gradle-xmake-plugin:publishPlugins 225 | ``` 226 | 227 | ## 联系方式 228 | 229 | * 邮箱:[waruqi@gmail.com](mailto:waruqi@gmail.com) 230 | * 主页:[xmake.io](https://xmake.io/#/zh-cn/) 231 | * 社区 232 | - [Reddit论坛](https://www.reddit.com/r/xmake/) 233 | - [Telegram群组](https://t.me/tbooxorg) 234 | - [Discord聊天室](https://discord.gg/xmake) 235 | - QQ群:343118190, 662147501 236 | * 源码:[Github](https://github.com/xmake-io/xmake), [Gitee](https://gitee.com/tboox/xmake) 237 | * 微信公众号:tboox-os 238 | 239 | ## 支持项目 240 | 241 | xmake-gradle项目属于个人开源项目,它的发展需要您的帮助,如果您愿意支持xmake-gradle项目的开发,欢迎为其捐赠,支持它的发展。 🙏 [[支持此项目](https://opencollective.com/xmake#backer)] 242 | 243 | 244 | 245 | ## 赞助项目 246 | 247 | 通过赞助支持此项目,您的logo和网站链接将显示在这里。[[赞助此项目](https://opencollective.com/xmake#sponsor)] 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 |

xmake-gradle

7 | 8 | 16 | 33 | 34 |

A gradle plugin that integrates xmake seamlessly

35 |
36 | 37 | ## Introduction ([中文](/README_zh.md)) 38 | 39 | xmake-gradle is a gradle plugin that integrates xmake seamlessly. 40 | 41 | If you want to know more, please refer to: 42 | 43 | * [Documents](https://xmake.io/#/home) 44 | * [HomePage](https://xmake.io) 45 | * [Github](https://github.com/xmake-io/xmake-gradle) 46 | * [Gitee](https://gitee.com/tboox/xmake-gradle) 47 | * [GradlePlugin](https://plugins.gradle.org/plugin/org.tboox.gradle-xmake-plugin) 48 | 49 | ## Prerequisites 50 | 51 | XMake installed on the system. Available [here](https://github.com/xmake-io/xmake). 52 | 53 | ## Apply the plugin 54 | 55 | ### plugins DSL 56 | 57 | ``` 58 | plugins { 59 | id 'org.tboox.gradle-xmake-plugin' version '1.2.3' 60 | } 61 | ``` 62 | 63 | ### Legacy plugin application 64 | 65 | ``` 66 | buildscript { 67 | repositories { 68 | maven { 69 | url "https://plugins.gradle.org/m2/" 70 | } 71 | } 72 | dependencies { 73 | classpath 'org.tboox:gradle-xmake-plugin:1.2.3' 74 | } 75 | repositories { 76 | mavenCentral() 77 | } 78 | } 79 | 80 | apply plugin: "org.tboox.gradle-xmake-plugin" 81 | ``` 82 | 83 | ## Configuation 84 | 85 | ### Simplest Example 86 | 87 | We add `xmake.lua` to `projectdir/jni/xmake.lua` and enable xmake in build.gradle. 88 | 89 | #### build.gradle 90 | 91 | ``` 92 | android { 93 | externalNativeBuild { 94 | xmake { 95 | path "jni/xmake.lua" 96 | } 97 | } 98 | } 99 | ``` 100 | 101 | #### JNI 102 | 103 | The JNI project structure: 104 | 105 | ``` 106 | projectdir 107 | - src 108 | - main 109 | - java 110 | - jni 111 | - xmake.lua 112 | - *.cpp 113 | ``` 114 | 115 | xmake.lua: 116 | 117 | ```lua 118 | add_rules("mode.debug", "mode.release") 119 | target("nativelib") 120 | set_kind("shared") 121 | add_files("nativelib.cc") 122 | ``` 123 | 124 | ### More Gradle Configuations 125 | 126 | ``` 127 | android { 128 | defaultConfig { 129 | externalNativeBuild { 130 | xmake { 131 | // append the global cflags (optional) 132 | cFlags "-DTEST" 133 | 134 | // append the global cppflags (optional) 135 | cppFlags "-DTEST", "-DTEST2" 136 | 137 | // switch the build mode to `debug` for `xmake f -m debug` (optional) 138 | buildMode "debug" 139 | 140 | // set abi filters (optional), e.g. armeabi, armeabi-v7a, arm64-v8a, x86, x86_64 141 | // we can also get abiFilters from defaultConfig.ndk.abiFilters 142 | abiFilters "armeabi-v7a", "arm64-v8a" 143 | 144 | // set the built targets 145 | //targets "xxx", "yyy" 146 | } 147 | } 148 | } 149 | 150 | externalNativeBuild { 151 | xmake { 152 | // enable xmake and set xmake.lua project file path 153 | path "jni/xmake.lua" 154 | 155 | // enable verbose output (optional), e.g. verbose, normal 156 | logLevel "verbose" 157 | 158 | // set c++stl (optional), e.g. c++_static/c++_shared, gnustl_static/gnustl_shared, stlport_static/stlport_shared 159 | stl "c++_shared" 160 | 161 | // set the given xmake program path (optional) 162 | // program /usr/local/bin/xmake 163 | 164 | // disable stdc++ library (optional) 165 | // stdcxx false 166 | 167 | // set the given ndk directory path (optional) 168 | // ndk "/Users/ruki/files/android-ndk-r20b/" 169 | 170 | // set sdk version of ndk (optional) 171 | // sdkver 21 172 | } 173 | } 174 | } 175 | ``` 176 | 177 | ## Build 178 | 179 | ### Build JNI and generate apk 180 | 181 | The `xmakeBuild` will be injected to `assemble` task automatically if the gradle-xmake-plugin has been applied. 182 | 183 | ```console 184 | $ ./gradlew app:assembleDebug 185 | > Task :nativelib:xmakeConfigureForArm64 186 | > Task :nativelib:xmakeBuildForArm64 187 | >> xmake build 188 | [ 50%]: ccache compiling.debug nativelib.cc 189 | [ 75%]: linking.debug libnativelib.so 190 | [100%]: build ok! 191 | >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/arm64-v8a 192 | > Task :nativelib:xmakeConfigureForArmv7 193 | > Task :nativelib:xmakeBuildForArmv7 194 | >> xmake build 195 | [ 50%]: ccache compiling.debug nativelib.cc 196 | [ 75%]: linking.debug libnativelib.so 197 | [100%]: build ok! 198 | >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/armeabi-v7a 199 | > Task :nativelib:preBuild 200 | > Task :nativelib:assemble 201 | > Task :app:assembleDebug 202 | ``` 203 | 204 | ### Force to rebuild JNI 205 | 206 | ```console 207 | $ ./gradlew nativelib:xmakeRebuild 208 | ``` 209 | 210 | ## Development 211 | 212 | ### Build Plugins 213 | 214 | ```console 215 | $ ./gradlew gradle-xmake-plugin:assemble 216 | ``` 217 | 218 | ### Publish Plugins 219 | 220 | see [https://guides.gradle.org/publishing-plugins-to-gradle-plugin-portal/](https://guides.gradle.org/publishing-plugins-to-gradle-plugin-portal/) 221 | 222 | ```console 223 | $ ./gradlew gradle-xmake-plugin:publishPlugins 224 | ``` 225 | 226 | ## Contacts 227 | 228 | * Email:[waruqi@gmail.com](mailto:waruqi@gmail.com) 229 | * Homepage:[xmake.io](https://xmake.io) 230 | * Community 231 | - [Chat on Reddit](https://www.reddit.com/r/xmake/) 232 | - [Chat on Telegram](https://t.me/tbooxorg) 233 | - [Chat on Discord](https://discord.gg/xmake) 234 | - Chat on QQ Group: 343118190, 662147501 235 | * Source Code:[GitHub](https://github.com/xmake-io/xmake), [Gitee](https://gitee.com/tboox/xmake) 236 | * WeChat Public: tboox-os 237 | 238 | ## Backers 239 | 240 | Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/xmake#backer)] 241 | 242 | 243 | 244 | ## Sponsors 245 | 246 | Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/xmake#sponsor)] 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH="\\\"\\\"" 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | if ! command -v java >/dev/null 2>&1 137 | then 138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 139 | 140 | Please set the JAVA_HOME variable in your environment to match the 141 | location of your Java installation." 142 | fi 143 | fi 144 | 145 | # Increase the maximum file descriptors if we can. 146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 147 | case $MAX_FD in #( 148 | max*) 149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 150 | # shellcheck disable=SC2039,SC3045 151 | MAX_FD=$( ulimit -H -n ) || 152 | warn "Could not query maximum file descriptor limit" 153 | esac 154 | case $MAX_FD in #( 155 | '' | soft) :;; #( 156 | *) 157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 158 | # shellcheck disable=SC2039,SC3045 159 | ulimit -n "$MAX_FD" || 160 | warn "Could not set maximum file descriptor limit to $MAX_FD" 161 | esac 162 | fi 163 | 164 | # Collect all arguments for the java command, stacking in reverse order: 165 | # * args from the command line 166 | # * the main class name 167 | # * -classpath 168 | # * -D...appname settings 169 | # * --module-path (only if needed) 170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 171 | 172 | # For Cygwin or MSYS, switch paths to Windows format before running java 173 | if "$cygwin" || "$msys" ; then 174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 176 | 177 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 178 | 179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 180 | for arg do 181 | if 182 | case $arg in #( 183 | -*) false ;; # don't mess with options #( 184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 185 | [ -e "$t" ] ;; #( 186 | *) false ;; 187 | esac 188 | then 189 | arg=$( cygpath --path --ignore --mixed "$arg" ) 190 | fi 191 | # Roll the args list around exactly as many times as the number of 192 | # args, so each arg winds up back in the position where it started, but 193 | # possibly modified. 194 | # 195 | # NB: a `for` loop captures its iteration list before it begins, so 196 | # changing the positional parameters here affects neither the number of 197 | # iterations, nor the values presented in `arg`. 198 | shift # remove old arg 199 | set -- "$@" "$arg" # push replacement arg 200 | done 201 | fi 202 | 203 | 204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 206 | 207 | # Collect all arguments for the java command: 208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 209 | # and any embedded shellness will be escaped. 210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 211 | # treated as '${Hostname}' itself on the command line. 212 | 213 | set -- \ 214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 215 | -classpath "$CLASSPATH" \ 216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ 217 | "$@" 218 | 219 | # Stop when "xargs" is not available. 220 | if ! command -v xargs >/dev/null 2>&1 221 | then 222 | die "xargs is not available" 223 | fi 224 | 225 | # Use "xargs" to parse quoted args. 226 | # 227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 228 | # 229 | # In Bash we could simply go: 230 | # 231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 232 | # set -- "${ARGS[@]}" "$@" 233 | # 234 | # but POSIX shell has neither arrays nor command substitution, so instead we 235 | # post-process each arg (as a line of input to sed) to backslash-escape any 236 | # character that might be a shell metacharacter, then use eval to reverse 237 | # that process (while maintaining the separation between arguments), and wrap 238 | # the whole thing up as a single "set" statement. 239 | # 240 | # This will of course break if any of these variables contains a newline or 241 | # an unmatched quote. 242 | # 243 | 244 | eval "set -- $( 245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 246 | xargs -n1 | 247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 248 | tr '\n' ' ' 249 | )" '"$@"' 250 | 251 | exec "$JAVACMD" "$@" 252 | -------------------------------------------------------------------------------- /gradle-xmake-plugin/src/main/groovy/org/tboox/gradle/XMakePlugin.groovy: -------------------------------------------------------------------------------- 1 | /*!A gradle plugin that integrates xmake seamlessly 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright (C) 2020-present, TBOOX Open Source Group. 16 | * 17 | * @author ruki 18 | * @file XMakePlugin.groovy 19 | * 20 | */ 21 | package org.tboox.gradle 22 | 23 | import com.android.build.gradle.AppExtension 24 | import com.android.build.gradle.LibraryExtension 25 | import org.gradle.api.* 26 | 27 | import java.util.logging.Logger 28 | 29 | class XMakePlugin implements Plugin { 30 | 31 | // tag 32 | private final String TAG = "plugin" 33 | 34 | // logger 35 | private XMakeLogger logger 36 | 37 | // project context 38 | private XMakeTaskContext projectContext 39 | 40 | // the architecture maps 41 | private Map archMaps = [Arm64: "arm64-v8a", Armv7: "armeabi-v7a", Arm: "armeabi", RiscV64: "riscv64", X64: "x86_64", X86: "x86"] 42 | 43 | // the forName maps 44 | private Map forNameMaps = ["arm64-v8a": "Arm64", "armeabi-v7a": "Armv7", "armeabi": "Arm", "riscv64": "RiscV64", "x86_64": "X64", "x86": "X86"] 45 | 46 | // the forName lists 47 | private List forNames = ["Arm64", "Armv7", "Arm", "RiscV64", "X64", "X86"] 48 | 49 | @Override 50 | void apply(Project project) { 51 | 52 | // create xmake plugin extension 53 | XMakePluginExtension extension = project.extensions.create('xmake', XMakePluginExtension) 54 | 55 | project.afterEvaluate { 56 | 57 | // init logger 58 | logger = new XMakeLogger(extension) 59 | 60 | // check project file exists (jni/xmake.lua) 61 | projectContext = new XMakeTaskContext(extension, project, logger) 62 | File projectFile = projectContext.projectFile 63 | if (projectFile == null || !projectFile.isFile()) { 64 | return 65 | } 66 | 67 | // trace 68 | logger.i(TAG, "activated for project: " + project.name) 69 | 70 | // register tasks: xmakeConfigureForXXX 71 | registerXMakeConfigureTasks(project, extension, logger) 72 | 73 | // register tasks: xmakeBuildForXXX 74 | registerXMakeBuildTasks(project, extension, logger) 75 | 76 | // register tasks: xmakeRebuildForXXX 77 | registerXMakeRebuildTasks(project, extension, logger) 78 | 79 | // register tasks: xmakeInstall 80 | registerXMakeInstallTasks(project, extension, logger) 81 | 82 | // register tasks: xmakeCleanForXXX 83 | registerXMakeCleanTasks(project, extension, logger) 84 | 85 | // register build task to the beginning of preBuild task 86 | def preBuildTask = project.tasks.named("preBuild") 87 | if (preBuildTask != null) { 88 | preBuildTask.configure { Task task -> 89 | task.dependsOn("xmakeInstall") 90 | } 91 | } 92 | 93 | // register clean task to the beginning of clean task 94 | def cleanTask = project.tasks.named("clean") 95 | if (cleanTask != null) { 96 | cleanTask.configure { Task task -> 97 | task.dependsOn("xmakeClean") 98 | } 99 | } 100 | } 101 | } 102 | 103 | private registerXMakeConfigureTasks(Project project, XMakePluginExtension extension, XMakeLogger logger) { 104 | for (String name : forNames) { 105 | project.tasks.register("xmakeConfigureFor" + name, XMakeConfigureTask, new Action() { 106 | @Override 107 | void execute(XMakeConfigureTask task) { 108 | String forName = task.name.split("For")[1] 109 | task.taskContext = new XMakeTaskContext(extension, project, logger, archMaps[forName]) 110 | } 111 | }) 112 | } 113 | } 114 | 115 | private registerXMakeBuildTasks(Project project, XMakePluginExtension extension, XMakeLogger logger) { 116 | for (String name : forNames) { 117 | def buildTask = project.tasks.register("xmakeBuildFor" + name, XMakeBuildTask, new Action() { 118 | @Override 119 | void execute(XMakeBuildTask task) { 120 | String forName = task.name.split("For")[1] 121 | task.taskContext = new XMakeTaskContext(extension, project, logger, archMaps[forName]) 122 | } 123 | }) 124 | buildTask.configure { Task task -> 125 | String forName = task.name.split("For")[1] 126 | task.dependsOn("xmakeConfigureFor" + forName) 127 | } 128 | } 129 | def buildTask = project.tasks.register("xmakeBuild", XMakeBuildTask, new Action() { 130 | @Override 131 | void execute(XMakeBuildTask task) { 132 | } 133 | }) 134 | buildTask.configure { Task task -> 135 | if (projectContext.abiFilters != null) { 136 | for (String filter: projectContext.abiFilters) { 137 | String forName = forNameMaps[filter] 138 | if (forName == null) { 139 | throw new GradleException("invalid abiFilter: " + filter) 140 | } 141 | task.dependsOn("xmakeBuildFor" + forName) 142 | } 143 | } else { 144 | task.dependsOn("xmakeBuildForArmv7") 145 | } 146 | } 147 | } 148 | 149 | private registerXMakeRebuildTasks(Project project, XMakePluginExtension extension, XMakeLogger logger) { 150 | for (String name : forNames) { 151 | def rebuildTask = project.tasks.register("xmakeRebuildFor" + name, XMakeRebuildTask, new Action() { 152 | @Override 153 | void execute(XMakeRebuildTask task) { 154 | String forName = task.name.split("For")[1] 155 | task.taskContext = new XMakeTaskContext(extension, project, logger, archMaps[forName]) 156 | } 157 | }) 158 | rebuildTask.configure { Task task -> 159 | String forName = task.name.split("For")[1] 160 | task.dependsOn("xmakeConfigureFor" + forName) 161 | } 162 | } 163 | def rebuildTask = project.tasks.register("xmakeRebuild", XMakeRebuildTask, new Action() { 164 | @Override 165 | void execute(XMakeRebuildTask task) { 166 | } 167 | }) 168 | rebuildTask.configure { Task task -> 169 | if (projectContext.abiFilters != null) { 170 | for (String filter: projectContext.abiFilters) { 171 | String forName = forNameMaps[filter] 172 | if (forName == null) { 173 | throw new GradleException("invalid abiFilter: " + filter) 174 | } 175 | task.dependsOn("xmakeRebuildFor" + forName) 176 | } 177 | } else { 178 | task.dependsOn("xmakeRebuildForArmv7") 179 | } 180 | } 181 | } 182 | 183 | private registerXMakeInstallTasks(Project project, XMakePluginExtension extension, XMakeLogger logger) { 184 | for (String name : forNames) { 185 | def installTask = project.tasks.register("xmakeInstallFor" + name, XMakeInstallTask, new Action() { 186 | @Override 187 | void execute(XMakeInstallTask task) { 188 | String forName = task.name.split("For")[1] 189 | task.taskContext = new XMakeTaskContext(extension, project, logger, archMaps[forName]) 190 | } 191 | }) 192 | installTask.configure { Task task -> 193 | String forName = task.name.split("For")[1] 194 | task.dependsOn("xmakeBuildFor" + forName) 195 | } 196 | } 197 | def installTask = project.tasks.register("xmakeInstall", XMakeInstallTask, new Action() { 198 | @Override 199 | void execute(XMakeInstallTask task) { 200 | } 201 | }) 202 | installTask.configure { Task task -> 203 | if (projectContext.abiFilters != null) { 204 | for (String filter: projectContext.abiFilters) { 205 | String forName = forNameMaps[filter] 206 | if (forName == null) { 207 | throw new GradleException("invalid abiFilter: " + filter) 208 | } 209 | task.dependsOn("xmakeInstallFor" + forName) 210 | } 211 | } else { 212 | task.dependsOn("xmakeInstallForArmv7") 213 | } 214 | } 215 | } 216 | 217 | private registerXMakeCleanTasks(Project project, XMakePluginExtension extension, XMakeLogger logger) { 218 | for (String name : forNames) { 219 | def cleanTask = project.tasks.register("xmakeCleanFor" + name, XMakeCleanTask, new Action() { 220 | @Override 221 | void execute(XMakeCleanTask task) { 222 | String forName = task.name.split("For")[1] 223 | task.taskContext = new XMakeTaskContext(extension, project, logger, archMaps[forName]) 224 | } 225 | }) 226 | cleanTask.configure { Task task -> 227 | String forName = task.name.split("For")[1] 228 | task.dependsOn("xmakeConfigureFor" + forName) 229 | } 230 | } 231 | def cleanTask = project.tasks.register("xmakeClean", XMakeCleanTask, new Action() { 232 | @Override 233 | void execute(XMakeCleanTask task) { 234 | } 235 | }) 236 | cleanTask.configure { Task task -> 237 | if (projectContext.abiFilters != null) { 238 | for (String filter: projectContext.abiFilters) { 239 | String forName = forNameMaps[filter] 240 | if (forName == null) { 241 | throw new GradleException("invalid abiFilter: " + filter) 242 | } 243 | task.dependsOn("xmakeCleanFor" + forName) 244 | } 245 | } else { 246 | task.dependsOn("xmakeCleanForArmv7") 247 | } 248 | } 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2015-2020 TBOOX Open Source Group 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | --------------------------------------------------------------------------------