如何在Ionic Pro中配置正确版本的play-services并完成构建
Got it, let's walk through exactly how to fix this and get your Ionic Pro builds working with the correct Play Services versions. Here's the step-by-step process:
1. Modify the project.properties file locally
First, navigate to your Ionic project's root directory. From there, go into the platforms/android folder and open the project.properties file in your favorite text editor.
Look for these two lines:
com.google.android.gms:play-services-maps:+ cordova.system.library.3=com.google.android.gms:play-services-location:+
The + sign tells Cordova to pull the latest available version, which can cause compatibility issues in Ionic Pro builds. Replace the + with a specific, stable version number that's compatible with your project (like 17.0.0—adjust this to a version that works for your plugins and target SDK). Your modified lines should look like this:
com.google.android.gms:play-services-maps:17.0.0 cordova.system.library.3=com.google.android.gms:play-services-location:17.0.0
Pro tip: Make sure both versions match! Mismatched Play Services versions are a common cause of Android build failures.
2. Commit the changes to Git
Since Ionic Pro uses Git to sync your project, you need to ensure your modification is tracked:
- Head back to your project's root directory
- Run
git statusto confirmplatforms/android/project.propertiesshows up as a modified file - Stage the change with
git add platforms/android/project.properties - Commit it with a clear message:
git commit -m "Lock Google Play Services versions for Ionic Pro builds"
3. Push to Ionic Pro and trigger a build
Now sync your updated code to Ionic Pro and start a build:
- Push your commit to the Ionic Pro remote:
git push ionic master(replacemasterwith your target branch if you're using a different one) - Log into your Ionic Pro dashboard, select your app, and go to the Build tab
- Choose the Android platform and start a new build task. The system will use your locked Play Services versions instead of pulling the latest.
Bonus: Avoid manual edits in the future
If you ever remove and re-add the Android platform (ionic cordova platform rm android && ionic cordova platform add android), the project.properties file will reset. To fix this permanently, add the dependency locks directly to your config.xml:
<platform name="android"> <!-- Add these lines inside the Android platform block --> <framework src="com.google.android.gms:play-services-maps:17.0.0" /> <framework src="com.google.android.gms:play-services-location:17.0.0" /> <!-- Your existing Android preferences/plugins go here --> </platform>
This way, every time you add the Android platform, Cordova will automatically inject the correct version numbers into project.properties without you having to edit it manually.
内容的提问来源于stack exchange,提问作者Alex

