Error: Unresolved reference: DaggerAppComponent [duplicate] - android

This question already has answers here:
Unresolved reference DaggerApplicationComponent
(16 answers)
Closed 4 years ago.
I've been facing this problem for 3 hours. I couldn't find any logical reason to what is happening. The problem is, Only when I use the generated Dagger classes, and after Gradle do the Build every reference to these classes became red and I get the error:
Error: Unresolved reference: DaggerAppComponent
But, If I comment out every line in the App class reference any of these generated Dagger classes. The build process completed successfully. I tried doing clean/ rebuild/ make project. but it doesn't work.
Some information about my environment:
Build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "xxxxx"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "android.arch.lifecycle:extensions:1.1.0"
implementation "android.arch.lifecycle:viewmodel:1.1.0"
implementation "android.arch.lifecycle:livedata:1.1.0"
implementation "android.arch.persistence.room:runtime:1.0.0"
implementation "android.arch.lifecycle:runtime:1.1.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
kapt "android.arch.lifecycle:compiler:1.1.0"
kapt "android.arch.persistence.room:compiler:1.0.0"
kapt "com.google.dagger:dagger-compiler:2.8"
compile "com.google.dagger:dagger:2.8"
compile "com.google.dagger:dagger-android:2.8"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Kotlin version: ext.kotlin_version = '1.1.51'
Android Studio version: 3.0.1
dependencies section in Build.Gradle file for the project (not the app module):
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
App class:
class App:Application() {
private val component:AppComponent by lazy {
DaggerAppComponent.builder()
.build()
}
override fun onCreate() {
super.onCreate()
component.inject(this)
}
}
If anyone can figure out what is the problem, it would be much appreciated.
P.S. I'm still learning Dagger2 and I'm new to Kotlin and Native development in general. I came from C# and Xamarin background.

You seem to be missing the application of the kapt Gradle plugin, as described in the kapt documentation. Basically, add this after your existing plugins:
apply plugin: 'kotlin-kapt'
(If this helps, this question should be marked as a duplicate of this one)

Related

Shows Please make sure you have the required dependencies in the classpath: class com.google.android.gms.vision.barcode.Barcode

Everything was working fine until I added implementation 'com.google.android.gms:play-services-ads:18.2.0' this dependency for showing ads in-app.
I am getting below error message while building the application. error gets removed if I remove ad library.
Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class com.google.android.gms.vision.barcode.Barcode, unresolved supertypes: com.google.android.gms.internal.zzbck
App level build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.creatorisone.chargingtheftsecurityalarm"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.04"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), "proguard-rules.pro"
}
}
configurations {
cleanedAnnotations
compile.exclude group: 'org.jetbrains', module: 'annotations'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'org.jetbrains:annotations-java5:17.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50"
implementation 'xyz.belvi.mobilevision:barcodescanner:2.0.3'
implementation 'androidx.fragment:fragment:1.2.0-alpha02'
implementation 'com.google.zxing:core:3.3.3'
implementation 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
implementation 'com.google.android.gms:play-services-ads:18.2.0'
}
repositories {
mavenCentral()
}
I have tried multiple solutions provided on StackOverflow but nothing is working in my case
"Error: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath"
error in Location Request class in android with kotlin
error: supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath
"Supertypes of the following classes cannot be resolved.” in Task:app:buildInfoGeneratorDebug
I have faced same problem and its resolve by adding
implementation 'com.google.android.gms:play-services-vision:15.0.2'

Failing on build with androidX error but I am not using androidX in project

I am trying to build but it gives me errors. I did research and tried following solutions but cant fix.
https://github.com/objectbox/objectbox-java/issues/386
Unable to merge dex
Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)
Error: Program type already present: androidx.versionedparcelable.ParcelImpl
Thats the error
Error: Program type already present: androidx.versionedparcelable.NonParcelField
Thats the screen
Thats my code
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.30"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and this one
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.adultgaming.fantasygameapp"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:multidex:1.0.3'
//Kotlin
implementation "androidx.core:core-ktx:1.0.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.30"
//Glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
//Eventbus
implementation 'org.greenrobot:eventbus:3.1.1'
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'
}
Please let me know if I missed something. And if want to devote let me know why.
First, check inside your gradle.properties, if you have
android.enableJetifier=true
android.useAndroidX=true
Then you do have androidx enabled.
Also, and this may be obvious, but clean your Gradle build with Build -> Clean Project
UPDATE WITH ANSWER
What is happening is one of your other libraries is using androidx, GLIDE FOR SURE, and maybe others.
You have two options...
Easy: Upgrade to androidx... Like why not? Totally worth it.
Hard: Downgrade your dependencies versions to pre androidX versions.

How to solve 'Unresolved reference: arch' from "import android.arch.lifecycle"?

In a Kotlin file, I have an 'Unresolved reference: arch'.
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.OnLifecycleEvent
I have no experience in programming but I wanted to get started and learn by doing.
I am trying to replicate an Android app from this article:
https://heartbeat.fritz.ai/creating-an-android-app-with-snapchat-style-filters-in-7-steps-using-firebases-ml-kit-e79946e99688
I have Android Studio 3.3, Kotlin compiler 1.3 and Gradle 4.10.1.
I have read several threads with similar problems and I have tried:
1) Clean, Rebuild, Sync with Gradle
2) Restart computer
3) Invalidate caches and restart AS
4) Delete .idea and restart the project
5) Look for any discrepancies in plugins but to my best of knowledge I have not found them, everything is in the latest stable version.
My project build.gradle:
buildscript {
ext.kotlin_version = '1.3.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
My app build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.zqc.ml.nautilus"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-ml-vision:18.0.2'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'com.otaliastudios:cameraview:1.5.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.core:core-ktx:1.1.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
apply plugin: 'com.google.gms.google-services'
It should run properly but instead build is failed
Execution failed for task ':app:compileDebugKotlin'.
Log points to this 'Unresolved reference: arch' and nothing else.
You're using androidx artifacts, therefore the classes that used to be in android.arch.lifecycle are now in androidx.lifecycle as per the Migrating to AndroidX documentation.

Cannot find symbol ViewModel with Dagger 2

I'm creating a new Android project and I adding Dagger 2, but it fails with an error related to androidx libraries.
After using a template from within Android Studio, I've added a few lines, kotlin-kapt, and the dependencies for Dagger 2.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.xxxx.yyyy"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
androidExtensions {
experimental = true
}
kapt {
generateStubs = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'com.google.android.material:material:1.0.0-alpha1'
// Image Loading
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
// Dagger
implementation 'com.google.dagger:dagger-android:2.15'
kapt 'com.google.dagger:dagger-android-processor:2.15'
// RxJava
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.3'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
// Navigation
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha01'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-alpha01'
// Pretty Logger
implementation 'com.orhanobut:logger:1.15'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha1'
}
When trying to build the application, it fails with the following errors.
error: cannot find symbol
public final class MainActivityViewModel extends android.arch.lifecycle.ViewModel {
^
symbol: class ViewModel
location: package android.arch.lifecycle
error: cannot find symbol
private final androidx.lifecycle.MediatorLiveData
^
symbol: class MediatorLiveData
location: package androidx.lifecycle
error: cannot find symbol
private androidx.navigation.NavController navController;
^
symbol: class NavController
location: package androidx.navigation
...
I've tried with androidx libraries, and the older libraries but both fail. If I removed the Dagger 2 dependencies it will build and run fine.
I'm currently using Android Studio 3.2 Canary 17.
Any idea what's going wrong?
Thanks.
Go to Settings -> Build, Execution, Deployment -> Compiler,
uncheck the 'Configure on demand' option if set.
Also make sure you are using latest gradle and Android Gradle plugin
I managed to track down the cause of the issue, it wasn't related to the build.gradle itself but the version of Java I was using.
Within Android Studios I have changed the JDK to use Java 10.
However, changing this setting back to using the embedded JDK has made the application compile successful.

Execution failed for task ':app:kaptGenerateStubsDebugKotlin' after android studio V3.1.1 update

I just updated android studio to V3.1.1. Then my program went wrong.
When build the program,there are two errors:
One in 'Run build':
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kaptGenerateStubsDebugKotlin'
Another in Java compiler:
java.lang.ClassNotFoundException: org.jetbrains.kotlin.resolve.checkers.SimpleDeclarationChecker
Here is my gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.restress.saniauto"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
buildToolsVersion '27.0.3'
}
androidExtensions {
experimental = true
}
buildscript {
ext.kotlin_version = '1.2.21'
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.22.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//RxJava
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.8'
implementation 'io.reactivex:rxkotlin:0.55.0'
//Room & RxAndroid2
implementation "android.arch.persistence.room:runtime:$room_version"
implementation "android.arch.persistence.room:rxjava2:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation "android.arch.persistence.room:testing:$room_version"
//Design
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:percent:26.1.0'
}
Well,I finally get over this.
When I use --stacktrace,I find the :app:kaptDebugKotlin is a procedure in BUILDING an android program.
--stacktrace result picture
And I get the error java.lang.ClassNotFoundException: org.jetbrains.kotlin.resolve.checkers.SimpleDeclarationChecker in this :app:kaptDebugKotlin procedure.
I doubt that there're something new in kotlin implementation,so I update my kotlin_version from 1.2.21 to 1.2.30.
Then I get more clear errors.That is the room parameters errors.
room error
So I change the arg0 to the parameter name in Dao functions in SQL query.
Finally it works.
I was working on the test project. Using dagger with Kotlin and this task failing was a blocker.
I tried many ways but the error message was not meaningful, the very next day I Start copying classes to a new project and found that issue is due to dagger and also convert Moshi annotation #JsonClass(generateAdapter = true) java class into Kotlin.
MoviesViewModel #Inject constructor(private val movieService: MovieService): ViewModel()
then :)
I had the same error and solved by updating the kotlin to the latest version (1.5.31) in my project build.gradle:
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
}
}
For people trying to use Jetpack Compose running into this error.
For me I was missing the composeOptions{...} block so I added it as shown below and the error is resolved now.
buildFeatures {
compose = true
viewBinding = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.0.1"
kotlinCompilerVersion = "1.5.21" // Make sure this version is same as your Kotlin version
}

Categories

Resources