android10 / android10/Android-CleanArchitecture
AutoValue in domain module : Cannot resolve symbol generated AutoValue_Foo
- Dominant language
- Java
- Stars
- 15.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the domain module's build.gradle and reproduce the mismatch between Android Studio's unresolved AutoValue_Trip warning and the successful build. Inspect how the apt-generated sources are exposed to the IDE, including the attempted generated sourceSet, and verify that compileJava still succeeds without introducing source-path errors. Done means the generated class is recognized by Android Studio without breaking compilation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- build-system, developer-experience
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100