-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android: Copy resource files in the correct folder #1753
Comments
There's some history here that's worth knowing. The Android platform moved from being an Eclipse (ant) project to being an Android Studio (gradle) project, and the project structure changed. Previously, To avoid breaking all the existing plugins, there's a remapping system in cordova-android that will take "old" paths and rewrite them to the newer paths. That remapping appears to be used unconditionally The workaround is to specify the full path that you want for the file, i.e. It's not feasible to automatically prefix all resource files with |
I understand. On my opinion checking for |
Android has a concept of build variants so i don't think it's a good idea to auto prefix and assume app/src/main.
So I think we should consider this a doc issue. |
Thank you @breautek, I didn't know about this. Could this path nevertheless automatically calculated for build variants? Is it really needed do decide in which build variant a resource file will be copied? Does |
I don't think so. Android has a few reserved ones, So outside of those 3, the build variant name is entirely up to the developer. Cordova CLI only ever uses Even if we conditionally prefix and assume
And each one of those directories can have variants as well, for localization, themes, device form factors, etc:
And each of these variants can be compounded, for example: I think if we WERE going to do any sort of prefixing, the path must begin with <resource-file src="Foo.xml" target="res/values/Foo.xml" /> <!-- goes to app/src/main/res/values/Foo.xml -->
<resource-file src="Foo.xml" target="/res/values/Foo.xml" /> <!-- goes to app/src/main/res/values/Foo.xml -->
<resource-file src="Foo.xml" target="app/src/main/res/xml/Foo.xml" /> <!-- goes to app/src/main/res/xml/Foo.xml -->
<resource-file src="Foo.xml" target="/bar/res/values/Foo.xml" /> <!-- goes to bar/res/values/Foo.xml which is not really a valid location -->
<resource-file src="Foo.xml" target="app/src/bar/res/values/Foo.xml" /> <!-- goes to app/src/bar/res/values/Foo.xml -->
<resource-file src="Foo.xml" target="foobar/src/main/res/values/Foo.xml" /> <!-- goes to foobar/src/main/res/values/Foo.xml which is valid only if something has created the foobar android module --> The key point here is we should be careful not to prefix something seems be an absolute path to a particular android module and/or build variant.
We don't have any explicit directives or anything to create build variants but it can be done via |
Hi @breautek, thank you for your very detailed answer and explanation. I know about these resource identifiers and my thought was also that the path should start with When Cordova is used for building or preparing, I think it should know where the destination is, otherwise it could not build/prepare? So if Cordova knows it builds to |
Bug Report
I want to copy resources to the
res
directory of the android app.Problem
I followed the documentation for the resource-file tag of the
config.xml
, where it shows an example to copy a resource file tores/values/
for Android:When I use this code, the resource file gets copied to
platforms/android/res/values
, but the correct folder would beplatforms/android/app/src/main/res/values
.When I do the same for iOS with
It gets correctly copied to
platforms/iOS/[AppName]/Resources
(using cordova-ios 7.1.1).Should there be not a similar behavior for Android? Must the documentation be updated to the correct path, or is this an issue in the Cordova-cli?
What is expected to happen?
The resource file should be put in the correct folder like the documentation says.
What does actually happen?
The resource file is copied in the wrong place.
Information
Command or Code
Environment, Platform, Device
Version information
Checklist
The text was updated successfully, but these errors were encountered: