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

Cordova-Android 7使用source-file复制PNG文件时出现问题求助

Troubleshooting source-file Tag Issues in Cordova-Android 7.0

Hey there, let's break down why your source-file tags aren't working as expected in Cordova-Android 7.0, plus fix the path issue you're running into.

The Core Problem: Project Structure Changes in Cordova-Android 7.x

Cordova-Android 7.0 made a big shift to align with Android Studio's modern Gradle-based project structure. Before this version, resources like drawables went straight into the platforms/android/res/ directory. But starting with 7.x, all app-specific resources are now stored under the platforms/android/app/src/main/res/ path instead.

Your current target-dir values point to the old legacy path, which means your PNG and XML files are being copied to a location the Android build process no longer uses for your app.

Fixing the source-file Paths

Update your plugin.xml entries to target the new correct resource directories:

<source-file src="res/android/drawable/ic_fingerprint_success.xml" target-dir="app/src/main/res/drawable"/>
<source-file src="res/android/drawable-hdpi/ic_fp_40px.png" target-dir="app/src/main/res/drawable-hdpi"/>

Additional Troubleshooting Steps

  • Verify file placement: After re-installing your plugin, check platforms/android/app/src/main/res/drawable-hdpi/ and drawable/ to confirm your files are there. If they're missing, double-check the src path in your source-file tags (it should be relative to your plugin's root directory where plugin.xml lives).
  • Check for case sensitivity: Android resource filenames are case-sensitive. Make sure your filenames (like ic_fp_40px.png) match exactly what you're referencing in your code.
  • Inspect plugin install logs: Run cordova plugin add <your-plugin-path> with verbose logging (--verbose) to spot any errors or warnings about missing source files or invalid target directories.

About the Missing Documentation

You're right that Cordova's official docs were slow to catch up with this 7.x change. The key takeaway is that all app resources, assets, and source files now target paths under the app/src/main/ directory in the Android platform folder, instead of the root platforms/android/ directory.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:59:52