Hi everyone!
I have a bit of a problem concerning my build.gradle using gradle 2.10 and
the gradle-experimental 0.7.0-alpha5 plugin in android studio.
This is my build.gradle file for my native dependency, which itself depends
on curl, ssl and crypto shared dependencies:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.model.native'
model {
repositories {
libs(PrebuiltLibraries) {
crypto {
headers.srcDir "../../../../external/crypto/include/"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile =
file("../../../../external/crypto/prebuilt/${targetPlatform.getName()}/libcrypto.a")
}
}
ssl {
headers.srcDir "../../../../external/ssl/include/"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile =
file("../../../../external/ssl/prebuilt/${targetPlatform.getName()}/libssl.a")
}
}
curl {
headers.srcDir "../../../../external/curl/include"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile =
file("../../../../external/curl/prebuilt/${targetPlatform.getName()}/libcurl.a")
}
}
}
}
android {
compileSdkVersion = 21
buildToolsVersion = "23.0.2"
defaultConfig.with {
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 9
}
}
android.ndk {
// Retrieve ndk dir
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir', null)
moduleName = "moduleName"
stl = "c++_static"
cppFlags.add("-std=c++11")
cppFlags.add("-pthread")
cppFlags.add("-fexceptions")
cppFlags.add("-frtti")
cppFlags.add("-DANDROID")
cppFlags.add("-DUSE_FILE32API")
ldLibs.addAll(["atomic", "log", "android", "EGL", "GLESv2", "z",
"OpenSLES"])
abiFilters.addAll(["armeabi-v7a", "x86"])
CFlags.add("-DUSE_FILE32API")
CFlags.add("-fexceptions")
}
android.sources {
jni {
source {
// some bunch of files
}
exportedHeaders {
// some headers
}
dependencies {
library "curl"
library "ssl"
library "crypto"
// it looks like the order matters, however when
linking to it in main project, it appears that the order is randomized
// the right order is curl > ssl > crypto
}
}
}
}
android.buildTypes {
release {
}
debug {
ndk.with {
debuggable = true
}
}
}
android.productFlavors {
create ("arm") {
ndk.with {
abiFilters.add("armeabi-v7a")
ldFlags.addAll([
"-L${file("./obj/local/armeabi-v7a")}".toString()
])
}
}
create("x86") {
ndk.with {
abiFilters.add("x86")
ldFlags.addAll([
"-L${file("./obj/local/x86")}".toString()
])
}
}
}
}
As you can see the library import order is correct in my build.gradle file.
and then my build.gradle for my application:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "com.company.myapp"
minSdkVersion.apiLevel = 21
targetSdkVersion.apiLevel = 21
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.pro'))
}
debug {
ndk.with {
debuggable = true
}
}
}
android.productFlavors {
create ("arm") {
ndk.with {
abiFilters.add("armeabi-v7a")
ldFlags.addAll([
"-L${file("./obj/local/armeabi-v7a")}".toString()
])
}
}
create("x86") {
ndk.with {
abiFilters.add("x86")
ldFlags.addAll([
"-L${file("./obj/local/x86")}".toString()
])
}
}
}
android.ndk {
moduleName = "mainModule"
stl = "c++_static"
cppFlags.add("-std=c++11")
cppFlags.add("-fexceptions")
cppFlags.add("-fpermissive")
cppFlags.add("-pthread")
cppFlags.add("-frtti")
cppFlags.add("-DANDROID")
ldLibs.addAll(["atomic", "log", "android", "EGL", "GLESv2", "z"])
abiFilters.addAll(["armeabi-v7a", "x86"])
}
android.sources {
main {
jni {
source {
//bunch of file
}
exportedHeaders {
// bunch of headers
}
dependencies {
project ":libmoduleName" linkage "static"
}
}
}
}
}
My problem is that while the dependencies are linked in the correct order
in the native dependency, their include order gets randomized in my main
build, which leads to undefined symbols during linkage.
Here are the relevant parts of the main options.txt file:
-shared
-Wl,-soname,libmainModule.so
-o
// bunch of .o file
/XXX/ssl/prebuilt/armeabi-v7a/libssl.a
/XXX/crypto/prebuilt/armeabi-v7a/libcrypto.a
/XXX/curl/prebuilt/armeabi-v7a/libcurl.a
-Wl,--no-undefined
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
--sysroot=/XXX/android-21/arch-arm
-Wl,--build-id
-L/Users/XXX/libs/armeabi-v7a
-lc++_static
-no-canonical-prefixes
-L/XXX/local/armeabi-v7a
-latomic
-llog
-landroid
-lEGL
-lGLESv2
-lz
As you can see the order got messed up, it should have been:
/XXX/curl/prebuilt/armeabi-v7a/libcurl.a
/XXX/ssl/prebuilt/armeabi-v7a/libssl.a
/XXX/crypto/prebuilt/armeabi-v7a/libcrypto.a
If someone has a way around it I would gladly appreciate, as I am a bit
stuck right now.
Thanks!
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.