Search code examples
android-studiog++linker-errorsndk-buildgradle-experimental

gradle experimental library link order


I am trying to build an application using android gradle experimental plugin 0.7.0-alpha5.

I have an application "mainProject" that depends on a native library "nativeLibrary", which itself depends on several other library (either precompiled or not)

When I am building my nativeLibrary project, everything compiles and link well. The library are linked in the order I give in the

dependencies
{
     lib1
     lib2
     lib3
}

block.

When I try building my mainProject, The project fails to link, because the order in which the libraries are passed to the g++ compiler is wrong (in a random order), here is an extract of the options.txt of the main project:

-shared
-Wl,-soname,mainProject.so
-o
// bunch oh .o files

lib2 // random order
lib3
lib1

-Wl,--no-undefined
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
--sysroot=somePath
-Wl,--build-id
-LPathToC++Compiler
-lc++_static
-no-canonical-prefixes
-L/somePth
-latomic
-llog
-landroid
-lEGL
-lGLESv2
-lz

In order to have it link, I must add manually the tag

-Wl,--start-group
lib2
lib3
lib1
-Wl,--end-group

Is there an automated way using gradle experimental plugin to specify the order in which the libraries are linked? Or do I have to create a task to edit the options.txt file before trying to link?

Thanks!!

EDIT:

I found some usefull stuff on the gradle forums, however it doesn't seems to work with gradle-experimental:

https://discuss.gradle.org/t/c-cross-compiling-with-mingw-w64-is-there-a-way-to-modify-linker-flags/7390/5


Solution

  • So it turned out it is a bug in the current gradle experimental version. I have filled a bug request, and will keep this thread updated as it is processed.

    see https://code.google.com/p/android/issues/detail?id=208198&thanks=208198&ts=1461675016