androidandroid-studiogradlebuild.gradledragger

java.lang.NoClassDefFoundError: dagger/Provides


When I try to build project I get this dragger exception. I need help to resolve this issue. I searched on the site and found some similar issues. I tried solutions

  1. Invalidate internal cache and restart.
  2. delete .gradle folder and rebuild project

But nothing worked for me. Here is the build.gradle file code

apply plugin: 'com.android.application'

android {

    compileSdkVersion 27
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.firstup.android"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 10
        versionName "1.0.4"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            signingConfig signingConfigs.debug
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.0.0'
    implementation 'com.android.support:support-v4:27.0.0'
    implementation 'com.android.support:recyclerview-v7:27.0.0'
    implementation('com.android.support:design:27.0.2'){
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'recyclerview-v7'
    }
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

    implementation('com.google.android.gms:play-services-auth:11.4.2'){
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.google.android.gms', module: 'play-services-base'
    }

    implementation('com.google.android.gms:play-services-base:11.4.2'){
        exclude group: 'com.android.support', module: 'support-v4'
    }
//    implementation 'com.google.android.gms:play-services-gcm:11.4.2'

//     ExoPlayer
    implementation 'com.google.android.exoplayer:exoplayer:r2.4.4'

    // Mixpanel
    implementation 'com.mixpanel.android:mixpanel-android:4.9.8'

    // SwipeLayout
    implementation 'com.github.rambler-digital-solutions:swipe-layout-android:1.0.14'

    // ViewPagerIndicator
    implementation 'me.relex:circleindicator:1.2.2@aar'

    // ButterKnife
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

    // Dagger 2
    implementation 'com.google.dagger:dagger:2.12'
    annotationProcessor('com.google.dagger:dagger-compiler:2.12'){
        exclude group: 'com.google.dagger', module: 'dagger'
    }
    //MaterialPicker
    implementation 'com.wdullaer:materialdatetimepicker:3.1.2'
    implementation('com.wdullaer:materialdatetimepicker:3.1.2'){
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'design'
        exclude group: 'com.android.support', module: 'recyclerview-v7'
    }

    // RxAndroid
    implementation 'io.reactivex:rxjava:1.2.0'
    implementation('io.reactivex:rxandroid:1.2.1'){
        exclude group: 'io.reactivex', module: 'rxjava'
    }

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation('com.squareup.retrofit2:adapter-rxjava:2.0.2'){
        exclude group: 'com.squareup.retrofit2', module: 'retrofit'
    }
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation('com.squareup.retrofit2:converter-gson:2.3.0'){
        exclude group: 'com.squareup.retrofit2', module: 'retrofit'
        exclude group: 'com.google.code.gson', module: 'gson'
    }
    implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'
    implementation('com.squareup.retrofit2:converter-simplexml:2.3.0'){
        exclude group: 'com.squareup.retrofit2', module: 'retrofit'
    }

    // Gson
    implementation 'com.google.code.gson:gson:2.8.0'

    // Facebook
    implementation 'com.facebook.android:facebook-android-sdk:4.19.0'
    implementation('com.facebook.android:facebook-android-sdk:4.19.0'){
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'customtabs'
    }

    // Glide
    implementation 'com.github.bumptech.glide:glide:4.3.0'

    implementation 'com.android.support:customtabs:27.0.0'

    implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
    implementation('uk.co.chrisjenx:calligraphy:2.3.0'){
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'junit', module: 'junit'
    })
    testCompile 'junit:junit:4.12'
}

stack trace

Information:Gradle tasks [clean, :app:assembleDebug]
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\alarm\alarm_clock\AlarmActivity.java
Error:(11, 61) error: cannot find symbol class DaggerAlarmActivityComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\base\BaseActivity.java
Error:(13, 55) error: cannot find symbol class DaggerBaseActivityComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\alarm\alarm_clock\AlarmChallengeFragment.java
Error:(12, 61) error: cannot find symbol class DaggerAlarmFragmentComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\alarm\alarm_clock\AlarmClockFragment.java
Error:(11, 61) error: cannot find symbol class DaggerAlarmFragmentComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\alarm\alarm_list\AlarmListFragment.java
Error:(15, 60) error: cannot find symbol class DaggerAlarmListComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\alarm\set_up_alarm\AddAlarmFragment.java
Error:(14, 62) error: cannot find symbol class DaggerIAddAlarmComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\application\FirstUpApplication.java
Error:(12, 55) error: cannot find symbol class DaggerAppComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\auth\AuthActivity.java
Error:(13, 57) error: cannot find symbol class DaggerAuthActivityComponent
Error:(16, 57) error: cannot find symbol class DaggerAuthComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\auth\change_password\ChangePasswordFragment.java
Error:(10, 64) error: cannot find symbol class DaggerIChangePasswordComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\brands\BrandFragment.java
Error:(17, 50) error: cannot find symbol class DaggerBrandComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\brands\CommonScreenActivity.java
Error:(13, 50) error: cannot find symbol class DaggerIBrandActivityComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\campaigns\campaign_item\CampaignFragment.java
Error:(20, 67) error: cannot find symbol class DaggerICampaignComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\campaigns\finished\FinishedCampaignsFragment.java
Error:(14, 62) error: cannot find symbol class DaggerFinishedCampaignsComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\campaigns\pager\CampaignPagerFragment.java
Error:(16, 59) error: cannot find symbol class DaggerICampaignPagerComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\main\MainActivity.java
Error:(24, 48) error: cannot find symbol class DaggerMainActivityComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\main\home\HomeFragment.java
Error:(31, 53) error: cannot find symbol class DaggerHomeComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\main\settings\user_settings\change_email\ChangeEmailFragment.java
Error:(11, 84) error: cannot find symbol class DaggerIChangeEmailComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\main\settings\user_settings\UserSettingsFragment.java
Error:(15, 71) error: cannot find symbol class DaggerIUserSettingComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\main\vibes\VibesFragment.java
Error:(18, 54) error: cannot find symbol class DaggerVibesComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\news\NewsFragment.java
Error:(19, 48) error: cannot find symbol class DaggerNewsComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\onboarding\OnboardingInfoFragment.java
Error:(17, 54) error: cannot find symbol class DaggerOnboardingComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\settings\alarm_settings\AlarmSettingsFragment.java
Error:(24, 67) error: cannot find symbol class DaggerAlarmSettingsComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\settings\settings_activity\SettingsActivity.java
Error:(23, 70) error: cannot find symbol class DaggerSettingsActivityComponent
F:\FirstUP_android-develop\app\src\main\java\com\firstup\android\presentation\well_done\WellDoneFragment.java
Error:(27, 53) error: cannot find symbol class DaggerWellDoneComponent
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.NoClassDefFoundError: dagger/Provides
Information:BUILD FAILED in 1m 3s
Information:26 errors
Information:0 warnings
Information:See complete output in console

Adding AppComponent code for Error:(11, 61) error: cannot find symbol class DaggerAlarmActivityComponent

package com.firstup.android.presentation.alarm.alarm_clock.di;

import com.firstup.android.presentation.alarm.alarm_clock.AlarmActivity;
import com.firstup.android.presentation.application.di.AppComponent;
import com.firstup.android.presentation.application.di.BaseActivityModule;
import com.firstup.android.presentation.application.di.PerActivity;

import dagger.Component;

/**
 * Created by
 * rMozes on 2/27/17.
 */
@PerActivity
@Component(dependencies = AppComponent.class, modules = BaseActivityModule.class)
public interface AlarmActivityComponent {
    void inject(AlarmActivity _activity);
}



package com.firstup.android.presentation.alarm.alarm_clock;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Window;
import android.view.WindowManager;

import com.firstup.android.R;
import com.firstup.android.global.Constants;
import com.firstup.android.presentation.alarm.alarm_clock.di.DaggerAlarmActivityComponent;
import com.firstup.android.presentation.application.FirstUpApplication;
import com.firstup.android.presentation.application.di.BaseActivityModule;
import com.firstup.android.presentation.base.BaseActivity;
import com.firstup.android.presentation.base.BaseFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import ru.rambler.libs.swipe_layout.SwipeLayout;

/**
 * Created by
 * rMozes on 2/26/17.
 */

public class AlarmActivity extends BaseActivity {

    @BindView(R.id.swipeLayout_AAC) SwipeLayout mSwipeLayout;

    private BaseFragment mFragment;

    public static Intent getCallingIntent(String _type) {
        Intent intent = new Intent(FirstUpApplication.getInstance(), AlarmActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Constants.Preferences.SP_ALARM_TYPE, _type);
        return intent;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm_clock);
        ButterKnife.bind(this);
        initialize();

        disableLock();

        DaggerAlarmActivityComponent.builder()
                .appComponent(FirstUpApplication.getInstance().getAppComponent())
                .baseActivityModule(new BaseActivityModule(this))
                .build()
                .inject(this);

        if (savedInstanceState == null)
            initialize();
    }

    private void initialize() {
//        switch (getIntent().getStringExtra(Constants.Preferences.SP_ALARM_TYPE)) {
        switch (mSPUtils.getAlarmType()) {
            case Constants.Preferences.SP_ALARM_TYPE_CHALLENGE:
                initializeChallenge();
                break;
            case Constants.Preferences.SP_ALARM_TYPE_SWIPE:
                initializeSwipe();
                break;
        }
    }

    private void initializeChallenge() {
        mSwipeLayout.setSwipeEnabled(false);

        getFragmentNavigator()
                .replaceFragmentWithoutBackStack(AlarmChallengeFragment.newInstance());
    }

    private void initializeSwipe() {
        mSwipeLayout.setSwipeEnabled(true);
        mSwipeLayout.setOnSwipeListener(mListener);
        mFragment = AlarmClockFragment.newInstance();

        getFragmentNavigator().replaceFragmentWithoutBackStack(mFragment);
    }

    private void onSwipe() {
        ((AlarmContract.View) mFragment).onSwipe();
    }

    private void disableLock() {
        Window window = this.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    }

    @Override
    public int getContainerId() {
        return R.id.flContainer_AAC;
    }

    @Override
    public int getToolbarId() {
        return -1;
    }

    private SwipeLayout.OnSwipeListener mListener = new SwipeLayout.OnSwipeListener() {
        @Override
        public void onBeginSwipe(SwipeLayout swipeLayout, boolean moveToRight) {}

        @Override
        public void onSwipeClampReached(SwipeLayout swipeLayout, boolean moveToRight) {
            onSwipe();
        }

        @Override
        public void onLeftStickyEdge(SwipeLayout swipeLayout, boolean moveToRight) {}

        @Override
        public void onRightStickyEdge(SwipeLayout swipeLayout, boolean moveToRight) {}
    };
}

Solution

  • Don't exclude anything from dagger-compiler in your build.gradle, add it like this as stated in Dagger doc

    dependencies {
      compile 'com.google.dagger:dagger:2.x'
      annotationProcessor 'com.google.dagger:dagger-compiler:2.x'
    }