Disabling static library build in Gradle
NickName:normen Ask DateTime:2015-01-14T02:32:39

Disabling static library build in Gradle

I am using gradle to build a JNI library for our java project and it works fine, however I can't seem to figure out how to keep gradle from building both shared and static versions of the file. I'd like to disable the build of the static library to speed up the build process. Adding the "shared" tag doesn't seem to do the trick.

From the gradle build file:

libraries {
  bulletjme {
      shared
  }
}

The gradle manual states that "For example, when you define a library called helloworld and build on Linux, Gradle will, by default, produce libhelloworld.so and libhelloworld.a binaries." However it doesn't say how to disable the build of either of the binaries.

Thanks for any answers!

Copyright Notice:Content Author:「normen」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/27929052/disabling-static-library-build-in-gradle

Answers
raspy 2016-03-03T12:50:34

In Gradle 2.11 this can be set up by setting buildable property to false. Although the documentation says it's read-only, it actually works.\n\nmodel {\n components {\n library(NativeLibrarySpec) {\n binaries.withType(StaticLibraryBinarySpec) {\n buildable = false\n }\n }\n }\n}\n\n\nWhen checking components output, Gradle will now say that a library is disabled by user:\n\n$ gradle components\n...\nBinaries\nShared library 'library:sharedLibrary'\n build using task: :librarySharedLibrary\n build type: build type 'debug'\n flavor: flavor 'default'\n target platform: platform 'linux_x86-64'\n tool chain: Tool chain 'gcc' (GNU GCC)\n shared library file: build/libs/library/shared/liblibrary.so\nStatic library 'library:staticLibrary' (not buildable)\n build using task: :libraryStaticLibrary\n build type: build type 'debug'\n flavor: flavor 'default'\n target platform: platform 'linux_x86-64'\n tool chain: Tool chain 'gcc' (GNU GCC)\n static library file: build/libs/library/static/liblibrary.a\n Disabled by user\n\n\nThis can also be handled globally for all libraries at once:\n\nmodel {\n components {\n libraryA(NativeLibrarySpec)\n libraryB(NativeLibrarySpec)\n all {\n binaries.withType(StaticLibraryBinarySpec) {\n buildable = false\n }\n }\n }\n}\n",


More about “Disabling static library build in Gradle” related questions

Disabling static library build in Gradle

I am using gradle to build a JNI library for our java project and it works fine, however I can't seem to figure out how to keep gradle from building both shared and static versions of the file. I'd...

Show Detail

Build static library only using Gradle

I am building a C project using Gradle, which includes sqlite3 as a native dependency. I would like to build only the static library as I do not need the shared library(.so). In the Gradle document...

Show Detail

Android Gradle Adding static library

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 $(

Show Detail

Use static C library with gradle

Im trying to create static library and use it in another project using gradle. My gradle.build in library project: apply plugin: 'c' model { components { dmggameserver(NativeLibrarySpec...

Show Detail

gradle: How to package a static library (.a) into aar

I am build a module with gradle, and need to package some static libraries into aar file, but I find gradle only package dynamic libraries. How to package a static library (.a) into aar?

Show Detail

How to Build Library Jar with Gradle

I followed this gradle tutorial: https://guides.gradle.org/building-java-libraries/ with gradle 4.9 and for some reason in projects that reference the build jar can't see the Library class that s...

Show Detail

How can I link a NativeLibrarySpec library specified in a different build.gradle file to my main build.gradle file?

Previously I had everything in my main build.gradle file. I would like to break it up and have each component have its own build.gradle file, then include those libraries from the sub-components to...

Show Detail

Build variants in Gradle for a Library Project in Android

I am trying to configure with Gradle a project which contains some external libraries. With Gradle I can setup different Environmental Configuration (with a class inside a config file) for the main

Show Detail

Adding Gradle build Folder in library

I am trying to import a project as a library in android studio. I configured the build.gradle and the setting folder but I kept getting an error message saying that the configuration with the name

Show Detail

How can I add a static library to Android NDK using the build.gradle file?

I'm trying to learn to use the NDK in AndroidStudio, and I'd like to import the "android_native_app_glue" file used in the "native-activity" sample, so that I have a framework for basic functions l...

Show Detail