External libraries with Necessitas 0.3 -- still requires some hacking, or am I missing something?

2,365 views
Skip to first unread message

Tom Russo

unread,
Oct 31, 2011, 2:43:43 AM10/31/11
to android-qt
I have just spent time tonight trying to get working a basic application that accesses a non-Qt external share library.  It took some doing, because it appears that Qt Creator is trying hard to do something that is incompatible with this task, and I'm not sure why or how to stop it.

Here's what I tried:

 - In my application's .pro file (within Qt Creator) I added "-L/path/to/my/libs -lmylib" to the LIBS variable
 - Added "/path/to/my/includes" to INCLUDEPATH in the .pro file.
 - Built mylib using a standalone toolchain, carefully modifying the final command to build the shared library to add "-Wl,-soname,libmylib.so" so that a non-versioned .so file is made rather than libmylib.so->libmylib.so.0->libmylib.so.0.6.6 symbolic link set with SONAME of "libmylib.so.0".
 - copied the libmylib.so file to MyProject/android/libs/armeabi
 - Built my project in Qt creator.  Build is successful.

 - try to run the application.   Observed that the libmylib.so is copied from libs/armeabi into the .apk file, confirmed by copying the .apk file
   to MyApplication.zip and doing an "unzip -l"

Then it went wrong:
  -  Result is an application failure on the android device, and an error message that it can't load "libmylib.so".  I looked on the device, and sure enough, the libmylib.so file WAS there in the application's directory along with the .so for the application itself.

I did look on the Projects View/Run Settings page under Package Configuration, where there is a box for "prebundled libraries" but there is, as far as I can tell, no way to add one.  The box is completely unresponsive to clicks, there is no "add" button, and it seems to do nothing.

Looking through some issue tickets (http://sourceforge.net/p/necessitas/tickets/57/ and http://sourceforge.net/p/necessitas/tickets/73/, both of which imply that the issue has been fixed in Alpha 3) it appears that the libs.xml file in the res/values directory needs to have the bundled library listed, so I edited that file and changed:

   <array name="bundled_libs"/>

to

  <array name="bundled_libs">
      <item>mylib</item>
  </array>

and rebuilt the project, and reran it.  I got a dialog box that libs.xml had been modified from outside Creator, and sure enough it had... my edits had been overwritten and the blank array was back.

I did, in the end, finally get my project to run on my android device --- by abandoning Qt Creator at this point.  I built my code in Qt creator, but then did not try to run it from there.  I re-edited libs.xml, did a cd to my project's android directory and issued "ant clean debug" there.  I then manually issued the adb uninstall and adb install commands that Qt Creator had run.  Nothing in these steps overwrote libs.xml, and my application deployed and ran perfectly.  At least I have a path forward now, but it removes my ability to debug in Qt Creator.

So, what is the RIGHT way to get prebundled libraries to work properly using the Qt Creator workflow?  What is the "prebundled libraries" box in the Projects/Run Settings/Package Configuration/Libraries pane supposed to do, and how to I add one (or more)?  I like Qt Creator, but at this point I can't use it for anything more than to set up the initial project and to give me command line hints how to deploy my project for testing.  I can't debug in it, because it'll clobber libs.xml every time I try to run.  What's the secret?  Or is the use of external, non-Qt libraries still a work in progress?
--
Tom Russo    KM5VY   SAR502   DM64ux          http://www.swcp.com/~russo/
Tijeras, NM  QRPL#1592 K2#398  SOC#236 http://kevan.org/brain.cgi?DDTNM
 "One man alone can be pretty dumb sometimes, but for real bona fide
 stupidity, there ain't nothin' can beat teamwork." - Edward Abbey



BogDan Vatra

unread,
Oct 31, 2011, 4:03:44 AM10/31/11
to andro...@googlegroups.com
Hi Tom,

Hmm it should work ... please run the following command:
$ adb shell ls /data/data/<your_application_package_name>/libs
You should see that library there, if not, then the library is not
copied where it should.
Please add the following script to your .pro file to install external libs:

external_libs.files=/path/to/your/lib
x86 {
external_libs.path = /libs/x86
} else: armeabi-v7a {
external_libs.path = /libs/armeabi-v7a
} else {
external_libs.path = /libs/armeabi
}

INSTALLS += external_libs

The "prebundled libraries" box is used to configure libraries which
are compiled and managed by QtCreator (the library must be compiled by
your project or any project which your project depends on).


Cheers,
BogDan.

2011/10/31 Tom Russo <tom....@gmail.com>:

Tom Russo

unread,
Oct 31, 2011, 10:21:20 AM10/31/11
to andro...@googlegroups.com
On Mon, Oct 31, 2011 at 02:03, BogDan Vatra <taipan...@gmail.com> wrote:
Hi Tom,

Hmm it should work ... please run the following command:
$ adb shell ls /data/data/<your_application_package_name>/libs
You should see that library there, if not, then the library is not
copied where it should.

BogDan:

Yes, the library *IS* copied over into the application directory.  I confirmed that last night during all the failed runs --- they are right there in /data/data/my.application.name/libs and definitely in the .apk file,  but apparently it is still not found at run time unless it is listed in the libs.xml file when the package is built. 
 
Please add the following script to your .pro file to install external libs:

external_libs.files=/path/to/your/lib
x86 {
     external_libs.path = /libs/x86
} else: armeabi-v7a {
     external_libs.path = /libs/armeabi-v7a
} else {
     external_libs.path = /libs/armeabi
}

INSTALLS += external_libs

Hmm.  I'll try that, but as I said, the external library *is* bundled in the .apk file and is installed into the /data/data/.../libs directory, but the application seems unable to find it unless I manually edit libs.xml and add the library to the "bundles_libs" array and build the package with ant manually instead of through Qt Creator.

I'll try to make up a simple test case tonight and post it to a ticket to demonstrate the issue most clearly.

The "prebundled libraries" box is used to configure libraries which
are compiled and managed by QtCreator (the library must be compiled by
your project or any project which your project depends on).


Ok.  It's a pity we can't force non-qt libraries and those not managed by Creator into that. 
 

BogDan Vatra

unread,
Oct 31, 2011, 3:54:29 PM10/31/11
to andro...@googlegroups.com
I'll try to find a better solution, please reopen one issue.

Cheers,
BogDan.

2011/10/31 Tom Russo <tom....@gmail.com>:
>
>

Tom Russo

unread,
Nov 1, 2011, 1:57:13 PM11/1/11
to andro...@googlegroups.com
On Mon, Oct 31, 2011 at 13:54, BogDan Vatra <taipan...@gmail.com> wrote:
I'll try to find a better solution, please reopen one issue.

Cheers,
BogDan.

BogDan:

I have created a highly detailed ticket on this issue:

https://sourceforge.net/p/necessitas/tickets/106/

It contains a test case (Qt project and simple external library) as an attachment, and has all the steps needed to reproduce both the problem and the manual work-around (outside of Creator) spelled out in the ticket.

I also made a suggestion for how this might best be handled within Qt Creator's Run Settings dialog, but without really digging into what Qt Creator is doing it may not be the right way to handle it.

Hope that helps.
 

BogDan

unread,
Nov 1, 2011, 2:40:39 PM11/1/11
to android-qt
Thanks !

BogDan.

On Nov 1, 7:57 pm, Tom Russo <tom.km...@gmail.com> wrote:
> On Mon, Oct 31, 2011 at 13:54, BogDan Vatra <taipanroma...@gmail.com> wrote:
> > I'll try to find a better solution, please reopen one issue.
>
> > Cheers,
> > BogDan.
>
> BogDan:
>
> I have created a highly detailed ticket on this issue:
>
> https://sourceforge.net/p/necessitas/tickets/106/
>
> It contains a test case (Qt project and simple external library) as an
> attachment, and has all the steps needed to reproduce both the problem and
> the manual work-around (outside of Creator) spelled out in the ticket.
>
> I also made a suggestion for how this might best be handled within Qt
> Creator's Run Settings dialog, but without really digging into what Qt
> Creator is doing it may not be the right way to handle it.
>
> Hope that helps.
>
>
>
>
>
>
>
>
>
> > 2011/10/31 Tom Russo <tom.km...@gmail.com>:
>
> > > On Mon, Oct 31, 2011 at 02:03, BogDan Vatra <taipanroma...@gmail.com>
> > >> 2011/10/31 Tom Russo <tom.km...@gmail.com>:
> Tijeras, NM  QRPL#1592 K2#398  SOC#236http://kevan.org/brain.cgi?DDTNM

Tom Russo

unread,
Nov 1, 2011, 3:28:41 PM11/1/11
to andro...@googlegroups.com


On Tue, Nov 1, 2011 at 12:40, BogDan <taipan...@gmail.com> wrote:
Thanks !

I just noticed some mistakes in the text of my bug report.  They are somewhat embarrassing because I was trying to make the report very clear on what steps to take to get the thing running.  Everywhere in the text of the report, wherever I refer to "simple" (as in libsimple.so or <item>simple</item>) it is a mistake, and one should use "sample" (as in libsample.so or <item>sample</item>) instead.  I submitted a correction in a follow-up on the bug, but those supplemental comments are "awaiting moderation."
 
Tijeras, NM  QRPL#1592 K2#398  SOC#236 http://kevan.org/brain.cgi?DDTNM

Pavel Chivixin

unread,
Nov 9, 2011, 9:46:05 AM11/9/11
to android-qt
I'm new in Qt and Adroid developement, but got the same problem with
external libraries.
Additional things, I noticed : if my own libraries are controlled by
Qt creator and I can edit bundled libraries list throught project
settings in Run-Package configuration. External libraries will be
automatically added in libs.xml list in form below:

<array name="bundled_libs">
<item>libMy_lib1.so</item>
<item>libMy_lib2.so</item>
<item>libMy_lib3.so</item>
</array>

As I experimented, they won't be recognized, because lib* prefix and
*.so extension are unnecessary. In additions file libs.xml will be
overwritten at deployment by Qt Creator even in this case.
Solution sugested by Tom Russo is working, thanks. But main problem
after this is application debugging. Is there any way to attach
application running on device or emulator?
I tried this link:
http://developer.android.com/guide/developing/debugging/debugging-projects-cmdline.html
With DDMS Android skd tool I can see my application process available
to atatch, but can't do it from Necessitas Qt Creator (Debug -> Start
Debugging -> Start and Attach to Remote Application, host-port:
localhost:8700). Are there some instructions, or attaching to running
android application in principle is impossible at the moment?

Thanks for any advices,
Pavel Chivixin

Vadim Fedotov

unread,
Jan 16, 2012, 3:08:44 AM1/16/12
to andro...@googlegroups.com
Thanks for this info!
It was a big relief to know that it is a bug in necessitas.
Bye the way, I play with it a little and found a simple workaround for this issue.
 
1. Edit the "libs.xml" file (android/res/values/libs.xml) in following way:
   - make copy of "<array name="bundled_libs"/>"
   - change name, for example use "bundled_libs_fixed"
   - add item for each library ("<item>simple</item>")
   - close XML tag
 
libs.xml should be look like:
-----------------------------------------------------------
<?xml version='1.0' encoding='utf-8'?>
<resources>
    <array name="bundled_libs_fixed">
        <item>shared1</item>
        <item>shared2</item>
    </array>
    <array name="qt_libs">
        <item>QtCore</item>
        <item>QtGui</item>
        <item>QtWebKit</item>
        <item>QtXmlPatterns</item>
    </array>
    <array name="bundled_libs"/>
</resources>
-----------------------------------------------------------
 
2. Edit file "AndroidManifest.xml" (android/AndroidManifest.xml) in following way:
   - found string  "bundled_libs", something like:
          <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
   - change android:resource array name from "bundled_libs"
          <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
      to "bundled_libs_fixed", it will look like
          <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs_fixed"/>
 
Thats's all. This values doesn't overwrites automatically so we could use this patch until it will be fixed.
Hope beta 1 of necessitas will be available soon.
 
With Best Regards,
Vadim

Juba

unread,
Feb 28, 2012, 6:40:33 AM2/28/12
to andro...@googlegroups.com
Hi all,
    I'am trying the Vadim fix, but doesn't work for me.
The external lib that don't link is the same that the project name (I think that this don't care).

I am trying to run an app on a real device connected via adb TCP, when I start the application from QtCreator the application start correctly, but when I try to launch from the device I get the linker error.

Is this fix working only for QtCreator Run?
Thanks in advance,
Stefano.

Vadim Fedotov

unread,
Feb 28, 2012, 6:54:38 AM2/28/12
to andro...@googlegroups.com

Hi, Stefano.

Fix that I was talking about previously works fine for real devices. I'm succesfully executed application on Samsung Galaxy with 8 or something like that external libraries.
Probably there is a misunderstanding here because lib with the name of the executed project is the application main library (I don't remember correct constant name from AndroidManifest.xml) and main library it is not required to be present in external libraries list. So your problem is probably of compleatly different nature then that of external libraries dependencies problem,

With Best Regards,
Vadim

Arun pk

unread,
Oct 3, 2012, 3:04:57 AM10/3/12
to andro...@googlegroups.com
Hi...
      I have done those steps to add my shared library to my Project... And its recognizing the .so file correctly... But its showing errors....as,
arm-linux-androideabi/bin/ld.exe:../AndroTest1/libIVIWidgets.so: file format not recognized; treating as linker script
arm-linux-androideabi/bin/ld.exe:../AndroTest1/libIVIWidgets.so:1: syntax error

I am not sure whats going wrong.... Can any one give me a suggestion how to overcome this error......

I have created my shared library in normal Qt Creator & not using Necesitas Qt Creator... is that the problem??? 

Mandeep Sandhu

unread,
Oct 3, 2012, 3:52:36 AM10/3/12
to andro...@googlegroups.com
On Wed, Oct 3, 2012 at 12:34 PM, Arun pk <arunp...@gmail.com> wrote:
> Hi...
> I have done those steps to add my shared library to my Project... And
> its recognizing the .so file correctly... But its showing errors....as,
> arm-linux-androideabi/bin/ld.exe:../AndroTest1/libIVIWidgets.so: file format
> not recognized; treating as linker script
> arm-linux-androideabi/bin/ld.exe:../AndroTest1/libIVIWidgets.so:1: syntax
> error
>
> I am not sure whats going wrong.... Can any one give me a suggestion how to
> overcome this error......

That seems to be the issue. If you used stock Qt creator, did you
setup the toolchain there to build ARM binaries? The necessitas Qt
creator comes with the toolchai9ns installed so you don't have to
install them manually.

I think because of this your default compiler would've generated intel
x86 binaries which you're trying to run on an ARM platform.

Try using the necessitas Qt creator. It should solve your problem.

HTH,
-mandeep

Arun pk

unread,
Oct 3, 2012, 5:18:33 AM10/3/12
to andro...@googlegroups.com
Thanks Mandeep for the reply....

    I have tried to create the shared library in Necessitas Qt Creator.... But it gives meerror...
arm-linux-androideabi/bin/ld.exe: cannot find -lQtDeclarative

I am sure that its added this in the package configuration...... and its there in libs.xml....

Mandeep Sandhu

unread,
Oct 3, 2012, 5:58:33 AM10/3/12
to andro...@googlegroups.com
> I have tried to create the shared library in Necessitas Qt Creator....
> But it gives meerror...
> arm-linux-androideabi/bin/ld.exe: cannot find -lQtDeclarative

Looks like the linker cannot find libQtDeclarative.so. Is the path to
the lib there in the -L option given while compiling?

>
> I am sure that its added this in the package configuration...... and its
> there in libs.xml....

This has nothing to do with your runtime configuration (i.e the env in
which the app will be running). Looks like an issue with your build
setup.

-mandeep

Arun pk

unread,
Oct 30, 2012, 5:42:08 AM10/30/12
to andro...@googlegroups.com
I have tried so many times creating new workspace for my project.. still its showing the same thing "-lQtDeclarative not found"..... My other projects which are created by using Ncessitas Creator are working fine... Is there anything else which i miss to add... any suggestion regarding this.....

Arun pk

unread,
Oct 30, 2012, 6:46:20 AM10/30/12
to andro...@googlegroups.com
How did u cretae theShared Library by using Necessitas Qt Creator.. When i am trying to use this to generate Shared Library its showing error... ld.exe: cannot find -lQtDeclarative".... i have tried so many times to generate the library but no success.. i dont know weather i miss something or not... please help me regarding this...

Sten .

unread,
Oct 30, 2012, 6:49:21 AM10/30/12
to andro...@googlegroups.com
Don't know about QtDeclarative - it was not used in our project. So may be your version of Qt just miss it - have you check that?
2012/10/30 Arun pk <arunp...@gmail.com>

Arun pk

unread,
Oct 30, 2012, 6:54:49 AM10/30/12
to andro...@googlegroups.com
How can i check that.... But by using this Qt Creator i was able to create other applications..... Most of the QML app will be using Qt Declarative modules...

Sten .

unread,
Oct 30, 2012, 7:00:24 AM10/30/12
to andro...@googlegroups.com
To check that is simple - just locate the QtDeclarative.so file in Qt.
I know about QML using declarative.
But sorry I could not realy help you because I don't know recent necessitas status. Most likely you have some problems with linkage.
By the way - from my point of view there is not much profit in dealing with necessitas numerous bugs when we can see Qt5 shining in the future. :)

Arun pk

unread,
Oct 30, 2012, 7:14:41 AM10/30/12
to andro...@googlegroups.com
But when i am compiling the code in "@libIVIWidgets.so.1.0.0.lnk.cmdline"  file its showing path to QtDeclarative module as 
"-LC:\Users\arunkun\necessitas\Android\Qt\480\armeabi\lib -lQtDeclarative".... one more thing i noticed i sthat other than this path everywhere they are using forward slash to specify the path.... I doubt whether this causes the problem or not... libQtDeclarative.SO is present in that path...that i made sure.... currently i am using version 0.3 only, till now i didnt use version 4.... 

Arun pk

unread,
Oct 30, 2012, 7:47:18 AM10/30/12
to andro...@googlegroups.com
This is what i am getting when compiling my code....

-LC:/Users/emb-arunkun/necessitas/android-ndk-r6b/sources/cxx-stl/gnu-libstdc++/libs/armeabi -LC:/Users/emb-arunkun/necessitas/android-ndk-r6b/platforms/android-5/arch-arm//usr/lib -LC:\Users\emb-arunkun\necessitas\Android\Qt\480\armeabi\lib -lQtDeclarative -L/tmp/necessitas/unstable/Android/Qt/480/build-armeabi/install/lib -L/tmp/necessitas/android-ndk-r6b/sources/cxx-stl/gnu-libstdc++/libs/armeabi -L/tmp/necessitas/android-ndk-r6b/platforms/android-5/arch-arm//usr/lib -lQtSvg -lQtSql -lQtXmlPatterns -lQtNetwork -lQtScript -lQtGui -lQtCore -lstdc++ -lsupc++ -llog -lz -lm -ldl -lc -lgcc > libtestAppx.so.1.0.0.lnk.cmdline

C:/Users/emb-arunkun/necessitas/android-ndk-r6b/toolchains/arm-linux-androideabi-4.6.2/prebuilt/windows/bin/arm-linux-androideabi-g++ @libtestAppx.so.1.0.0.lnk.cmdline

ma-make: Leaving directory `C:/Users/emb-arunkun/AndroidApp/testAppx-build--Necessitas_Qt_4_8_0_for_Android_armv5_Release'

c:/users/emb-arunkun/necessitas/android-ndk-r6b/toolchains/arm-linux-androideabi-4.6.2/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6.2/../../../../arm-linux-androideabi/bin/ld.exe: cannot find -lQtDeclarative

collect2: ld returned 1 exit status

ma-make: *** [libtestAppx.so.1.0.0] Error 1

Ray Donnelly

unread,
Oct 30, 2012, 8:40:36 AM10/30/12
to andro...@googlegroups.com
Hi Arun,

The slash direction is indeed an issue. the @file syntax requires
posix style slashes and cannot work with Windows ones. How did you add
the QtDeclarative library to QtCreator? Are you using the latest
version of Necessitas Qt Creator?
Message has been deleted

Arun pk

unread,
Oct 30, 2012, 10:53:49 PM10/30/12
to andro...@googlegroups.com
I have added it by selecting it in the Package Configurations in QtCreator Run Settings... 
Currently I am using Necessitas 0.3..... i didnt upgraded to version 4... 
if i am trying to do the same in Linux environment will it work fine???

Arun pk

unread,
Oct 31, 2012, 1:49:25 AM10/31/12
to andro...@googlegroups.com
Thanks for the replies.... Today i have downloaded Necesitas Alpha 4.... Now i am able to generate Libraries by using Qt Creator...
Now how can i use this library with my aplication... i have tried adding it in the libs.xml tried, but it does not getting added.. shows me error when i run my application in Emulator as well as on Device(Eror: invalid Qt Version").... Did anyone tried adding own library in an android app using Necessitas Qt creator...
Reply all
Reply to author
Forward
0 new messages