Re: Building native libraries with native dependencies for multiple architectures

788 views
Skip to first unread message
Message has been deleted

Mikael Nousiainen

unread,
May 30, 2013, 2:33:43 AM5/30/13
to maven-androi...@googlegroups.com
Bump. This is really blocking development for me.

Could someone even point me to a right direction with this -- how to create a native library that depends on another native library and build both for multiple architectures?

On Thursday, May 23, 2013 7:37:23 PM UTC+3, Mikael Nousiainen wrote:
I have succeeded in building a single native shared (.so) library for multiple architectures by just specifying the architectures in Application.mk using APP_ABI := armeabi armeabi-v7a x86

However, I have a situation where I have another native library depending on the first one and *both* need to be compiled for multiple architectures.

My example uses libogg and libvorbis, where libvorbis depends on libogg.

I need to build:
1. libogg for armeabi, armeabi-v7a and x86
2. libvorbis for armeabi, armeabi-v7a and x86, so that each built architecture depends on the libogg artifact of the corresponding architecture

If I specify only one dependency on libogg for libvorbis, build fails on x86, as it tries to link x86 code with arm code:

    <dependency>
      <groupId>native.lib</groupId>
      <artifactId>ogg</artifactId>
      <version>${project.version}</version>
      <classifier>armeabi</classifier>
      <type>so</type>
    </dependency>

The failure happens here:

[DEBUG] /home/mikael/software/android/android-ndk/toolchains/x86-4.6/prebuilt/linux-x86_64/bin/i686-linux-android-g++ -Wl,-soname,libvorbis.so -shared --sysroot=/home/mikael/software/android/android-ndk/platforms/android-9/arch-x86 ./obj/local/x86/objs/vorbis/mdct.o ./obj/local/x86/objs/vorbis/smallft.o ./obj/local/x86/objs/vorbis/block.o ./obj/local/x86/objs/vorbis/envelope.o ./obj/local/x86/objs/vorbis/window.o ./obj/local/x86/objs/vorbis/lsp.o ./obj/local/x86/objs/vorbis/lpc.o ./obj/local/x86/objs/vorbis/analysis.o ./obj/local/x86/objs/vorbis/synthesis.o ./obj/local/x86/objs/vorbis/psy.o ./obj/local/x86/objs/vorbis/info.o ./obj/local/x86/objs/vorbis/floor1.o ./obj/local/x86/objs/vorbis/floor0.o ./obj/local/x86/objs/vorbis/res0.o ./obj/local/x86/objs/vorbis/mapping0.o ./obj/local/x86/objs/vorbis/registry.o ./obj/local/x86/objs/vorbis/codebook.o ./obj/local/x86/objs/vorbis/sharedbook.o ./obj/local/x86/objs/vorbis/lookup.o ./obj/local/x86/objs/vorbis/bitrate.o ./obj/local/x86/objs/vorbis/vorbisfile.o ./obj/local/x86/objs/vorbis/vorbisenc.o -lgcc ./obj/local/x86/ogg-1.0-SNAPSHOT-armeabi.so -no-canonical-prefixes  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now   -lc -lm -o ./obj/local/x86/libvorbis.so

[INFO] /home/mikael/software/android/android-ndk/toolchains/x86-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.6/../../../../i686-linux-android/bin/ld: error: ./obj/local/x86/ogg-1.0-SNAPSHOT-armeabi.so: incompatible target

[INFO] /home/mikael/software/android/android-ndk/toolchains/x86-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.6/../../../../i686-linux-android/bin/ld: ./obj/local/x86/objs/vorbis/block.o: in function vorbis_block_init:jni/libvorbis/block.c:106: error: undefined reference to 'oggpack_writeinit'

If I specify multiple dependencies using different classifiers, build fails in the very beginning stating that libogg has already been included in the build:

    <dependency>
      <groupId>native.lib</groupId>
      <artifactId>ogg</artifactId>
      <version>${project.version}</version>
      <classifier>armeabi</classifier>
      <type>so</type>
    </dependency>

    <dependency>
      <groupId>native.lib</groupId>
      <artifactId>ogg</artifactId>
      <version>${project.version}</version>
      <classifier>armeabi-v7a</classifier>
      <type>so</type>
    </dependency>

    <dependency>
      <groupId>native.lib</groupId>
      <artifactId>ogg</artifactId>
      <version>${project.version}</version>
      <classifier>x86</classifier>
      <type>so</type>
    </dependency>

And the corresponding error messages are:

[DEBUG] findNativeLibraryDependencies found 3: [native.lib:ogg:so:armeabi:1.0-SNAPSHOT:compile, native.lib:ogg:so:armeabi-v7a:1.0-SNAPSHOT:compile, native.lib:ogg:so:x86:1.0-SNAPSHOT:compile]
[DEBUG] resolveArtifacts found 3: [native.lib:ogg:so:armeabi:1.0-SNAPSHOT:compile, native.lib:ogg:so:armeabi-v7a:1.0-SNAPSHOT:compile, native.lib:ogg:so:x86:1.0-SNAPSHOT:compile]
[DEBUG] Listing LOCAL_EXPORT_C_INCLUDES for native.lib:ogg:so:armeabi:1.0-SNAPSHOT: [/tmp/android_maven_plugin_native_includes1369326778780_ogg/ogg/ogg.h, /tmp/android_maven_plugin_native_includes1369326778780_ogg/ogg/config_types.h, /tmp/android_maven_plugin_native_includes1369326778780_ogg/ogg/os_types.h]
[DEBUG] Listing LOCAL_EXPORT_C_INCLUDES for native.lib:ogg:so:armeabi-v7a:1.0-SNAPSHOT: [/tmp/android_maven_plugin_native_includes1369326778794_ogg/ogg/ogg.h, /tmp/android_maven_plugin_native_includes1369326778794_ogg/ogg/config_types.h, /tmp/android_maven_plugin_native_includes1369326778794_ogg/ogg/os_types.h]
[DEBUG] Listing LOCAL_EXPORT_C_INCLUDES for native.lib:ogg:so:x86:1.0-SNAPSHOT: [/tmp/android_maven_plugin_native_includes1369326778797_ogg/ogg/ogg.h, /tmp/android_maven_plugin_native_includes1369326778797_ogg/ogg/config_types.h, /tmp/android_maven_plugin_native_includes1369326778797_ogg/ogg/os_types.h]
[DEBUG] Set ANDROID_MAVEN_PLUGIN_LOCAL_SHARED_LIBRARIES = ogg ogg ogg
[INFO] /home/mikael/software/android/android-ndk/ndk-build [-C, /home/mikael/.../libvorbis, V=1, vorbis]
[DEBUG] [INFO] /home/mikael/software/android/android-ndk/build/core/build-module.mk:34: *** Android NDK: Aborting.    .  Stop.
Android NDK: Trying to define local module 'ogg' in jni/libvorbis/Android.mk.   
[DEBUG] Android NDK: But this module was already defined by jni/libvorbis/Android.mk.   

Is it even possible to do what I'm trying to achieve?

I'm using android-maven-plugin 3.6.0 and Android SDK version 22 on Linux.

Johan Lindquist

unread,
May 30, 2013, 9:15:31 AM5/30/13
to maven-androi...@googlegroups.com
Hi Mikael,

Unfortunately, multiple architectures are currently not supported by
the plugin - there has been an ongoing discussion on how to fix this but
little or no progress so far, mainly due to lack of time for all
involved so far.

Johan
>> ./obj/local/x86/ogg-1.0-SNAPSHOT-armeabi.so [2] -no-canonical-prefixes
>> -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -lc -lm
>> -o ./obj/local/x86/libvorbis.so
>>
>> [INFO]
>> /home/mikael/software/android/android-ndk/toolchains/x86-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.6/../../../../i686-linux-android/bin/ld:
>> error: ./obj/local/x86/ogg-1.0-SNAPSHOT-armeabi.so [1]: incompatible
>> [3]: *** Android NDK: Aborting. . Stop.
>> Android NDK: Trying to define local module 'ogg' in
>> jni/libvorbis/Android.mk.
>> [DEBUG] Android NDK: But this module was already defined by
>> jni/libvorbis/Android.mk.
>>
>> Is it even possible to do what I'm trying to achieve?
>>
>> I'm using android-maven-plugin 3.6.0 and Android SDK version 22 on
>> Linux.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Maven Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to
> maven-android-deve...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out
> [4].
>
>
>
> Links:
> ------
> [1] http://ogg-1.0-SNAPSHOT-armeabi.so
> [2] http://build-module.mk:34
> [3] https://groups.google.com/groups/opt_out

--
you too?

Manfred Moser

unread,
May 30, 2013, 9:28:04 AM5/30/13
to maven-androi...@googlegroups.com
Afaik the native folder in the examples project has that set up..

manfred
> --
> You received this message because you are subscribed to the Google Groups
> "Maven Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to maven-android-deve...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

Mikael Nousiainen

unread,
May 30, 2013, 9:31:06 AM5/30/13
to maven-androi...@googlegroups.com
Thanks, but I cannot agree completely with that comment, because building a single native library that does not have any native dependencies for multiple architectures sure works with the latest (3.6.0) plugin. Simply define APP_ABI in Application.mk.

My problem is related to the native dependencies of native libraries:
1. Build libogg for armeabi, armeabi-v7a and x86 -> WORKS
2. Build libvorbis (that depends on libogg) for armeabi, armeabi-v7a and x86 -> FAILS, because the separate builds (for each architecture) cannot find the corresponding compiled versions of libogg, as you can only define dependency for one architecture.

There have been a number of issues in GitHub addressing this:

Mikael Nousiainen

unread,
May 30, 2013, 9:35:12 AM5/30/13
to maven-androi...@googlegroups.com, man...@simpligility.com
Could you please share a direct link to the project? I have not found any examples of native library builds for multiple architectures -- especially ones that have other native dependencies.

Manfred Moser

unread,
May 30, 2013, 9:47:10 AM5/30/13
to maven-androi...@googlegroups.com
And all those pull requests are pulled in and part of 3.6.0...

> Thanks, but I cannot agree completely with that comment, because building
> a
> *single* native library *that does not have any native dependencies* for
> multiple architectures sure works with the latest (3.6.0) plugin. Simply
> define APP_ABI in Application.mk.
>
> My problem is related to the *native dependencies* of native libraries:
> --
> You received this message because you are subscribed to the Google Groups
> "Maven Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to maven-android-deve...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

Manfred Moser

unread,
May 30, 2013, 9:48:33 AM5/30/13
to Mikael Nousiainen, maven-androi...@googlegroups.com, man...@simpligility.com

Mikael Nousiainen

unread,
May 30, 2013, 3:12:46 PM5/30/13
to maven-androi...@googlegroups.com, Mikael Nousiainen, man...@simpligility.com
Thanks, but these samples don't seem to have any examples of multi-architecture builds or multi-architecture dependencies.

Manfred Moser

unread,
May 30, 2013, 3:18:25 PM5/30/13
to maven-androi...@googlegroups.com, Mikael Nousiainen, man...@simpligility.com
Seems like it is waiting for your contribution then..

Mikael Nousiainen

unread,
May 31, 2013, 3:00:56 AM5/31/13
to maven-androi...@googlegroups.com, Mikael Nousiainen, man...@simpligility.com
True. I think I could create a simple multi-arch build example for a single native library without native dependencies and publish them as a pull request.

The point of this thread and my question was different, though: I'm asking (possibly from the developers of the plugin) whether native multi-architecture builds containing transitive native dependencies are even supported yet - and if they are, how should I configure the dependencies and the plugin?

Mikael Nousiainen

unread,
May 31, 2013, 3:04:25 AM5/31/13
to maven-androi...@googlegroups.com, Mikael Nousiainen, man...@simpligility.com
And to clarify my problem further:
(1) Multi-architecture build for a native library works
(2) I do not know how to properly configure native dependencies for the multi-architecture build in (1)

Manfred Moser

unread,
May 31, 2013, 2:39:07 PM5/31/13
to Mikael Nousiainen, maven-androi...@googlegroups.com, Mikael Nousiainen, man...@simpligility.com
> And to clarify my problem further:
> (1) Multi-architecture build for a native library works

What are the file names in the local repository when you run

mvn install

on that project.

If you answer with a list I can give you the dependency snippets ..

Basically it will boil down to using the correct parameters for

groupId
artifactId
version
classifier
type (=packaging)

Hth

manfred

Mikael Nousiainen

unread,
May 31, 2013, 4:03:55 PM5/31/13
to maven-androi...@googlegroups.com, Mikael Nousiainen, man...@simpligility.com
Running mvn install on project (1), which is libogg, produces the following artifacts when APP_ABI = armeabi armeabi-v7a x86 mips:

[INFO] Installing /home/mikael/project/.../libogg/pom.xml to /home/mikael/.m2/repository/com/.../native/lib/ogg/1.0-SNAPSHOT/ogg-1.0-SNAPSHOT.pom
[INFO] Installing /home/mikael/project/.../libogg/target/ndk-libs/armeabi/libogg.so to /home/mikael/.m2/repository/com/.../native/lib/ogg/1.0-SNAPSHOT/ogg-1.0-SNAPSHOT-armeabi.so
[INFO] Installing /home/mikael/project/.../libogg/target/ogg-1.0-SNAPSHOT.har to /home/mikael/.m2/repository/com/.../native/lib/ogg/1.0-SNAPSHOT/ogg-1.0-SNAPSHOT-armeabi.har
[INFO] Installing /home/mikael/project/.../libogg/target/ndk-libs/armeabi-v7a/libogg.so to /home/mikael/.m2/repository/com/.../native/lib/ogg/1.0-SNAPSHOT/ogg-1.0-SNAPSHOT-armeabi-v7a.so
[INFO] Installing /home/mikael/project/.../libogg/target/ogg-1.0-SNAPSHOT.har to /home/mikael/.m2/repository/com/.../native/lib/ogg/1.0-SNAPSHOT/ogg-1.0-SNAPSHOT-armeabi-v7a.har
[INFO] Installing /home/mikael/project/.../libogg/target/ndk-libs/x86/libogg.so to /home/mikael/.m2/repository/com/.../native/lib/ogg/1.0-SNAPSHOT/ogg-1.0-SNAPSHOT-x86.so
[INFO] Installing /home/mikael/project/.../libogg/target/ogg-1.0-SNAPSHOT.har to /home/mikael/.m2/repository/com/.../native/lib/ogg/1.0-SNAPSHOT/ogg-1.0-SNAPSHOT-x86.har
[INFO] Installing /home/mikael/project/.../libogg/target/ndk-libs/mips/libogg.so to /home/mikael/.m2/repository/com/.../native/lib/ogg/1.0-SNAPSHOT/ogg-1.0-SNAPSHOT-mips.so
[INFO] Installing /home/mikael/project/.../libogg/target/ogg-1.0-SNAPSHOT.har to /home/mikael/.m2/repository/com/.../native/lib/ogg/1.0-SNAPSHOT/ogg-1.0-SNAPSHOT-mips.har

And to build project (2), which is libvorbis, I've tried to specify dependencies the ways (which both failed) I described in the first post of this thread.

I'm running Maven 3.0.4, android-maven-plugin 3.6.0 and Android SDK version 22 on Linux x86_64.

Mikael Nousiainen

unread,
Jun 4, 2013, 4:22:48 AM6/4/13
to maven-androi...@googlegroups.com, Mikael Nousiainen, man...@simpligility.com
Any ideas how to specify dependencies for these artifacts?

Mikael Nousiainen

unread,
Jun 25, 2013, 9:52:54 AM6/25/13
to maven-androi...@googlegroups.com, Mikael Nousiainen, man...@simpligility.com
Hello Manfred,

I'd be glad to receive any kind of input related to this problem. Do you have any clues how the build should be configured?

-Mikael
Reply all
Reply to author
Forward
0 new messages