All Projects → howardpang → androidNativeBundle

howardpang / androidNativeBundle

Licence: Apache-2.0 license
a gradle plugin that support publish c/c++ headers to 'aar' and depend those 'aar'

Programming Languages

groovy
2714 projects

Projects that are alternatives of or similar to androidNativeBundle

StaticBus
🚌 A static bus use in modules.
Stars: ✭ 15 (-75%)
Mutual labels:  gradle-plugin
gradle-plugin-bootstrap
All you need to create a custom Gradle plugin
Stars: ✭ 24 (-60%)
Mutual labels:  gradle-plugin
vehicle-commander-java
The Vehicle Commander template demonstrates best practices for building in-vehicle military applications with ArcGIS Runtime. The Vehicle Commander template contains source code for an in-vehicle application.
Stars: ✭ 16 (-73.33%)
Mutual labels:  native-development
kobby
Kobby is a codegen plugin of Kotlin DSL Client by GraphQL schema. The generated DSL supports execution of complex GraphQL queries, mutation and subscriptions in Kotlin with syntax similar to native GraphQL syntax.
Stars: ✭ 52 (-13.33%)
Mutual labels:  gradle-plugin
android-gradle-plugins
Gradle Plugins for Android builds
Stars: ✭ 12 (-80%)
Mutual labels:  gradle-plugin
metalava-gradle
A Gradle plugin for Metalava, AOSP's tool for API metadata extraction and compatibility tracking.
Stars: ✭ 29 (-51.67%)
Mutual labels:  gradle-plugin
bye-bye-jetifier
Gradle Plugin to verify if you can keep Android Jetifier disabled
Stars: ✭ 173 (+188.33%)
Mutual labels:  gradle-plugin
kfc-plugins
Kotlin/JS Fast Configuration
Stars: ✭ 37 (-38.33%)
Mutual labels:  gradle-plugin
gradle-android-emulator
Gradle plugin for starting the Android Emulator when running instrumentation tests
Stars: ✭ 30 (-50%)
Mutual labels:  gradle-plugin
android-buddy
Transform Android project classes with Byte Buddy at compile time
Stars: ✭ 42 (-30%)
Mutual labels:  gradle-plugin
corda-gradle-plugins
Gradle plugins used by Corda and Cordapps
Stars: ✭ 21 (-65%)
Mutual labels:  gradle-plugin
allure-gradle
Allure Gradle Plugin
Stars: ✭ 62 (+3.33%)
Mutual labels:  gradle-plugin
Robfuscate
Obfuscate the int index of R.id/R.string/R.layout… in the classes.dex of Android project
Stars: ✭ 56 (-6.67%)
Mutual labels:  gradle-plugin
dockerPreparePlugin
Gradle plugin to generate docker layer-friendly directory for spring boot applications
Stars: ✭ 44 (-26.67%)
Mutual labels:  gradle-plugin
secrets-gradle-plugin
A Gradle plugin for providing your secrets to your Android project.
Stars: ✭ 475 (+691.67%)
Mutual labels:  gradle-plugin
chainsaw
Gradle plugin: adds support for building Java 9 modules.
Stars: ✭ 71 (+18.33%)
Mutual labels:  gradle-plugin
xjc-generation-gradle-plugin
A Gradle Plugin for generating JAXB Java sources using the XJC compiler
Stars: ✭ 20 (-66.67%)
Mutual labels:  gradle-plugin
laboratory
Feature flags for multi-module Kotlin Android projects
Stars: ✭ 71 (+18.33%)
Mutual labels:  gradle-plugin
gradle-git-versioning-plugin
This extension will set project version, based on current Git branch or tag.
Stars: ✭ 44 (-26.67%)
Mutual labels:  gradle-plugin
gradle-versioneye-plugin
Plugin for Gradle to update your project's dependencies status on www.versioneye.com
Stars: ✭ 31 (-48.33%)
Mutual labels:  gradle-plugin

NativeBundle

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

  • android gradle plugin 3.0.0 - 7.0.3

Build and Test

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

Usage

1.Edit your root build.gradle file, add classpath 'io.github.howardpang:androidNativeBundle:1.1.1' to the file

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        //Add androidNativeBundle dependency
        classpath "io.github.howardpang:androidNativeBundle:1.1.1"
    }
}

2. Export header to aar

1. Apply plugin to your lib, add following line to your lib build.gradle
apply plugin: 'com.android.library'
apply plugin: 'com.ydq.android.gradle.native-aar.export' // must below android gradle plugin
2. Specify header path that you want to export, add following code segment to your lib build.gradle;
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")
}
3.The plugin also support flavours feature, you can add this code to flavour configure, like this:
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")
        }
    }
}
4.Because publish more than one static library will cause link order problem, so you can specify link order, for example libxx.a should link before libyy.a, like this:
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"
}
5. Android lib only packet shared library(so) to aar, this plugin can generate another aar to packet static library ,if you set 'bundleStatic',the plugin will gather static lib from 'externalNativeBuild' output dir default, you can specify other dir by set 'extraStaticLibDir' in 'nativeBundleExport', you can also exclude some static lib;
Default, the plugin will create a "bundleStaticLibRelease" task to packet the static bundle, but if you use flavours feature, the plugin will create "bundleStaticLib${flavourName}Release" for every flavour;
After you configure, you can add static publication to your publish script, like this:
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
        }
    }
}

3. Import aar

1. Apply plugin to your lib/app, add following line to your lib/app build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.ydq.android.gradle.native-aar.import' // must below android gradle plugin
2. If you use 'externalNativeBuild' to build, there are two ways to build
  • ndkBuild: Add this line
    include ${ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK} #must be before "include $(BUILD_SHARED_LIBRARY)" or "include $(BUILD_STATIC_LIBRARY)"
    to every module that you want in Android.mk, like this
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: Add this line
    include (${ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK})
    to CMakeLists.txt; Then link modules if the target needed
    target_link_libraries(<target> ${ANDROID_GRADLE_NATIVE_MODULES})
    like this
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)
3. If you use custom command ndk-build
  • Add following line to every module you want like "externalNativeBuild:ndkBuild"
  • Add macro
    "ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK=${nativeBundleImport.ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK}"
    to your ndk-build, like this
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}"]
4. If you want to link some static library with whole archive, you can set it in build.gradle like this
nativeBundleImport {
    wholeStaticLibs = "libxx.a:libyy.a" // Library is seperated by colon
}
5. If your module have below dependency , the plugin will put the so in to 'aar' and add it to native compile
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'
}
6. If you don't want to add some dependency to native compile, for example, you have 'implementation "com.my.group:moduleA:1.0.0" ' dependency and it contain native interface, you can do like this
nativeBundleImport {
    //wholeStaticLibs = "libxx.a:libyy.a" // Library is seperated by colon
    excludeDependencies.add("com.my.group:moduleA")
    excludeDependencies.add("com.my.group:moduleB")
}
7. The plugin will extract headers(include) and library to "${project.projectDir}/build/nativeLib/", you can find what interfaces that aar contain
8. If android studio IDE can't parse those headers when you edit c/c++ source and press 'Sync Project With Gradle Files' button to re-sync project
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].