使用ANDROID_DEPLOYMENT_DEPENDENCIES精简Android应用后添加Qt定位组件失败求助
Let's get your app back up and running. That error tells us the QML plugin for QtPositioning isn't being deployed to your Android device—especially since you're using ANDROID_DEPLOYMENT_DEPENDENCIES, which requires explicit declaration of all plugins and libraries you need.
Root Cause
When you use ANDROID_DEPLOYMENT_DEPENDENCIES to slim down your app, Qt doesn't automatically include all plugins that come with the modules you add. You have to manually list every plugin (and their native backend libraries) that your QML code relies on.
Step-by-Step Solution
1. Update Your .pro File
Add these lines to your project's .pro file to ensure the necessary plugins and libraries are included in the deployment:
# First, declare the Qt modules you're using QT += positioning location # Explicitly add the required plugins and their Android backends to deployment ANDROID_DEPLOYMENT_DEPENDENCIES += \ # QtPositioning plugins (QML + native Android backend) $$[QT_INSTALL_PLUGINS]/qml/QtPositioning/libdeclarative_positioning.so \ $$[QT_INSTALL_PLUGINS]/positioning/libqtpositioning_android.so \ # QtLocation plugins (QML + native Android backend) $$[QT_INSTALL_PLUGINS]/qml/QtLocation/libdeclarative_location.so \ $$[QT_INSTALL_PLUGINS]/location/libqtlocation_android.so # If you're using map services like OpenStreetMap, add this too: ANDROID_DEPLOYMENT_DEPENDENCIES += $$[QT_INSTALL_PLUGINS]/geoservices/libqtgeoservices_osm.so
The $$[QT_INSTALL_PLUGINS] variable points to your Qt installation's plugin directory, so this should work regardless of where you installed Qt (as long as your kit is configured correctly).
2. Verify Plugins Are in the APK
After building, confirm the plugins are present in your APK. Extract the APK (using a tool like apktool or just rename it to .zip and unzip) and check the lib/<your-abi>/ folder—you should see all the .so files listed above.
3. Add Required Permissions to AndroidManifest.xml
Location features need permissions to work. Open your AndroidManifest.xml and add these lines inside the <manifest> tag:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- If your app needs location access in the background (Android 10+), add this: --> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
4. Clean and Rebuild
Cached build artifacts can sometimes cause issues. Do a full clean:
- Go to Build > Clean All in Qt Creator.
- Delete the
build-folder in your project directory (just to be safe). - Rebuild the project and redeploy to your device.
Additional Tips
- Ensure your Qt kit is set up for Android correctly (check that you're using a Qt version compatible with your target Android SDK—Qt 5.12+ is solid for most use cases).
- If you're using a custom-built Qt, double-check that the positioning/location plugins were compiled for Android (they should be present in the
pluginsfolder of your Qt build). - If you're still having issues, run your app with Qt Creator's debugger attached—look for additional log messages that might point to missing dependencies beyond the plugins listed.
内容的提问来源于stack exchange,提问作者Edip Ahmet

