【问题标题】:Gradle doesn't shows dagger2 component graph anymore after updateGradle 更新后不再显示 dagger2 组件图
【发布时间】:2018-04-13 01:00:37
【问题描述】:

最近,我将 Gradle 版本和 gradle 插件更新为: 4.6 和 3.1.1。现在,当我尝试编译有一些依赖问题的项目时,gradle 只会指出一个编译错误,说它找不到类 DaggerApplicationComponent。

之前,当出现dagger依赖问题时,会显示什么依赖不满足,依赖树。喜欢:

"Dagger 2 cannot be provided without an @Provides-annotated method"

"Error:(51, 10) error: .BaseActivity cannot be provided without an @Provides-annotated method. BaseActivity is injected at AppComponent.inject(baseActivity) Error:(75, 10) error: MainActivity cannot be provided without an @Inject constructor or from an @Provides-annotated method. MainActivity is injected at .AppComponent.inject(mainActivity)"

现在它显示了这个:

不满足的依赖来自 java 库中的类。它的gradle文件是:

apply plugin: 'java-library'
apply plugin: 'net.ltgt.apt'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.google.dagger:dagger:2.15'

    apt 'com.google.dagger:dagger-compiler:2.15'


    api 'com.squareup.retrofit2:retrofit:2.4.0'

    api 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'


    implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
    implementation 'com.squareup.okhttp:logging-interceptor:2.6.0'

    implementation 'io.reactivex.rxjava2:rxjava:2.1.12'


    api 'com.squareup.moshi:moshi:1.5.0'
    /*implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.google.code.gson:gson:2.8.2'*/



}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"

根 gradle 文件是:

// Top-level build file whesugre you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'
        classpath 'com.google.gms:google-services:3.1.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }



}



plugins {
    id "net.ltgt.apt" version "0.15"

}

allprojects {


    repositories {
        jcenter()

        maven { url 'https://maven.google.com' }
        google()
    }



}


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


Android Studio 3.1.1
Build #AI-173.4697961, built on April 3, 2018
JRE: 1.8.0_152-release-1024-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.14.0-deepin2-amd64

是否需要额外的配置?


编辑:

现在我通过命令行运行构建来解决它。

./gradlew build

它显示:

home/alexandre/dev/projetos/gitlab/BeerCollection/app/src/main/java/com/github/alexpfx/udacity/beercollection/dagger/ApplicationComponent.java:22: error: [com.github.alexpfx.udacity.beercollection.dagger.HomeSubComponent.inject(com.github.alexpfx.udacity.beercollection.ui.home.HomeFragment)] com.github.alexpfx.udacity.beercollection.databaselib.search.BeerRemoteDataSource cannot be provided without an @Provides-annotated method.
public interface ApplicationComponent {
       ^
      com.github.alexpfx.udacity.beercollection.databaselib.search.BeerRemoteDataSource is injected at
          com.github.alexpfx.udacity.beercollection.favorite.FavoriteInteractorImpl.<init>(…, beerRemoteDataSource)
      com.github.alexpfx.udacity.beercollection.favorite.FavoriteInteractorImpl is injected at
          com.github.alexpfx.udacity.beercollection.dagger.FavoriteModule.providesFavoriteInteractor(favoriteInteractor)
      com.github.alexpfx.udacity.beercollection.favorite.FavoriteInteractor is injected at
          com.github.alexpfx.udacity.beercollection.databaselib.search.DefaultSearchPresenter.<init>(…, arg2)
      com.github.alexpfx.udacity.beercollection.databaselib.search.DefaultSearchPresenter is injected at
          com.github.alexpfx.udacity.beercollection.dagger.SearchModule.searchPresenter(searchPresenter)
      com.github.alexpfx.udacity.beercollection.databaselib.search.SearchPresenter is injected at
          com.github.alexpfx.udacity.beercollection.ui.home.HomeFragment.searchPresenter
      com.github.alexpfx.udacity.beercollection.ui.home.HomeFragment is injected at
          com.github.alexpfx.udacity.beercollection.dagger.HomeSubComponent.inject(homeFragment)
2 errors

我无法让它显示在构建选项卡上,但对我来说没关系

【问题讨论】:

  • IIRC 应该有一些名为“日志”或类似的选项卡,您可以在其中找到完整的 gradle 输出。输出还将包括任何错误
  • 有一个事件日志选项卡,但它没有显示依赖关系图

标签: android gradle android-gradle-plugin dagger-2 gradle-plugin


【解决方案1】:

在 Build 选项卡上单击 Toggle View 可以找到 gradle 输出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 2014-11-08
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多