MatthiasRobbers / shortbread

Android library that creates app shortcuts from annotations
Apache License 2.0
1.78k stars 149 forks source link

Getting java.lang.ClassNotFoundException while trying to init the library #5

Closed cre8ivejp closed 7 years ago

cre8ivejp commented 7 years ago

I'm getting this exception when I call Shortbread.create(this); in my Application class. Am I missing something?

OS: 7.1 Device: Google Pixel

java.lang.ClassNotFoundException: shortbread.ShortbreadGenerated
W/System.err:     at java.lang.Class.classForName(Native Method)
W/System.err:     at java.lang.Class.forName(Class.java:400)
W/System.err:     at java.lang.Class.forName(Class.java:326)
W/System.err:     at shortbread.Shortbread.create(Shortbread.java:37)
Caused by: java.lang.ClassNotFoundException: Didn't find class "shortbread.ShortbreadGenerated"
MatthiasRobbers commented 7 years ago

The code generation did not complete. Hard to tell what the exact issue is. Did you add any Shortcut annotations yet? Can post the elements and the shortcuts so I can try to reproduce? Or even better, point me to a sample project with that I can reproduce it. Thanks!

gargas commented 7 years ago

I am also getting the same error

MatthiasRobbers commented 7 years ago

@gargas I tried to reproduce but the only state where I get the ClassNotFoundException is when I have zero @Shortcut annotations in my code. That is a bug and I will fix it but that is probably not the case here, right?

Also are you using other annotation processors that are not using the annotationProcessor notation in gradle? Are you using proguard?

gargas commented 7 years ago

I had added @Shortcut annotation in several activities. yes i am using proguard

MatthiasRobbers commented 7 years ago

Just checked again, it works with proguard.

I want to fix this but I need to reproduce it. Can you post your build.gradle by any chance? Is there anything special with your project like using an old version of the Android Gradle Plugin or something? As written before, a sample project would be the best.

dlackty commented 7 years ago

Same problem here even without proguard. Trying to figure out what happened.

AlexanderThiele commented 7 years ago

I had the same problem.

In my project we're using a different annotation processor plugin: apply plugin: 'com.neenbedankt.android-apt'

And i fixed this crash by using apt instead of annotationProcessor:

compile 'com.github.matthiasrobbers:shortbread:1.0.0' apt 'com.github.matthiasrobbers:shortbread-compiler:1.0.0'

MatthiasRobbers commented 7 years ago

Thanks, @AlexanderThiele!

So the solution is to either use the old apt as a workaround

compile 'com.github.matthiasrobbers:shortbread:1.0.0'
apt 'com.github.matthiasrobbers:shortbread-compiler:1.0.0'

or better, migrate your project to the new built-in annotationProcessor syntax. Migration guide: https://bitbucket.org/hvisser/android-apt/wiki/Migration