gpt4 book ai didi

Android 库使用 Gradle 进行组装,但在 connectedCheck 上出现 "package R does not exist"错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:22:33 25 4
gpt4 key购买 nike

我有一个具有以下文件结构的 android 库。

Android_Library
├── libs
└── src
├── instrumentTest
│   ├── assets
│   └── java
└── main
├── aidl
├── gen
├── java
└── res

当我使用 Gradle 组装库时,任务成功运行。但是,当我尝试运行 connectedCheck 时,出现以下有关未找到 R 文件的错误:

: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

我本来以为是R资源生成的问题,没想到组装的时候也会失败。

编辑:

我试过有和 R 导入语句(我知道这是不正确的)和没有和 R 导入语句。两者都会导致相同的错误。

已解决:

感谢@Xav 的提示(如下):我正在从一个较大的项目中提取一个库,并尝试自行构建它以进行模块化测试。

改变

import com.example.app.R;

库文件中的语句

com.example.library.R

允许连接的检查运行。

(显然主应用程序和库的 res 文件是相同的)。

补充说明:

由于 switch 语句采用 R id,因此 switch 语句在编译时起作用。但是,我仍然不确定为什么 gradlew assemble 使用不正确的 import 语句而 gradlew connectedCheck 失败。

最佳答案

虽然这似乎与错误无关,但我看到您正在使用来自 R 类的 ID 执行 switch 语句,但您在库中。

这是不可能的,因为这些 ID 不是最终的。

我想知道这是否是错误,但编译器感到困惑并输出不同的错误消息。

关于Android 库使用 Gradle 进行组装,但在 connectedCheck 上出现 "package R does not exist"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17711204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com