Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NDK: Is it possible to define the android NDK Version in build.gradle so the native code will use a defined version?

Here's my problem:

I've got a library stored at Github. That Library contains native code and everything that's needed for handling C++ files. Locally the project/library works fine but I want to include that library as a dependency via JitPack. So that's where the problem starts...

JitPack seems to use the newest version of NDK but that's not the version my code can be built with. For now, there's no time to update my library but can't find any solution to define the NDK version as a dependency to the project.

I know that ndk.dir can be defined at local.properties but that file should not be part of the repo. I wonder if there's a way to tell JitPack which NDK-Version it should use to build the dependency.

I'm curious if any of you already had a similar problem and if anyone has an idea how to solve it.

I appreciate any idea. :)

like image 204
Thomas Cirksena Avatar asked Sep 27 '19 07:09

Thomas Cirksena


People also ask

Which version of NDK should I use?

You should always be using the latest NDK for the best behavior (possibly N-1 if there's a bug in the latest stable, but that won't be the average case). It does sound like your APP_PLATFORM is set to a newer platform than the device you're trying to run on. APP_PLATFORM is a minimum supported version.

How do I know what version of Android NDK I have?

Go to Tools->SDK Manager (or Files->Settings->Appearance & Behavior->System Settings->Android SDK ). Then select the SDK Tools tab, and check the Show Package Details checkbox. You will see your NDK version.

How does an Android APK execute compiled native code using the Java native interface?

Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE's integrated build system. Your Java code can then call functions in your native library through the Java Native Interface (JNI) framework.


1 Answers

Today, Android Studio plugin supports side-by-side NDK, and the SDK Manager can manage multiple versions of NDK. In gradle.build, you set e.g. android.ndkVersion '19.2.5345600'. You can probably trigger SDK Manager programmatically to install the expected version.

Note that sharing local.properties would not help, because it points to NDK installed directory (which depends on the PC configuration), and does not store the NDK version.

like image 175
Alex Cohn Avatar answered Sep 24 '22 03:09

Alex Cohn