title: "Package R does not exist" error when building with Gradle from command line
body: <p>I'm attemping to build an <code>Android</code> project with <code>Gradle</code> from command line, but found a problem when I want to change the directory structure. </p>
  
  <p>Currently is like this:</p>
  
  <pre><code>.
  └── main
      ├── AndroidManifest.xml
      ├── ic_launcher-web.png
      ├── java
      │   └── com 
      │       └── myproject
      │           └── MainActivity.java
      └── res 
          ├── ... 
          ├── layout
          │   ├── activity_main.xml
          │   └── fragment_main.xml
          ├── ... 
          ...
  </code></pre>
  
  <p>Then I execute:</p>
  
  <pre><code>./gradlew clean build
  </code></pre>
  
  <p>That ends with:</p>
  
  <pre><code>BUILD SUCCESSFUL
  </code></pre>
  
  <p>Ok. All fine. But now I want to create a new directory, so:</p>
  
  <p>I create an <code>ui</code> directory and move <code>MainActivity.java</code> there:</p>
  
  <pre><code>.
  └── main
      ├── AndroidManifest.xml
      ├── ic_launcher-web.png
      ├── java
      │   └── com
      │       └── myproject
      │           └── ui
      │               └── MainActivity.java
      └── res
          ├── ...
          ├── layout
          │   ├── activity_main.xml
          │   └── fragment_main.xml
          ├── ...
          ...
  </code></pre>
  
  <p>Modify its package:</p>
  
  <pre><code>package com.myproject.ui;
  
  // imports
  
  public class MainActivity extends ActionBarActivity {
      ...
  }
  </code></pre>
  
  <p>Modify its <code>android:name</code> attribute in <code>AndroidManifest.xml</code>:</p>
  
  <pre><code>&lt;activity 
      android:name=".ui.MainActivity" 
      android:label="@string/app_name" &gt;
      ...
  &lt;/activity&gt;
  </code></pre>
  
  <p>And try to compile it again:</p>
  
  <pre><code>./gradlew clean build
  </code></pre>
  
  <p>With following errors:</p>
  
  <pre><code>/home/birei/MyDummyProject/MyProject/src/main/java/com/myproject/ui/MainActivity.java:19: error: package R does not exist
          setContentView(R.layout.activity_main);
                          ^
  /home/birei/MyDummyProject/MyProject/src/main/java/com/myproject/ui/MainActivity.java:23: error: package R does not exist
                      .add(R.id.container, new PlaceholderFragment())
                            ^
  /home/birei/MyDummyProject/MyProject/src/main/java/com/myproject/ui/MainActivity.java:33: error: package R does not exist
          getMenuInflater().inflate(R.menu.main, menu);
                                     ^
  /home/birei/MyDummyProject/MyProject/src/main/java/com/myproject/ui/MainActivity.java:43: error: package R does not exist
          if (id == R.id.action_settings) {
                     ^
  /home/birei/MyDummyProject/MyProject/src/main/java/com/myproject/ui/MainActivity.java:60: error: package R does not exist
              View rootView = inflater.inflate(R.layout.fragment_main, container, false);
  
  BUILD FAILED
  </code></pre>
  
  <p>What am I doing wrong? Any ideas?</p>
  
  <p>Thank you.</p>