Home > Enterprise >  Gradle plugin for Android that generates native library
Gradle plugin for Android that generates native library

Time:07-13

I'm trying to create a gradle plugin for Android that generates code.

I want the gradle plugin to generate code that will be compiled to a native library at application build time.

Generating the code is easy but I'm not sure how I can compile it to a native library. I've tried using kotlin native. However, I can't seem to find a way for the gradle plugin to perform native compilation using kotlin native.

CodePudding user response:

What you are doing is possible - here are the official docs about how to build plain c/c code for Android(basically everything you need to know). It won't be gradle building native, though - the build will be dependent on either CMake(supports building for arbitrary platforms) or ndk-build(supports only android native build).

Basically, you have to generate your code into a cpp folder of your project and Gradle will automatically(almost) know what to do. Well in order to do that you would have to first set up CMake or ndk-build config files.

JNI files generation would be a good idea also, rather than writing all the dull JNI boilerplate manually.

Personally, I was not generating c code but I used the complete set of further steps: setting up build files, compiling, and building. I mostly used official docs for that, with occasional googling, so you ought to be covered here, mate.

CodePudding user response:

I am sure this question has been addressed before: https://developer.android.com/studio/projects/gradle-external-native-builds

Take a look at this official documentation

  • Related