Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent IntelliJ from copying resources into the project compiler output directory?

I have the following directory structure within IntelliJ, which contains an Android library project:

java/com/example/base/AndroidManifest.xml
java/com/example/base/assets # contains Android assets
java/com/example/base/res    # contains Android resources
java/com/example/base/Base.java
java/com/example/base/base.iml

The base.iml contains the following:

<content url="file://$MODULE_DIR$">
  <sourceFolder url="file://$MODULE_DIR$"
                isTestSource="false"
                packagePrefix="com.example.base" />
  <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
  <excludeFolder url="file://$MODULE_DIR$/res" />
</content>

When I build an Android application project that depends on my library project, I get an error:

[myapp] java.util.zip.ZipException: duplicate entry: res/drawable/image_shadow.9.png

In the Project Structure dialog, I configured Project compiler output to be an out directory under the root of my project. When I try to build my Android project, I noticed that copies of my Android resources end up under the out/production/base/com/example/base/res/ folder.

My hypothesis is that my Android resources are being treated like "normal" Java resources (the type you would load using Class.getResource()), which is why they are being copied to out/production, which in turn causes the duplicate entry exception that I am seeing.

Any idea if this is the case? If so, how can I prevent these files from being copied over? In Eclipse, the <classpathentry> element in the .classpath file has an excluding attribute that takes a glob pattern to prevent this sort of behavior.

like image 567
bolinfest Avatar asked Oct 22 '12 18:10

bolinfest


People also ask

What is compiler output IntelliJ?

Compiler output path is the path to the directory in which IntelliJ IDEA stores the compilation results. In this directory, the IDE creates two sub-directories: output for production code and test output for test sources.

How do I change the source folder in IntelliJ?

From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Modules. Select the necessary module and open the Sources tab. next to Source Folders or Test Source Folders. Specify the package prefix and click OK.

What is sources root in IntelliJ?

Sources Root - this is where your actual project code goes - typically in src/main/scala (though you can change that, or add extra source directories in your build). Directories nested below this level should be packages. Intellij needs to know these are sources so it can highlight them, check them for errors, etc.

How do I change directory in IntelliJ module?

Select the top-level directory in the Project tool window and press Alt+Insert or select New | Module from the context menu. The New Module wizard opens. From the list on the left, select a module type.


1 Answers

I encountered a similar problem because the main dir was marked as "Sources".

So in project structure, for the Android facet, under the "Structure" tab I had:

... Resources directory: .../src/main/res ...

And under the normal "Sources" tab for the module, the main dir under src had been marked as "Sources".

I fixed it by making the Sources tab look like:

- src (unmarked) - main (unmarked) - java (Sources) - res (Resources)

So I guess the error is because the res things are being packed into the zip both as sources and resources hence the duplication.

like image 166
rmin Avatar answered Oct 13 '22 01:10

rmin