android10 / android10/Android-CleanArchitecture

AutoValue in domain module : Cannot resolve symbol generated AutoValue_Foo

Đang mở
#246 1 bình luận 2 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
15.5k
Fork
3.3k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu với build.gradle của mô-đun domain và tái hiện sự không khớp giữa cảnh báo của Android Studio rằng không thể phân giải AutoValue_Trip và việc build thành công. Kiểm tra cách các source được apt tạo ra được cung cấp cho IDE, bao gồm cả sourceSet được tạo đã thử, đồng thời xác minh rằng compileJava vẫn thành công mà không gây ra lỗi về đường dẫn source. Công việc được xem là hoàn tất khi Android Studio nhận diện được class đã tạo mà không làm hỏng quá trình biên dịch.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
android, java
Lĩnh vực
build-system, developer-experience
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.