Cordova-Android 7使用source-file复制PNG文件时出现问题求助
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/anddrawable/to confirm your files are there. If they're missing, double-check thesrcpath in yoursource-filetags (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

