title: Android library assembles with Gradle but "package R does not exist" error raise on connectedCheck
body: <p>I have an android library with the file structure below.</p>
  
  <pre><code>Android_Library
  ├── libs
  └── src
      ├── instrumentTest
      │   ├── assets
      │   └── java
      └── main
          ├── aidl
          ├── gen
          ├── java
          └── res
  </code></pre>
  
  <p>When I assemble the library with Gradle, the task runs successfully. However, when I try running a connectedCheck I get the following errors about the R file not being found:</p>
  
  <pre><code>:validateDebugSigning
  :packageDebug
  :assembleDebug
  :prepareTestDependencies
  :compileTestAidl
  :processTestTestManifest
  :generateTestBuildConfig
  :mergeTestAssets
  :compileTestRenderscript
  :mergeTestResources
  :processTestResources
  :compileTest
  
  
   Android_Library/src/instrumentTest/java/com/example/library/util/UtilTests.java:514: error: package R does not exist
                          case R.plurals.time_days_ago: {
                                ^
          ...
  
  Note: Recompile with -Xlint:unchecked for details.
  18 errors
  :compileTest FAILED
  
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':compileTest'.
  &gt; Compilation failed; see the compiler error output for details.
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  
  BUILD FAILED
  </code></pre>
  
  <p>I originally thought that it was a problem in the R resource generation, but then I would expect it to also fail when assembling.</p>
  
  <p>Edit:</p>
  
  <p>I have tried both having and R import statement (which I know is incorrect) and not having and R import statement. Both result in the same error.</p>
  
  <p>SOLVED:</p>
  
  <p>Thanks to @Xav's tip (below): I'm extracting a library from a larger project and attempting to build it on its own for modular testing.</p>
  
  <p>Changing the </p>
  
  <p><code>import com.example.app.R;</code> </p>
  
  <p>statements in the library files to </p>
  
  <p><code>com.example.library.R</code></p>
  
  <p>allows the connected check to run.</p>
  
  <p>(apparently the res files for both the main app and the library are the same).</p>
  
  <p>Additional notes:</p>
  
  <p>Since the switch statement takes in R id's the switch statement works when it compiles. However, I am still unsure of why <code>gradlew assemble</code> works with the incorrect <code>import</code> statements while <code>gradlew connectedCheck</code> fails.</p>