[Android 1.3] [Gradle 2.5] Build with native third party shared libraries

748 views
Skip to first unread message

Stéphane Saffré

unread,
Aug 7, 2015, 12:00:38 PM8/7/15
to adt-dev

Hello,

I am struggling to build a simple native library depending on another native third-party shared library (turbojpeg). This native library is basically a wrapper of turbojpeg library.

I have followed the documentation I have found here:

However I am unable to make Android Studio find the third-party library. Here is the project setup

Project build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.0'
}
}

allprojects {
repositories {
jcenter()
}
}


app module build.gradle:

apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "22.0.1"

defaultConfig.with {
applicationId = "com.stephane.turbojpegplugin"
minSdkVersion.apiLevel = 19
targetSdkVersion.apiLevel = 19
}
}
/*
* native build settings
*/
android.ndk {
moduleName = "TurboJpegPlugin"
stl = "stlport_static"
ldLibs = [ "turbojpeg" ]
/*
* Other ndk flags configurable here are
* cppFlags += "-fno-rtti"
* cppFlags += "-fno-exceptions"
* ldLibs = ["android", "log"]
* stl = "system"
*/
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" @
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm7") {
ndk.abiFilters += "armeabi-v7a"
}
}
}

Gradle builds sucessfully with these files however at project build here is the output:

Information:Gradle tasks [clean, :app:compileArm7DebugSources, :app:compileArm7DebugAndroidTestSources]
:app:clean
:app:copyArmeabi-v7aDebugTurboJpegPluginSharedLibraryGdbServer
:app:createArmeabi-v7aDebugTurboJpegPluginSharedLibraryGdbsetup
:app:compileArmeabi-v7aDebugTurboJpegPluginSharedLibraryTurboJpegPluginMainCpp
:app:linkArmeabi-v7aDebugTurboJpegPluginSharedLibrary
D:\Dev\android-ndk-r10e\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\arm-linux-androideabi\bin\ld.exe
Error:error: cannot find -lturbojpeg
D:\Dev\projects\android\TurboJpegPlugin\app\src\main\jni\TurboJpegPlugin.cpp
Error:(9) undefined reference to 'tjInitDecompress'
Error:(10) undefined reference to 'tjDecompressHeader2'
Error:(13) undefined reference to 'tjDecompress2'
Error:(14) undefined reference to 'tjDestroy'
Error:error: ld returned 1 exit status
Error:Execution failed for task ':app:linkArmeabi-v7aDebugTurboJpegPluginSharedLibrary'.
> A build operation failed.
     Linker failed while linking libTurboJpegPlugin.so.
 See the complete log at: file:///D:/Dev/projects/android/TurboJpegPlugin/app/build/tmp/linkArmeabi-v7aDebugTurboJpegPluginSharedLibrary/output.txt
Information:BUILD FAILED
Information:Total time: 0.763 secs
Information:7 errors
Information:0 warnings
Information:See complete output in console


The turbojpeg library is in the jniLibs folder like this:


Following older articles/documentation, the jniLibs folder is where the native shared libraries should be put to Android Studio automatically find them but it seems it not the case anymore. Did I miss something?

Any help would be greatly appreciated.

Thanks!

Stéphane Saffré

unread,
Aug 8, 2015, 6:01:29 AM8/8/15
to adt-dev
Eventually, I managed to link to the libraries giving explicitely the path the the third-party library this way:

android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" @
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm7") {
ndk.abiFilters += "armeabi-v7a"
        ndk.ldFlags += "-Lsrc/main/jniLibs/armeabi-v7a"
}
}

Is it the expected behaviour with the experimental 0.2.0 build plugin ?

Ignas Brašiškis

unread,
Aug 17, 2015, 11:51:30 AM8/17/15
to adt-dev
Same problem here, I am strugling to link third party so's.

In Gradle 2.4 normal way to build against native so's was simple:
In build sets add jniLibs in sourceset –
sourceSets {
        main {
            jniLibs.srcDirs = ['jniLibs']
        }
    } 
As I understand sourceSets here are replaced by android.sources directive. I tried this:
android.sources {
main {
java{
source{
srcDir 'src'
}
}
jniLibs{
source{
srcDir 'jniLibs'
}
}
}
}

Gradle runs well however it still does not link: in runtime I get link error. Any ideas how to solve it?

Xavier Ducrohet

unread,
Aug 17, 2015, 3:22:04 PM8/17/15
to adt...@googlegroups.com
This is not yet supported by the plugin.

--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Stéphane Saffré

unread,
Aug 18, 2015, 4:09:32 AM8/18/15
to adt...@googlegroups.com
Ok, thanks for the information.

--
Stéphane SAFFRÉ

--
You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/9bWWbfty3gA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages