Не удается найти класс символов DataBindingComponent, вызванный java.util.NoSuchElementException - PullRequest
0 голосов
/ 27 октября 2018

У меня есть проект, в котором я использую версию кинжала 2.18 (implementation "com.google.dagger:dagger:2.18") в Android Studio 3.3 Beta 1, но когда я его запускаю, он выходит из строя с ошибкой ниже

e/../../databinding/ActivityHomeBinding.java:46: error: cannot find symbol
      @Nullable DataBindingComponent component) {
                ^
  symbol:   class DataBindingComponent
  location: class ActivityHomeBinding
i: Note: [1] Wrote GeneratedAppGlideModule with: []
e: [kapt] An exception occurred: java.util.NoSuchElementException
        at com.sun.tools.javac.util.List$2.next(List.java:432)
        at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:302)
        at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:254)
        at dagger.android.processor.AndroidMapKeys.mapKeyValue(AndroidMapKeys.java:75)
        at dagger.android.processor.AndroidMapKeys.lambda$annotationsAndFrameworkTypes$5(AndroidMapKeys.java:56)
        at java.util.stream.Collectors.lambda$toMap$58(Collectors.java:1321)
        at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
        at java.util.stream.Streams$StreamBuilderImpl.forEachRemaining(Streams.java:419)

Toрешить проблему, я попытался

What went wrong: Execution failed for task ':app:kaptGenerateStubsDebugKotlin'. Could not resolve all files for configuration ':app:kapt'. Failed to transform file 'jetifier-core-1.0.0-alpha10.jar' to match attributes {artifactType=processed-jar} using transform JetifyTransform Failed to transform '/home/s/.gradle/caches/modules-2/files-2.1/com.android.tools.build.jetifier/jetifier-core/1.0.0-alpha10/9eb7027c383061de12f93aae7a22cbeb97832d2a/jetifier-core-1.0.0-alpha10.jar' using Jetifier. Reason: The given artifact contains a string literal with a package reference 'android/support/v4' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.. (Run with --stacktrace for more details.) To disable Jetifier, set android.enableJetifier=false in your gradle.properties file.

  • Использование версии кинжала 2.16, которая все еще не работает со странными ошибками

    e: /home/s/G/app/src/main/java/com/edijae/crusar/sample/di/modules/ApiModule.kt: (11, 16): Unresolved reference: logging
    e: /home/s/G/app/src/main/java/com/edijae/crusar/sample/di/modules/ApiModule.kt: (40, 40): Unresolved reference: HttpLoggingInterceptor
    e: /home/s/G/app/src/main/java/com/edijae/crusar/sample/di/modules/ApiModule.kt: (41, 35): Unresolved reference: HttpLoggingInterceptor
    

Тем не менее, когда я перехожу к ApiModule.kt, ошибки нет.То есть import okhttp3.logging.HttpLoggingInterceptor не выделено красным цветом, и я могу перейти к этому классу.

Ниже мой основной build.gradle

 buildscript {
        ext.kotlin_version = '1.2.71'
        ext.realmVersion ='5.4.2'
        repositories {
            google()
            jcenter()
            maven {
                url "https://maven.google.com"
            }
            maven { url "https://jitpack.io" }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.4.0-alpha02'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath "io.realm:realm-gradle-plugin:$realmVersion"

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

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

    /**
     * Configure common tasks on all the submodules
     */
    allprojects { project ->

        // Get versions, this is where we store things
        // like the list of submodules or the version
        project.apply from: "$rootDir/versions.gradle"

        gradle.projectsEvaluated {
            tasks.withType(JavaCompile.class) {
                options.compilerArgs << "-Xmaxerrs" << "10000"
            }
        }
        afterEvaluate {
            if (project.plugins.hasPlugin("kotlin-kapt")) {
                kapt {
                    javacOptions {
                        option("-Xmaxerrs", 10000)
                    }
                }
            }
        }
    }
    task clean(type: Delete) {
        delete rootProject.buildDir
    }  

Ниже build.gradle* 1036 моего приложения*

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'maven'
apply plugin: 'realm-android'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dataBinding {
        enabled true
    }
        compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}


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

    //kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    //glide
    kapt "com.github.bumptech.glide:compiler:4.8.0"
    implementation "com.github.bumptech.glide:glide:4.8.0"

    //dagger
    implementation "com.google.dagger:dagger:2.18"
    kapt "com.google.dagger:dagger-compiler:2.18"
    implementation "com.google.dagger:dagger-android:2.18"
    implementation "com.google.dagger:dagger-android-support:2.18"

    // if you use the support libraries
    kapt "com.google.dagger:dagger-android-processor:2.18"

    //retrofit
    implementation "com.squareup.retrofit2:retrofit:2.4.0"
    implementation "com.squareup.retrofit2:converter-gson:2.4.0"
    implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"
    debugImplementation "com.squareup.okhttp3:logging-interceptor:3.8.0"


     testImplementation 'junit:junit:4.12'
     androidTestImplementation "androidx.test:runner:1.0.0"
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'

     }

Ответы [ 2 ]

0 голосов
/ 30 октября 2018

Мне удалось устранить ошибку путем

  • , изменив debugImplementation "com.squareup.okhttp3:logging-interceptor:3.8.0" на implementation "com.squareup.okhttp3:logging-interceptor:3.8.0".Это решило ошибку Unresolved reference: HttpLoggingInterceptor.

  • Добавление процессора-выпрямителя в мой основной build.gradle

    classpath 'com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta02'

  • Добавление ядра jentifier в мой app's build.gradle

    kapt 'com.android.tools.build.jetifier:jetifier-core:1.0.0-beta02' annotationProcessor 'com.android.tools.build.jetifier:jetifier-core:1.0.0-beta02'

основной уровень build.gradle

buildscript {
    ext.kotlin_version = '1.3.0'
    ext.realmVersion ='5.4.2'
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0-alpha02'
        classpath 'com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta02'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

build.gradle приложения

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'maven'
apply plugin: 'realm-android'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dataBinding {
        enabled true
    }
        compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}


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

    kapt 'com.android.tools.build.jetifier:jetifier-core:1.0.0-beta02'
    annotationProcessor 'com.android.tools.build.jetifier:jetifier-core:1.0.0-beta02'

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    kapt "com.github.bumptech.glide:compiler:4.8.0"
    implementation "com.github.bumptech.glide:glide:4.8.0"

    implementation "com.google.dagger:dagger:2.18"
    kapt "com.google.dagger:dagger-compiler:2.18"
    implementation "com.google.dagger:dagger-android:2.18"
    implementation "com.google.dagger:dagger-android-support:2.18"

    // if you use the support libraries
    kapt "com.google.dagger:dagger-android-processor:2.18"

    implementation "com.squareup.retrofit2:retrofit:2.4.0"
    implementation "com.squareup.retrofit2:converter-gson:2.4.0"
    implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"
    implementation "com.squareup.okhttp3:logging-interceptor:3.8.0"


     testImplementation 'junit:junit:4.12'
     androidTestImplementation "androidx.test:runner:1.0.0"
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'

     }
0 голосов
/ 27 октября 2018

У меня возникла та же проблема
оказалось, что эта ошибка связана с ошибкой Jetifier
см .:
https://github.com/google/dagger/issues/1245
https://issuetracker.google.com/issues/115738511

решение : пока держите кинжал 2.16

implementation "com.google.dagger:dagger-android:2.16"  
implementation "com.google.dagger:dagger-android-support:2.16"  
kapt "com.google.dagger:dagger-compiler:2.16"  
kapt "com.google.dagger:dagger-android-processor:2.16"  
...