Use ExtrasBinder for library project
Opened this issue ยท 21 comments
Inside my ViewPagerFragment
, which extends support.v4.app.Fragment
, while invoking ExtrasBinder.bind(this);
, I am getting the following err:
java.lang.ClassNotFoundException: com.accenture.android.test.fragment.ViewPagerFragment$$ExtraBinder
What can cause this problem?
My first guess would be that you've forgotten to add the @Extra
annotation to your member variables. If so, then that's why the $$ExtraBinder
was never generated for your ViewPagerFragment
class.
That is unless I've overlooked something important while reading the source code. If my guess doesn't solve your problem then @TheFinestArtist will likely be able to give us the correct answer.
Nope, @Extra
annotation was added.
@ugurcany Thanks for reporting an issue! I will take a look and try to regenerate the bug!
@ugurcany I just found out why! I think your ExtraBinder
class is proguarded. Therefore, the ExtraBinder wouldn't be able to find the class for you!
Check if your ExtraBinder
class is created after you build your app! If it does, I am pretty sure that java.lang.ClassNotFoundException
caused by the proguard. Please add following proguard option to keep ExtraBinder
class to be proguarded.
-keep class com.thefinestartist.annotations.** { *; }
-keep class **$$ExtraBinder { *; }
-keepclasseswithmembernames class * {
@com.thefinestartist.annotations.Extra <fields>;
}
Let me know if you have any more issues or questions!
Proguard is not enabled for my project. I am having these lines in my proguard rules file anyway.
@ugurcany Can you share me part of your code so that I can regenerate the error?
Is your com.accenture.android.test.fragment.ViewPagerFragment$$ExtraBinder
class created?
Here is my ViewPagerFragment
class:
public class ViewPagerFragment extends Fragment {
@Extra("TEXT")
String text;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_viewpager, container, false);
ButterKnife.bind(this, rootView);
ExtrasBinder.bind(this);
acn_textview.setText(text);
return rootView;
}
@Bind(R.id.acn_textview)
AcnTextView acn_textview;
}
And here is the error in more details:
Caused by: java.lang.ClassNotFoundException: Didn't find class "acn.android.test.fragment.ViewPagerFragment$$ExtraBinder" on path: DexPathList[[zip file "/data/app/acn.android.test-1/base.apk"],nativeLibraryDirectories=[/data/app/acn.android.test-1/lib/x86, /vendor/lib, /system/lib]]
I checked under my build
folder. ViewPagerFragment$$ExtraBinder
is not created. What should I do to fix this?
Honestly, I couldn't really regenerate your issue. I added Butterknife
in my sample app and copied your class and for me ExtraBinder
worked fine. Seems like you are using Butterknife
. I have few more question.
- There is two kinds of dependencies for
Butterknife
. Are you usingcompile 'com.jakewharton:butterknife:7.0.1'
? - Have you added
apt 'com.thefinestartist:compilers:0.8.5'
in your dependencies?- If you haven't, the compiler won't generate any
ExtraBinder
class in build time!
- If you haven't, the compiler won't generate any
- Maybe your device API version?
- It would be really helpful if you share me any project that keep causing this error!
I really thanks for your contribution for the library!
- Yes, I am using
compile 'com.jakewharton:butterknife:7.0.1'
. - Yes,
apt 'com.thefinestartist:compilers:0.8.5'
andapply plugin: 'com.neenbedankt.android-apt'
are added to module-level gradle file. Andclasspath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
is added to project-level gradle file. - My device API ver is 21.
Oh Okay, I think I really need any sample app that causes this ClassNotFoundException
.
Here it is: https://github.com/ugurcany/ACN-Android-Framework
test
module contains the ViewPagerFragment
class that I shared.
@ugurcany Thanks so much! I think the annotation processor doesn't work properly if it is added in other than main module! I will take a look on this!
@ugurcany Seems like it work fine if apply plugin: 'com.neenbedankt.android-apt'
is added in main project module. With APT plugin, I think the android processor work fine.
I will still looking for way to use ExtraBinder
without adding apply plugin: 'com.neenbedankt.android-apt'
line in your main project module.
Thank you for the solution. I will try.
Could you please let me know when it is possible to solve the problem without a need to apply the plugin to main module?
@ugurcany I tried to understand Android annotation deeply, I think I need to understand how Butterknife
is working for such case. I can't really say when would I be able to add this, I will do ASAP! Let me try this for this weekend and I will let you know how much it would take!
@ugurcany I think this might take longer than I thought! Sorry about this~
Have you found any solution?
@ugurcany Not much I was busy with updating other apps. Do you have any idea for this?
Nope. Sorry.