Building a Standalone Static Library for Android with Gradle / Android Studio
I have migrated my NDK based app from ant command line to Android Studio.
Android Studio is layered on top of Gradle. Gradle calls CMake to generate C ++ code.
What I'm looking for is a way to create just a set of static .a files for android targets armv7, arm64, x86, etc.
Android Studio projects target complete applications.
Is there a way to make Gradle (or AStudio) only build static libs (.a) without building apps or shared library?
I am using all the latest Android stuff under Linux: Android Studio 3.0 canary4. NDK 15.0.4075724
source to share
You can create static library in Android Studio and Gradle in two ways:
- Adding to your Android.mk module
include $(BUILD_STATIC_LIBRARY)
using either ndk-build or gradle -experimental plugin. -
Adding to your CMakeLists.txt
add_library(mylib STATIC source_file1.cpp source_file2. ... )
using Android Studio 2.3+ and adding to build.gradle module
android{ defaultConfig{ externalNativeBuild{ cmake{ \\ add cmake parameters here if you have some } } } }
and then click Sync Gradle Files. But always remember that you cannot package (add) the built-in static library to your app.apk and hence you cannot load the cpp code from java code. You can only load shared libraries into your android app.
source to share