dagger icon indicating copy to clipboard operation
dagger copied to clipboard

NoClassDefFoundError on ObjectGraph

Open orira opened this issue 13 years ago • 8 comments

Hi

I'm getting the following java.lang.NoClassDefFoundError: dagger.ObjectGraph when my app launches

I'm just trying to get dagger implemented into my app. Ive disabled proguard as I thought this was at fault. I'm using gradle as the build system, but can't seem to get around this issue, any help would be great.

Thanks

orira avatar Nov 27 '13 21:11 orira

Show your dependencies closure from your build file. On Nov 27, 2013 1:58 PM, "Wade Reweti" [email protected] wrote:

Hi

I'm getting the following java.lang.NoClassDefFoundError: dagger.ObjectGraph when my app launches

I'm just trying to get dagger implemented into my app. Ive disabled proguard as I thought this was at fault. I'm using gradle as the build system, but can't seem to get around this issue, any help would be great.

Thanks

— Reply to this email directly or view it on GitHubhttps://github.com/square/dagger/issues/362 .

JakeWharton avatar Nov 27 '13 22:11 JakeWharton

attached below

dependencies {
    compile 'com.jakewharton:butterknife:4.0.1'
    compile 'com.squareup.dagger:dagger-compiler:1.0.1'
    compile 'com.squareup.dagger:dagger:1.0.1'
    compile files('/Users/wadereweti/Projects/dependencies/activeandroid-3.1-beta.jar')
 }

Thanks

orira avatar Nov 27 '13 22:11 orira

You need the actual dagger dependency to be available at runtime.

cgruber avatar Dec 04 '13 22:12 cgruber

thanks cgruber, but I would've thought, given it's available at compile time, it would be available at runtime.

having to write both

compile 'com.squareup.dagger:dagger-compiler:1.0.1' compile 'com.squareup.dagger:dagger:1.0.1'

runtime 'com.squareup.dagger:dagger-compiler:1.0.1' runtime 'com.squareup.dagger:dagger:1.0.1'

doesn't seem right to me

orira avatar Dec 13 '13 00:12 orira

Sorry - I"m not a gradle guy - I literally know nothing about how gradle specifies, or how its dependency scopes work. A brief examination of relevant web-pages tells me that dep configurations don't work like maven scopes, though you can simulate them. But I have no idea how without further investigation. I would check on the gradle lists, or post a stack-overflow question.

As to my earlier comment - I'm only making a statement about an environmental constraint, not about how you configure that in gradle. And I'm observing that the bytes aren't there in your run-time classpath, or you would not get a NoClassDefFound. :)

cgruber avatar Dec 13 '13 01:12 cgruber

yep right you are, thanks man.

orira avatar Dec 13 '13 02:12 orira

You can see some Gradle solutions in #325. Placing both artifacts in the compile scope should absolutely work. Are you sure something else like ProGuard isn't affecting the classes? Also, are you doing a clean build from the command line or just in the IDE. The IDE isn't going to pick up the dependencies unless you refresh its model (in the Gradle pane) and even sometimes then it may not include them. You'll want to go to "Build" > "Rebuild Project" to do a clean build after click the aforementioned "Refresh" button.

JakeWharton avatar Dec 17 '13 16:12 JakeWharton

I started getting this with Android Studio 0.9.0 and build tools 21.1.0. I had compile for dagger and dagger-compiler before, which was working well. After the update, setting dagger-compiler to apt fixed the problem.

felipecsl avatar Nov 03 '14 17:11 felipecsl