Andrey Samoilov
Andrey Samoilov

Reputation: 94

Qt on Android studio

Using Qt creator, I complied MyLib.so, MyLibQt.so (compiled for android). MyLib is wrapper for using MyLibQt. In MyLibQt I have such lines

if (!QApplication::instance())
{
   g_bCleanUpInstance = true;
   new QApplication(argc, argv);
}

At Android Studio I added these libs to project (jniLibs). The lib has been successfully added to apk, it has been compiled. The problem is: when I try call method from MyLib, using previous lines of code, I get exception:

A/MyLibQt.dll: (null):0 ((null)): This application failed to start because it could not find or load the Qt platform plugin "android"

I added to jniLibs libqtforandroid.so, but it didn't helped. So, my question is: how to resolve it?

Upvotes: 3

Views: 3947

Answers (2)

Andrey Samoilov
Andrey Samoilov

Reputation: 94

Sorry for so late answer. Root cause of the issue was not so obvious. Qt plugin for Android requires function main() in your custom library. If the plugin doesn't find the function, the plugin throws exception and the plugin will not correctly loaded.

It was about Qt5.4- 5.7. I don't know how it is now but can suggest that there is same situation.

Upvotes: 2

dtech
dtech

Reputation: 49279

As it is obvious from the error message, a Qt application is not just some code you can run willi-nilly, it runs against its own "runtime" that is the platform plugin, which provides the link between the Qt code and the device.

The platform plugin will be bundled with the Qt application when you are using the Qt toolchain, and in the case of android Qt apps, the Qt code is compiled as a .so library anyway. But you are explicitly compiling it as a library, so the platform plugin is not included, because it is assumed you will be using that library in a Qt application which will include it.

It may be possible to do it manually, but I am not an expert on that subject, there might be other complications, such as not running on an activity tailored to support a Qt application, or some other auxiliary files needed by Qt which would typically be created and bundled by the Qt toolchain, but it is a safe bet to do the opposite thing - just build your Qt application with the Qt toolchain, and use the necessary Java code from it.

Upvotes: 1

Related Questions