nativeBundle plugin is a gradle plugin that extend bundle task provided by android gradle plugin,it can help you publish c/c++ headers and other module that contain native source can dependent those module directly
1.Android studio import this project
2.Enter 'gradlew publishToMavenLocal' command in Terminal or click 'publishToMavenLocal' task in gradle task list
3.Open settings.gradle, include 'app' project and build it
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
//Add androidNativeBundle dependency
classpath "io.github.howardpang:androidNativeBundle:1.1.5"
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.ydq.android.gradle.native-aar.export' // must below android gradle plugin
nativeBundleExport {
headerDir = "${project.projectDir}/src/main/jni/include"
//excludeHeaderFilter.add("**/**.cpp")
//includeHeaderFilter.add("**/**.h")
//bundleStatic = true
//extraStaticLibDir = "${project.projectDir}/xx"
//excludeStaticLibs.add("**/libmylib.a")
//excludeStaticLibs.add("**/libxx.a")
}
productFlavors {
flavorDimensions "default"
export {
dimension "default"
nativeBundleExport {
headerDir = "${project.projectDir}/src/main/jni/include"
//excludeHeaderFilter.add("**/**.cpp")
//includeHeaderFilter.add("**/**.h")
//bundleStatic = true
//extraStaticLibDir = "${project.projectDir}/xx"
//excludeStaticLibs.add("**/libmylib.a")
//excludeStaticLibs.add("**/libxx.a")
}
}
}
nativeBundleExport {
headerDir = "${project.projectDir}/src/main/jni/include"
//excludeHeaderFilter.add("**/**.cpp")
//includeHeaderFilter.add("**/**.h")
bundleStatic = true
//extraStaticLibDir = "${project.projectDir}/xx"
//excludeStaticLibs.add("**/libmylib.a")
//excludeStaticLibs.add("**/libxx.a")
linkOrder = "libxx.a:libyy.a"
}
publishing {
publications {
maven(MavenPublication) {
groupId 'com.ydq.android.native-aar'
artifactId "mylib"
artifact bundleRelease
}
mavenStaticBundle(MavenPublication) {
groupId 'com.ydq.android.native-aar'
artifactId "mylib-static"
artifact bundleStaticLibRelease
}
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.ydq.android.gradle.native-aar.import' // must below android gradle plugin
include $(CLEAR_VARS)
LOCAL_SRC_FILES := myapp.cpp \
LOCAL_MODULE := myapp
LOCAL_LDLIBS += -llog
include ${ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK} #must followed by "include $(BUILD_SHARED_LIBRARY)" or "include $(BUILD_STATIC_LIBRARY)"
include $(BUILD_SHARED_LIBRARY)
cmake_minimum_required(VERSION 3.4.1)
project(echo LANGUAGES C CXX)
add_library(myapp
SHARED
myapp.cpp)
target_link_libraries(myapp
log
)
include (${ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK})
target_link_libraries(myapp ${ANDROID_GRADLE_NATIVE_MODULES})
target_compile_options(myapp
PRIVATE
-Wall -Werror)
def execmd = ["$ndkbuildcmd", "-j${coreNum}", "V=1", "NDK_PORJECT_PATH=$buildDir",
"APP_BUILD_SCRIPT=$androidMKfile", "NDK_APPLICATION_MK=$applicationMKfile", "ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK=${nativeBundleImport.ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK}"]
nativeBundleImport {
wholeStaticLibs = "libxx.a:libyy.a" // Library is seperated by colon
}
dependencies {
implementation "com.my.group:module:1.0.0:armeabi-v7a@so"
implementation "com.my.group:module:1.0.0:armeabi-v7a@har" // contain 'headers'
}
nativeBundleImport {
//wholeStaticLibs = "libxx.a:libyy.a" // Library is seperated by colon
excludeDependencies.add("com.my.group:moduleA")
excludeDependencies.add("com.my.group:moduleB")
}