Skip to content

Commit

Permalink
Switch to Prefab package format.
Browse files Browse the repository at this point in the history
  • Loading branch information
caikelun committed Feb 5, 2021
1 parent ff40b1b commit 167d0b0
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 216 deletions.
79 changes: 28 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.1-red.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.2-red.svg?style=flat)
![](https://img.shields.io/badge/Android-4.1%20--%2011-blue.svg?style=flat)
![](https://img.shields.io/badge/arch-armeabi--v7a%20%7C%20arm64--v8a%20%7C%20x86%20%7C%20x86__64-blue.svg?style=flat)

Expand Down Expand Up @@ -41,76 +41,45 @@ If xDL is compiled into an independent dynamic library:

## Usage

xDL uses [Prefab](https://google.github.io/prefab/) package format, which is supported by Android Gradle Plugin 4.0+.

More information: [Using native dependencies](https://developer.android.com/studio/build/native-dependencies)

### 1. Add dependency in build.gradle

```Gradle
ext {
XDL_VERSION = '1.0.1'
android {
buildFeatures {
prefab true
}
}
dependencies {
implementation "io.hexhacking.xdl:xdl-android-lib:${XDL_VERSION}"
implementation 'io.hexhacking.xdl:xdl-android-lib:1.0.2'
}
apply from: "https://raw.githubusercontent.com/hexhacking/xDL/master/gradle/nativedeps.gradle"
```

If your network is restricted, please try:

```Gradle
apply from: "https://gitlab.com/hexhacking/xDL/-/raw/master/gradle/nativedeps.gradle"
```

Or:

```Gradle
apply from: "https://gitee.com/hexhacking/xDL/raw/master/gradle/nativedeps.gradle"
```

Of course, you can also download this script and put it in your own project.

`nativedeps.gradle` will download xDL header file and dynamic library to the `build` directory.

### 2. Add dependency in CMakeLists.txt or Android.mk

> CMakeLists.txt
```CMake
# xDL base path (you may need to modify this path)
set(XDL_BASE ${CMAKE_CURRENT_SOURCE_DIR}/../../../build/nativedeps/xdl)
find_package(xdl REQUIRED CONFIG)
# import xDL
add_library(xdl SHARED IMPORTED)
set_target_properties(xdl PROPERTIES
IMPORTED_LOCATION ${XDL_BASE}/aar/jni/${ANDROID_ABI}/libxdl.so
INTERFACE_INCLUDE_DIRECTORIES ${XDL_BASE}/header
)
# your library
add_library(mylib SHARED mylib.c)
target_link_libraries(mylib xdl)
target_link_libraries(mylib xdl::xdl)
```

> Android.mk
```
# xDL base path (you may need to modify this path)
LOCAL_PATH := $(call my-dir)
XDL_BASE := $(LOCAL_PATH)/../../../build/nativedeps/xdl
# import xDL
include $(CLEAR_VARS)
LOCAL_MODULE := xdl
LOCAL_SRC_FILES := $(XDL_BASE)/aar/jni/$(TARGET_ARCH_ABI)/libxdl.so
LOCAL_EXPORT_C_INCLUDES := $(XDL_BASE)/header
include $(PREBUILT_SHARED_LIBRARY)
# your library
include $(CLEAR_VARS)
LOCAL_MODULE := mylib
LOCAL_SRC_FILES := mylib.c
LOCAL_SHARED_LIBRARIES += xdl
LOCAL_MODULE := mylib
LOCAL_SRC_FILES := mylib.c
LOCAL_SHARED_LIBRARIES += xdl
include $(BUILD_SHARED_LIBRARY)
$(call import-module,prefab/xdl)
```

### 3. Specify one or more ABI(s) you need
Expand All @@ -125,7 +94,7 @@ android {
}
```

### 4. Exclude libxdl.so when packaging (Optional)
### 4. Add packaging options

If you are using xDL in an SDK project, you may need to avoid packaging libxdl.so into your AAR, so as not to encounter duplicate libxdl.so file when packaging the app project.

Expand All @@ -137,13 +106,21 @@ android {
}
```

On the other hand, if you are using xDL in an APP project, you may need to add some options to deal with conflicts caused by duplicate libxdl.so file.

```Gradle
android {
packagingOptions {
pickFirst '**/libxdl.so'
}
}
```

There is a sample app in the [xdl-sample](xdl_sample) folder you can refer to.


## API

include xDL's header file:

```C
#include "xdl.h"
```
Expand Down
79 changes: 28 additions & 51 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.1-red.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.2-red.svg?style=flat)
![](https://img.shields.io/badge/Android-4.1%20--%2011-blue.svg?style=flat)
![](https://img.shields.io/badge/arch-armeabi--v7a%20%7C%20arm64--v8a%20%7C%20x86%20%7C%20x86__64-blue.svg?style=flat)

Expand Down Expand Up @@ -41,76 +41,45 @@ xDL 是 Android DL 系列函数的增强实现。

## 使用

xDL 使用从 Android Gradle Plugin 4.0+ 开始支持的 [Prefab](https://google.github.io/prefab/) 包格式。

更多信息: [使用 native 依赖项](https://developer.android.com/studio/build/native-dependencies)

### 1. 在 build.gradle 中增加依赖

```Gradle
ext {
XDL_VERSION = '1.0.1'
android {
buildFeatures {
prefab true
}
}
dependencies {
implementation "io.hexhacking.xdl:xdl-android-lib:${XDL_VERSION}"
implementation 'io.hexhacking.xdl:xdl-android-lib:1.0.2'
}
apply from: "https://raw.githubusercontent.com/hexhacking/xDL/master/gradle/nativedeps.gradle"
```

如果你的网络受到了限制,请试一试:

```Gradle
apply from: "https://gitlab.com/hexhacking/xDL/-/raw/master/gradle/nativedeps.gradle"
```

或者:

```Gradle
apply from: "https://gitee.com/hexhacking/xDL/raw/master/gradle/nativedeps.gradle"
```

当然,你也可以把这个脚本下载后放在你自己的工程里。

`nativedeps.gradle` 将把 xDL 的头文件和动态库下载到 `build` 目录中。

### 2. 在 CMakeLists.txt 或 Android.mk 中增加依赖

> CMakeLists.txt
```CMake
# xDL base 路径 (你可能需要修改这个路径)
set(XDL_BASE ${CMAKE_CURRENT_SOURCE_DIR}/../../../build/nativedeps/xdl)
find_package(xdl REQUIRED CONFIG)
# 导入 xDL
add_library(xdl SHARED IMPORTED)
set_target_properties(xdl PROPERTIES
IMPORTED_LOCATION ${XDL_BASE}/aar/jni/${ANDROID_ABI}/libxdl.so
INTERFACE_INCLUDE_DIRECTORIES ${XDL_BASE}/header
)
# 你的动态库
add_library(mylib SHARED mylib.c)
target_link_libraries(mylib xdl)
target_link_libraries(mylib xdl::xdl)
```

> Android.mk
```
# xDL base 路径 (你可能需要修改这个路径)
LOCAL_PATH := $(call my-dir)
XDL_BASE := $(LOCAL_PATH)/../../../build/nativedeps/xdl
# 导入 xDL
include $(CLEAR_VARS)
LOCAL_MODULE := xdl
LOCAL_SRC_FILES := $(XDL_BASE)/aar/jni/$(TARGET_ARCH_ABI)/libxdl.so
LOCAL_EXPORT_C_INCLUDES := $(XDL_BASE)/header
include $(PREBUILT_SHARED_LIBRARY)
# 你的动态库
include $(CLEAR_VARS)
LOCAL_MODULE := mylib
LOCAL_SRC_FILES := mylib.c
LOCAL_SHARED_LIBRARIES += xdl
LOCAL_MODULE := mylib
LOCAL_SRC_FILES := mylib.c
LOCAL_SHARED_LIBRARIES += xdl
include $(BUILD_SHARED_LIBRARY)
$(call import-module,prefab/xdl)
```

### 3. 指定一个或多个你需要的 ABI
Expand All @@ -125,7 +94,7 @@ android {
}
```

### 4. 打包时排除 libxdl.so (可选的)
### 4. 增加打包选项

如果你是在一个 SDK 工程里使用 xDL,你可能需要避免把 libxdl.so 打包到你的 AAR 里,以免 app 工程打包时遇到重复的 libxdl.so 文件。

Expand All @@ -137,13 +106,21 @@ android {
}
```

另一方便, 如果你是在一个 APP 工程里使用 xDL,你可以需要增加一些选项,用来处理重复的 libxdl.so 文件引起的冲突。

```Gradle
android {
packagingOptions {
pickFirst '**/libxdl.so'
}
}
```

你可以参考 [xdl-sample](xdl_sample) 文件中的示例 app。


## API

包含 xDL 的头文件:

```C
#include "xdl.h"
```
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ buildscript {

allprojects {
repositories {
// mavenLocal()
google()
jcenter()
}
Expand All @@ -33,7 +34,7 @@ ext {

POM_GROUP_ID = "io.hexhacking.xdl"
POM_ARTIFACT_ID = "xdl-android-lib"
POM_VERSION_NAME = "1.0.1"
POM_VERSION_NAME = "1.0.2"

POM_NAME = "xDL Android Lib"
POM_DESCRIPTION = "xDL is an enhanced implementation of the Android DL series functions."
Expand Down
62 changes: 0 additions & 62 deletions gradle/nativedeps.gradle

This file was deleted.

12 changes: 0 additions & 12 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,13 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}

task nativesymbolZip(type: Zip, dependsOn: 'build') {
archiveClassifier.set("native-symbol")
from file("build/intermediates/cmake/release/obj/")
}

task nativeheaderZip(type: Zip) {
archiveClassifier.set("native-header")
EXPORTED_NATIVE_HEADERS.each { from file(it) }
}

project.afterEvaluate {
publishing.publications {
mavenAar(MavenPublication) {
from components.release

artifact sourcesJar
artifact javadocJar
artifact nativesymbolZip
artifact nativeheaderZip

artifactId POM_ARTIFACT_ID
groupId POM_GROUP_ID
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include ':xdl_lib'
include ':xdl'
include ':xdl_sample'
rootProject.name = "xDL"
File renamed without changes.
Loading

0 comments on commit 167d0b0

Please sign in to comment.