I have an android library with file structure below.
Android_Library βββ libs βββ src βββ instrumentTest β βββ assets β βββ java βββ main βββ aidl βββ gen βββ java βββ res
When I compile the library with Gradle, the task succeeds. However, when I try to start connectCheck, I get the following errors that the R file was not found:
: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'. > 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
Initially, I thought this was a problem in generating the R resource, but then I expect it to also fail during assembly.
Edit:
I tried both to have and the import operator R (I know that this is wrong) and does not have the import operator R. Both results lead to the same error.
DECIDE:
Thanks to @Xav's hint (below): I am extracting a library from a larger project and trying to build it myself for unit testing.
The change
import com.example.app.R;
in library files on
com.example.library.R
allows you to test the connection.
(apparently, the res files for the main application and the library are the same).
Additional notes:
Since the switch statement takes the value R id, the switch statement works during compilation. However, I still don't know why gradlew assemble works with invalid import statements, and gradlew connectedCheck fails.
source share