[SOLVED] Qt 5.2 beta 1 Android Qt Sensors
I created a simple Qt Quick 2 project with Qt Creator, added a ProximitySensor ... and it works very well.
So, I decided to use it into my real project, but in my real project the ProximitySensor does not work.
After some debugging, I noticed that in the test project during the launch of the application on the debug console Qt report something like that:
I/Qt (5345): Sensors Start
But in my real project, during the launch the Qt does not report the starting of Sensors.
So, I checked if there was some differences into .pro, in the AndroidManifest and in other files... but nothing.
Someone has a suggestion on where to look for solving this problem ??
Ok, I solved by myself.
The problem was that into "res/values/strings.xml" the Qt will put all the libraries to deploy and to load. But there is also the name of the app.
So, I provided my strings.xml with my app name and from that moment the only option is to manually edit the strings.xml and add the extra libraries and Qt module you need by hand.
i think your problem solved is similar to Qt Bluetooth. right?
difficult to me..Could you please describe more for me?..so your solution will be help to solve my problem. thank you!
Ok, I give your more details.
In my .pro there is the following statement:
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/Android_Bundle
The Qt 5.2 during the build creates a directory into the building tree called 'android' (it is togheter with the generated object files). Into this 'android' directory it put a lot of files necessary for the binding with java android system.
But some of them needs to be adjusted depending on your app. The most common case is the AndroidManifest.xml, but there are also other files.
So, the Qt build system after generating the 'android' with defaults files, copy all your custom files from ANDROID_PACKAGE_SOURCE_DIR, overwriting the default ones created automatically.
And now comes the strange difficult thing to manage: the res/values/strings.xml
This files contains a sort of 'translations' for strings used in the AndroidManifest.xml. It looks like:
<?xml version='1.0' encoding='utf-8'?>
<string name="ministro_not_found_msg">Can\'t find Ministro service.\nThe application can\'t start.</string> <string name="ministro_needed_msg">This application requires Ministro service. Would you like to install it?</string> <string name="fatal_error_msg">Your application encountered a fatal error and cannot continue.</string>
If you look the first string is "app_name". This means that if you want that your app on the smartphone as a name choose by you, you have to provide a custom strings.xml.
But... there is also a string 'local_libs' that lists all the libraries necessary to run the application that will be loaded at runtime !!!
This particular string is auto-generated by qmake depending on your .pro configuration.
So, let consider this scenario:
- You setup a simple .pro and start creating your app
- Then you copy the strings.xml from build tree into ANDROID_PACKAGE_SOURCE_DIR and you change the "app_name"
- Then you want to use another module (sensors) and you add to .pro "QT += sensors"
- Baammm ERROR ... !!!
Because now the app requires additional libraries that has to be specified into strings.xml, but the build system will use your custom strings.xml overwriting the auto-created ones... and your custom strings.xml lacks the correct list of all libraries needed to put into the APK !!!
== Solution ==
- Everytime you change your .pro, comment the ANDROID_PACKAGE_SOURCE_DIR directive into .pro
- Do only a simple "Deploy" without running the app
- Check manually in the 'android' directory auto-generated if same of your custom files in ANDROID_PACKAGE_SOURCE_DIR has been different (use diff command if you are under linux)
- Apply the relevant modification
- Uncomment the ANDROID_PACKAGE_SOURCE_DIR
- Clean everything
- Rebuild and "Deploy"
Just a last remark:
I know that it's a beta... but I think we should file this case in someway (something like a bug) because it is very difficult to handle this situations and making the developers aware about that case they can figure out an automatic way of handling this sort of situations.
How can we do that ??
"bug report system":http://bugreports.qt-project.com is the place. Don't forget to first check if there's something there related to your problem.
Be as precise as possible (e.g. your post with the solution), so they may pinpoint the problem quicker.
Happy coding !
I created this QTBUG-34481
It's my first bugreport, I hope I did everything correctly.
Ok, I think that I don't write it correctly, or they don't understand correctly that situations.
So, please, people that had the same problem of me, can see the bug I opened and to add a comment or vote it, just to not be alone :-)
The rapidity of the answers gave to me on the bugrepors is straordinary :-)
I'll suggest to read the comments on the QTBUG-34481 especially the last one indicating the correct place for create a custom strings.xml