I'm unable to find a solution to bring an Android Studio
Library with Dagger 2
to run.
I will explain what happened:
- I have a running Android Studio Project that using
Dagger 2
- I have created a module from the app (bevor I used refactor for renaming) from this Project
- In another Project I have imported this module as a new module
- In fact: Now I have a Project with 3 library modules and my app (application) module
- I try to build and get this error
Errors:
Error:(7, 46) error: cannot find symbol class DaggerApplicationComponent
Error:(8, 46) error: cannot find symbol class DaggerHomeActivityComponent
Error:(21, 46) error: cannot find symbol class DaggerProfileComponent
Error:(27, 46) error: cannot find symbol class DaggerSearchComponent
Error:(27, 46) error: cannot find symbol class DaggerShareFeedComponent
Error:(312, 19) error: element value must be a constant expression
Error:(314, 19) error: element value must be a constant expression
.
.
.
and so on... This is the java file snippet with red underlined:
import android.app.Application;
import android.content.Context;
import com.aroniez.materialsnap.di.components.ApplicationComponent;
import com.aroniez.materialsnap.di.components.DaggerApplicationComponent;
import com.aroniez.materialsnap.di.modules.ApplicationModule;
import net.danlew.android.joda.JodaTimeAndroid;
Here is my build.gradle from the module (Please note, there is a line apply plugin: 'com.android.library' not apply plugin: 'com.android.application'):
apply plugin: 'com.android.library'
apply plugin: 'com.neenbedankt.android-apt'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
// applicationId "com.aroniez.materialsnap"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
renderscriptTargetApi 20
renderscriptSupportModeEnabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
//google libraries
//compile 'com.android.support:support-v4:23.1.1'
//square libraries
compile('com.squareup.retrofit2:retrofit:2.0.0-beta4') {
exclude module: 'okhttp'
}
//dagger for DI
apt 'com.google.dagger:dagger-compiler:2.0.2'
provided 'javax.annotation:jsr250-api:1.0'
//provided 'org.glassfish:javax.annotation:10.0-b28'
//library for fonts
//compile 'uk.co.chrisjenx:calligraphy:2.1.0'
//for testing
debugCompile('org.mockito:mockito-core:1.10.19') {
exclude group: 'org.hamcrest'
}
debugCompile('com.google.dexmaker:dexmaker:1.2') {
exclude group: 'org.hamcrest'
}
debugCompile('com.google.dexmaker:dexmaker-mockito:1.2') {
exclude group: 'org.hamcrest'
}
debugCompile 'commons-io:commons-io:2.4'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.0') {
exclude group: 'javax.inject'
}
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.0') {
exclude group: 'javax.inject'
exclude group: 'com.android.support'
}
compile 'com.android.support:palette-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
compile 'com.colintmiller:simplenosql:0.5.1'
compile 'com.pkmmte.view:circularimageview:1.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.google.dagger:dagger:2.0.2'
compile 'io.reactivex:rxandroid:1.1.0'
compile 'me.iwf.photopicker:PhotoPicker:0.2.8@aar'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
compile 'jp.wasabeef:glide-transformations:1.3.1'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
compile 'net.danlew:android.joda:2.9.2'
compile 'com.github.danylovolokh:hashtag-helper:1.1.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
}
This is the build.cradle from the project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven{
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
It seems Dagger 2
will not work when I set the plugin from "application" to "library" in the module build.gradle
I have tried a lot of things. But I am unable to solve it.
So, is there anybody outside with some experience to help a little bit? If yes, please try to explain to me what´s wrong (i am not a specialist with a dagger). It would be very nice if the problem could be solved!