gpt4 book ai didi

android - Dagger 2 不生成组件

转载 作者:太空宇宙 更新时间:2023-11-03 13:46:09 25 4
gpt4 key购买 nike

每次我尝试构建我的项目时都会发生以下错误:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V

遵循负责依赖注入(inject)的类:

应用模块

@Module
public class ApplicationModule {

private static final String APP_ID = "id";
private static final String APP_SECRET = "secret";

private final Application mApplication;

public ApplicationModule(Application application) {
mApplication = application;
}

@Provides
Application provideApplication() {
return mApplication;
}

@Provides
@Singleton
Client provideClient(Application application) {
return new Client.Builder(APP_ID, APP_SECRET, application).build();
}
}

应用组件

@Singleton
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {

void inject(MainApplication application);

Application getApplication();

Client getClient();

}

主应用程序

public class MainApplication extends android.app.Application {

private ApplicationComponent component;

@Inject
Client client;

@Override
public void onCreate() {
super.onCreate();

...

component = DaggerApplicationComponent.builder()
.applicationModule(new ApplicationModule(this))
.build();
component.inject(this);
}

public ApplicationComponent getComponent() {
return component;
}

}

还有我的gradle.build (Module:app)

buildscript {
repositories {
jcenter()
maven {
url 'http://dl.bintray.com/amulyakhare/maven'
}
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
applicationId "br.mobi.santor.agora"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

repositories {
flatDir {
dirs 'libs'
}
}

final SUPPORT_LIBRARY_VERSION = '25.1.0'
final DAGGER_VERSION = '2.8'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name: 'kinvey-android-2.10.6', ext: 'aar')

// AppCompat dependencies
compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION"

// Dagger dependencies
compile "com.google.dagger:dagger:$DAGGER_VERSION"
annotationProcessor "com.google.dagger:dagger-compiler:$DAGGER_VERSION"

// Network dependencies
compile 'com.squareup.picasso:picasso:2.5.2'

// Utils dependencies
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'joda-time:joda-time:2.9.7'

testCompile 'junit:junit:4.12'
}

最佳答案

NoSuchMethodError 几乎肯定意味着类路径上的 Guava 版本比用于编译的旧版本。确保您拥有最新版本的 Guava(几乎总是可以安全地使用最新的 these compatibility guarnatees )并且它应该可以工作。

关于android - Dagger 2 不生成组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41916466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com