Issue
In old traditional android ndk we will specify the static library to be linked in the Android.mk file.
Android.mk
PLATFORM_PREFIX := /opt/android-ext/
LOCAL_PATH := $(PLATFORM_PREFIX)/lib
include $(CLEAR_VARS)
LOCAL_MODULE := library
LOCAL_SRC_FILES := library.a
include $(PREBUILT_STATIC_LIBRARY)
LOCAL_STATIC_LIBRARIES := android_native_app_glue library
Here is my Question
I am little bit Confused when switching to Gradle experimental plugin for NDK. Share your ideas on how to link Static library in App build.gradle file.
I had followed the latest gradle experimental plug-in documentation given here.
Solution
Have a look at this sample.
Tell the compiler where the headers are (in
android.ndk{}
):CFlags += "-I${file("path/to/headers")}".toString() cppFlags += CFlags
Tell the linker where the .a file is (in android.ndk{} or where defining the flavors - make sure to add abiFilter - for example
abiFilters += "armeabi-v7"
)ldFlags += "-L${file(path/to/library.a)}".toString() ldLibs += ["nameOfLibrary"]
Note that the name of the library by convention is the string after "lib" in the .a file name. For example, for a file named libNative.a you should add ldLibs += ["native"] to gradle.
- Create a new module and use
apply plugin: 'java'
to apply java plugin. In the build.gradle write the necessary code to get and place the .a file in the appropriate directory (where you will get it from your module which is using it). Don't forget to add a dependency in the module using the library (compile project(':libraryModule')
independencies{}
) and to include it in the project in settings.gradle file withinclude ':libraryModule'
. If you want to place the module in a specified by you folder (for example where currently your Android.mk file is), just addproject(':libraryModule').projectDir = new File(settingsDir, 'path/to/module')
.
That should do it.
Answered By - Nedko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.