How can I package header files with android aar file

Viewed 928

I have a C++ module which builds to an aar file that contains a .so of the module. In order to use this in another project I need not only the .so but it's associated header files. I thought perhaps I could simply include the C++ header files in the .aar file but when importing an aar it doesn't appear that Android Studio unzips the .aar to make the header files visible.

How would I configure Android Studio/CMake to include header files in the .aar?

If I have a .aar file with header files, how can I make reference to the C++ header files when importing into Android Studio or do I need to unzip the .aar file instead of importing it into Android Studio?

1 Answers

this might help you click me!

Try to use AndroidNativeBundle plugin.

  • 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"
    }
}
  • Apply plugin to your lib, add following line to your lib build.gradle
plugins {
    id 'com.android.library'
    id 'com.ydq.android.gradle.native-aar.export'
}
  • Specify header path that you want to export, add following code segment to your lib build.gradle;
nativeBundleExport {
    headerDir = "${project.projectDir}/native/export/header/path"
}
Related