With the help of a colleague I found the problem. The problem was an outdated version in the qpm repository. Here are the steps for a kind of hello world project with androidnative:
Create a new project with Qt Creator and choose Qt Quick app template, that supports Android, with an empty window.
Build and run this template to check you project and create useful Android sources, that you need later.
Install the androidnative library in the root directory of the created project with qpm install android.native.pri as described in the installation tutorial of the library.
Go to a sub-directory cd vendor/android/native/pri and update the code with git checkout masterand git pull
Go back to the root directory of your project and add a sub-directory android-sources
Copy the AndroidManifext.xml file from the build directory of your project, that was created in step 2, to the new android-sources directory.
Copy the build.grandle file from the build directory of your project, that was created in step 2, to the new android-sources directory.
Add the following lines to this build.granle file:
apply from: "androidnative.gradle"
setAndroidNativePath("/../vendor/android/native/pri")
Copy the androidnative.grandle file to the android-source directory.
Add the AndroidManifest.xml and build.grandle to your project with the contextual menu for adding existing files in the file tree of your project in Qt Creator.
Add these lines to your project's .pro file:
include(vendor/vendor.pri)
android {
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
}
Now edit your main.cpp file and add the import statements and the following code snipped:
#ifdef Q_OS_ANDROID
#include "AndroidNative/systemdispatcher.h"
#include "AndroidNative/environment.h"
#include "AndroidNative/debug.h"
#include "AndroidNative/mediascannerconnection.h"
#include <QtAndroidExtras/QAndroidJniObject>
#include <QtAndroidExtras/QAndroidJniEnvironment>
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
Q_UNUSED(vm);
qDebug("NativeInterface::JNI_OnLoad()");
// It must call this function within JNI_OnLoad to enable System Dispatcher
AndroidNative::SystemDispatcher::registerNatives();
return JNI_VERSION_1_6;
}
#endif
Finally you can add some code for a simple hello world example. Firs the Import statement.
import QtQuick.Controls 2.0
import AndroidNative 1.0 as AN
Then some QML code inside the Window element:
title: qsTr("Hello World")
AN.Share {
id: an
}
Button {
text: "Share"
onClicked: {
an.shareContent( {
// leave it empty for a stupid example
} );
}
}
You find more instructions here at Github.