android10 / android10/Android-CleanArchitecture
AutoValue in domain module : Cannot resolve symbol generated AutoValue_Foo
- 主要语言
- Java
- 星标
- 15.5k
- 派生
- 3.3k
- PR 合并指标
- 30 天内没有已合并 PR
描述
I am trying to use AutoValue in the domain module.
Here is the AutoValue class data implementation :
```
import com.google.auto.value.AutoValue;
import org.jetbrains.annotations.Nullable;
import java.util.Date;
@AutoValue
public abstract class Trip {
public abstract int id();
public abstract String name();
public abstract int totalDistance();
@Nullable public abstract Date startDate();
@Nullable public abstract Date endDate();
public static Builder builder() {
return new AutoValue_Trip.Builder().totalDistance(0);
}
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder id(int id);
public abstract Builder name(String name);
public abstract Builder totalDistance(int totalDistance);
public abstract Builder startDate(Date startDate);
public abstract Builder endDate(Date endDate);
public abstract Trip build();
}
}
```
Android Studio cannot find the generated AutoValue_Trip class, so it marks it as an error however, the project builds and runs just fine.
Here is my module's build.gradle file
```
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
classpath "net.ltgt.gradle:gradle-apt-plugin:0.12"
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: "net.ltgt.apt"
apply plugin: 'me.tatarka.retrolambda'
//noinspection GroovyUnusedAssignment
sourceCompatibility = 1.8
//noinspection GroovyUnusedAssignment
targetCompatibility = 1.8
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
}
}
dependencies {
def domainDependencies = rootProject.ext.domainDependencies
def domainTestDependencies = rootProject.ext.domainTestDependencies
apt domainDependencies.autoValue
compileOnly domainDependencies.autoValue
provided domainDependencies.javaxAnnotation
compile domainDependencies.javaxInject
compile domainDependencies.rxJava
compile domainDependencies.arrow
testCompile domainTestDependencies.junit
testCompile domainTestDependencies.mockito
testCompile domainTestDependencies.assertj
}
```
I have tried using a sourceSet as follows to add the generated build files and folders to the source path:
```
main {
java {
srcDirs += 'src/../build/generated'
}
}
```
But then I was getting compileJava errors.
Has anyone ran into this issue and how did you correct it? Additional info will be provided if necessary.
贡献指南
这个仓库没有索引到贡献指南
调研方向
从 domain 模块的 build.gradle 开始,重现 Android Studio 报告无法解析 AutoValue_Trip 的警告与 build 成功之间的不一致。检查 apt 生成的源如何暴露给 IDE,包括尝试过的生成 sourceSet,并验证 compileJava 仍能成功执行,同时不会引入源路径错误。当 Android Studio 能够识别生成的类且不破坏编译时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- android, java
- 领域
- build-system, developer-experience
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100