android - AutoValue 在 Android 项目中找不到生成的构造函数

标签 android auto-value

我正在努力获得 AutoValue在 Android 项目中工作。它似乎对其他人有用,所以我一定只是遗漏了一些东西。我试过启用 jack 编译器,但似乎没有帮助。

Here是一个演示项目,当我在本地构建它时失败了。投诉在this class ,它找不到 AutoValue_Repo 构造函数。

这是我的项目级别build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.1'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

还有我的模块级别build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "org.cse390.githubhotness"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    provided 'com.google.auto.value:auto-value:1.2-rc1'
    compile "com.google.auto.value:auto-value:1.2-rc1"
    apt "com.google.auto.value:auto-value:1.2-rc1"

    compile 'com.jakewharton:butterknife:8.4.0'
    apt 'com.jakewharton:butterknife-compiler:8.4.0'

    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'

    testCompile 'junit:junit:4.12'
}

这是没有被自动赋值的类:

@AutoValue
public abstract class Repo {
  public abstract int id();
  public abstract String name();
  public abstract String fullName();
  public abstract String description();
  public abstract int numStars();
  public abstract String language();
  public abstract String htmlUrl();

  static Repo create(int id, String name, String fullName, String description,
                     int numStars, String language, String htmlUrl) {
    // See "How do I...?" below for nested classes.
    return new AutoValue_Repo(id, name, fullName, description, numStars,
        language, htmlUrl);
  }

}

这里有什么明显的错误吗?

最佳答案

因为我们在这里生成一个类,所以需要公开访问该方法,这样 autovalue 才能工作。

  public static Repo create(int id, String name, String fullName, String description,
                 int numStars, String language, String htmlUrl) {
        // See "How do I...?" below for nested classes.
        return new AutoValue_Repo(id, name, fullName, description, numStars,
                    language, htmlUrl);
   }

关于android - AutoValue 在 Android 项目中找不到生成的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40122530/

相关文章:

Android JSoup 不工作

java - 如何使用 AutoValue 解析结构为对象数组的 JSON?

具有 AutoValue 的 Android Room Persistence 库实体

android - 共享文件 - 找不到新的 Android 10 范围存储限制的解决方案?

java - 无法使用 FileProvider 和外部 PDF 编辑器保存 PDF 文件

android - 如何在arm的内联汇编中执行qadd命令?

java - Google AutoValue 无法识别 AutoValue_CustomType

android - Android 版 Google 登录中的问题

android - 什么是 autovalue.shaded 或者什么是 shaded jar?

java - 如何在 Android 中使用 firebase 9.2 的自动值