I want to move my resources directory form ./src/main/res
to ./res
in the interests of porting an app from Eclipse to Android Studio
I've added these lines to my build.gradle file:
sourceSets {
main {
resources {
srcDirs = ["./res"]
}
}
}
and Android Studio seems to recognize this after syncing my gradle files, but not really. When I open an xml file from res/layout it's clearly not recognized as a layout file, and I get the error message http://schemas.android.com/apk/res/android "URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)"
Is there a way to re-arrange my source files, or is sourceSets.main.resources.srcDirs
a lie?
Adding on: I did try using res
instead of resources
. This was the result:
Build file '/Users/falk/Android/Foo/fooapp/build.gradle' line: 33
A problem occurred evaluating project ':fooapp'.
> No signature of method: build_ag5e2qc90oc7bck5pxaqmbzuf.sourceSets() is applicable for argument types: (build_ag5e2qc90oc7bck5pxaqmbzuf$_run_closure2) values: [build_ag5e2qc90oc7bck5pxaqmbzuf$_run_closure2@4536888e]
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':fooapp'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
...
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: groovy.lang.MissingMethodException: No signature of method: build_ag5e2qc90oc7bck5pxaqmbzuf.sourceSets() is applicable for argument types: (build_ag5e2qc90oc7bck5pxaqmbzuf$_run_closure2) values: [build_ag5e2qc90oc7bck5pxaqmbzuf$_run_closure2@4536888e]
at build_ag5e2qc90oc7bck5pxaqmbzuf.run(/Users/falk/Android/Foo/fooapp/build.gradle:33)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
... 140 more
CodePudding user response:
Use res
instead of resources
sourceSets {
main {
res {
srcDirs = ["./res"]
}
}
}
// com.android.build.api.dsl.AndroidSourceSet
/** The Java-style resources for this source-set */
val resources: AndroidSourceDirectorySet
/** The Android Resources directory for this source-set. */
val res: AndroidSourceDirectorySet