PhoneGap构建旧版应用遇Gradle弃用报错,请求技术支持
Hey there, let's dig into why your old PhoneGap app is suddenly failing to build, even though it worked fine before. Looking at your build logs, there are a few key issues to address:
1. Gradle Deprecation Warnings (Potential Hidden Conflicts)
Your log shows several Gradle methods are deprecated (like Task.leftShift(Closure), JavaCompile.setDependencyCacheDir()), with plans to remove them in future Gradle versions. While these are warnings on their own, they can trigger silent failures if your project's Gradle version doesn't align with your Cordova platform or plugins.
Fixes:
- Update Gradle syntax: Open your project's
/project/build.gradlefile, jump to line 138, and replace the deprecatedleftShift(written as<<in code) withdoLast. For example:// Old code myTask << { /* ... */ } // New code myTask.doLast { /* ... */ } - Align Cordova-android with Gradle: Run
cordova platform lsto check your Android platform version. If you're on an oldercordova-android(e.g., 5.x), make sure you're using a compatible Gradle version (3.x). If possible, upgradecordova-androidto a stable release (like 7.x) that plays nicely with newer Gradle versions.
2. Plugin Version Compatibility Issues
The plugin installation logs reveal some version mismatches that could break your build:
- onesignal-cordova-plugin: You specified
^2.3.1, but npm installed 2.4.1 (the^lets npm auto-upgrade minor versions). This newer version might not be compatible with your old project setup. - cordova-plugin-compat: You asked for
^1.0.0, but got 1.2.0. This plugin handles API compatibility, but newer versions can conflict with older Cordova platforms. - cordova-plugin-whitelist: The log notes it only works with
cordova-android 4.0+. If your platform is older than that, this plugin is redundant and could cause conflicts.
Fixes:
- Lock plugin versions: Edit your
config.xmlorpackage.jsonto remove the^from plugin versions. For example, changeonesignal-cordova-plugin@^2.3.1toonesignal-cordova-plugin@2.3.1to force npm to install the exact version that worked before. - Adjust compat plugin: If your
cordova-androidis 6.3.0 or newer, you can removecordova-plugin-compatentirely (newer Cordova versions have built-in compatibility). If you need it, downgrade to 1.0.0 withcordova plugin add cordova-plugin-compat@1.0.0. - Check whitelist plugin: If your
cordova-androidis <4.0, uninstall the whitelist plugin withcordova plugin remove cordova-plugin-whitelist. For 4.0+, keep it (your log shows you have version 1.3.3, which is fine).
3. Deprecated API Warnings in CordovaLib
The log mentions files in CordovaLib using/overriding deprecated APIs. These are usually warnings, but they can escalate to errors if your Android SDK target is too new.
Fixes:
- Upgrade cordova-android: Newer versions of the Android platform include updated CordovaLib code that replaces deprecated APIs. Run
cordova platform update android@[stable-version](e.g.,android@7.1.4) to get the pre-built fixes. - If you can't upgrade: If you're stuck on an old platform, you'd need to manually edit CordovaLib files to replace deprecated methods with current Android SDK equivalents (this requires basic Android development knowledge).
Final Steps to Test
- Run
cordova cleanto clear cached build files. - Reinstall plugins with locked versions:
cordova plugin remove --save && cordova plugin add --save [plugin-name@exact-version]for each plugin. - Rebuild your app.
内容的提问来源于stack exchange,提问作者rrjlt

