gpt4 book ai didi

java - Google AutoValue 无法识别 AutoValue_CustomType

转载 作者:太空宇宙 更新时间:2023-11-04 09:48:04 26 4
gpt4 key购买 nike

我试图在我的 Android Studio 项目中使用 Google AutoValue 生成 HomeKey,但它没有忽略 AutoValue_HomeKey() (请参阅下面的注释代码)。使用的gradle版本:4.10.1

我的 Android 项目基于此示例: https://github.com/Zhuinden/simple-stack/tree/master/simple-stack-example-basic-java-fragment

我是否忘记应用插件,或者实现了错误的包?

HomeKey 类:

import com.google.auto.value.AutoValue;

@AutoValue
public abstract class HomeKey extends BaseKey {
public static HomeKey create() {

/*
Cannot resolve AutoValue_HomeKey()
*/
return new AutoValue_HomeKey();
}

@Override
protected BaseFragment createFragment() {
return new HomeFragment();
}
}

BaseKey 类:

import android.os.Bundle;
import android.os.Parcelable;

import gamf.tankolaskonyvelo.fragment.BaseFragment;

public abstract class BaseKey implements Parcelable {
public String getFragmentTag() {
return toString();
}

public final BaseFragment newFragment() {
BaseFragment fragment = createFragment();
Bundle bundle = fragment.getArguments();
if (bundle == null) {
bundle = new Bundle();
}
bundle.putParcelable("KEY", this);
fragment.setArguments(bundle);
return fragment;
}

protected abstract BaseFragment createFragment();
}
}

项目级别build.gradle:

buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven {url "https://jitpack.io" }

}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'
classpath 'com.google.gms:google-services:3.2.1'
}
}


allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }

}
}

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

应用程序级别build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
applicationId "gamf.tankolaskonyvelo"
minSdkVersion 20
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
androidTestImplementation('com.android.support.test.espresso:espresso- core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.github.Zhuinden:simple-stack:1.13.4'
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

implementation "com.google.auto.value:auto-value-annotations:1.6.2"
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
annotationProcessor 'frankiesardo:auto-parcel:1.0.3'
}

最佳答案

您正在使用托管在 clojars 上的 annotationProcessor 'frankiesardo:auto-parcel:1.0.3'

因此,您应该将以下存储库添加到 build.gradle 中的 allprojects { block 中:

maven { url "https://clojars.org/repo/" }

那么你应该尝试重建项目。

成功构建后,应显示注释处理生成的类。

<小时/>

(如果您检查存储库的根 build.gradle,那么您会看到示例可能使用的 Maven 存储库:

repositories {
google()
mavenCentral()
maven { url "https://clojars.org/repo/" }
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
jcenter()
}

因此,即使库本身托管在 jitpack.io 上,示例的依赖项 auto-parcel 也位于 clojars 上)

关于java - Google AutoValue 无法识别 AutoValue_CustomType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55168926/

26 4 0
文章推荐: Java,获取一个Objects元素到Map
文章推荐: linux - shell 脚本 : moving files to another directory
文章推荐: html -