You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PhoneGap构建旧版应用遇Gradle弃用报错,请求技术支持

Troubleshooting Your PhoneGap Build Failure (Even for Previously Working Old Apps)

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.gradle file, jump to line 138, and replace the deprecated leftShift (written as << in code) with doLast. For example:
    // Old code
    myTask << { /* ... */ }
    // New code
    myTask.doLast { /* ... */ }
    
  • Align Cordova-android with Gradle: Run cordova platform ls to check your Android platform version. If you're on an older cordova-android (e.g., 5.x), make sure you're using a compatible Gradle version (3.x). If possible, upgrade cordova-android to 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.xml or package.json to remove the ^ from plugin versions. For example, change onesignal-cordova-plugin@^2.3.1 to onesignal-cordova-plugin@2.3.1 to force npm to install the exact version that worked before.
  • Adjust compat plugin: If your cordova-android is 6.3.0 or newer, you can remove cordova-plugin-compat entirely (newer Cordova versions have built-in compatibility). If you need it, downgrade to 1.0.0 with cordova plugin add cordova-plugin-compat@1.0.0.
  • Check whitelist plugin: If your cordova-android is <4.0, uninstall the whitelist plugin with cordova 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

  1. Run cordova clean to clear cached build files.
  2. Reinstall plugins with locked versions: cordova plugin remove --save && cordova plugin add --save [plugin-name@exact-version] for each plugin.
  3. Rebuild your app.

内容的提问来源于stack exchange,提问作者rrjlt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:51:57