Android library is built using Gradle, but "package R does not exist" when creating an error

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.

+4
source share
1 answer

As long as this is not error-related, I see that you are executing the switch statement using the identifiers included in the R class, but you are in the library.

This is not possible because these identifiers are not final.

I am wondering if the error is confusing, but the compiler gives another error message.

+2
source

Source: https://habr.com/ru/post/1491978/


All Articles