Follow getting started and the tutorial to the second part.
Insert this code in your Application class to enable Stetho.
public void onCreate() {
super.onCreate();
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableWebKitInspector(new LithoWebKitInspector(this))
.build());
SoLoader.init(this, false);
}
And have a build.gradle dependencies like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
// Litho
compile 'com.facebook.litho:litho-core:0.2.0'
compile 'com.facebook.litho:litho-widget:0.2.0'
provided 'com.facebook.litho:litho-annotations:0.2.0'
annotationProcessor 'com.facebook.litho:litho-processor:0.2.0'
// SoLoader
compile 'com.facebook.soloader:soloader:0.2.0'
// Optional
// For debugging
debugCompile 'com.facebook.litho:litho-stetho:0.2.0'
// For integration with Fresco
compile 'com.facebook.litho:litho-fresco:0.2.0'
}
Run Stetho and navigate to ListItemSpec.
The app crashes saying it cannot find com/facebook/litho/annotations/Prop.
The app should not crash and Stetho should show ListItemSpec.
The exception is:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.lithoexample, PID: 25176
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/litho/annotations/Prop;
at com.facebook.litho.ComponentStethoNodeDescriptor.onGetStyles(ComponentStethoNodeDescriptor.java:193)
at com.facebook.litho.ComponentStethoNodeDescriptor.onGetStyles(ComponentStethoNodeDescriptor.java:26)
at com.facebook.stetho.inspector.elements.AbstractChainedDescriptor.getStyles(AbstractChainedDescriptor.java:154)
at com.facebook.stetho.inspector.elements.Document.getElementStyles(Document.java:153)
at com.facebook.stetho.inspector.protocol.module.CSS$2$1.store(CSS.java:144)
at com.facebook.litho.ComponentStethoNodeDescriptor.onGetStyleRuleNames(ComponentStethoNodeDescriptor.java:152)
at com.facebook.litho.ComponentStethoNodeDescriptor.onGetStyleRuleNames(ComponentStethoNodeDescriptor.java:26)
at com.facebook.stetho.inspector.elements.AbstractChainedDescriptor.getStyleRuleNames(AbstractChainedDescriptor.java:145)
at com.facebook.stetho.inspector.elements.Document.getElementStyleRuleNames(Document.java:147)
at com.facebook.stetho.inspector.protocol.module.CSS$2.run(CSS.java:118)
at com.facebook.stetho.common.android.HandlerUtil$2.onRun(HandlerUtil.java:90)
at com.facebook.stetho.common.android.HandlerUtil$2.onRun(HandlerUtil.java:87)
at com.facebook.stetho.common.android.HandlerUtil$WaitableRunnable.run(HandlerUtil.java:109)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.litho.annotations.Prop" on path: DexPathList[[zip file "/data/app/com.example.user.lithoexample-2/base.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.user.lithoexample-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.user.lithoexample-2/lib/arm, /vendor/lib, /system/lib]]
...
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
I experienced the same issue.
If you want to use stetho, you need to compile the annotations in, that means you need to change
provided 'com.facebook.litho:litho-annotations:0.2.0'
to
compile 'com.facebook.litho:litho-annotations:0.2.0'
I'll try to find a good place to add this to the docs.
This is actually only needed as temporary workaround. If you build from litho master then this won't happen any longer.
We'll try to get a 0.2.1 release out soon to address this. Thanks for bringing this to our attention!
Can confirm this works when I change provided to compile with the current version of litho, 0.2.0.
I'm going to close this as it's already fixed in master. We should have the release ready later this week.
hi @passy i am using debugCompile 'com.facebook.litho:litho-stetho:0.2.1'
but when I import com.facebook.litho.stetho.LithoWebKitInspector;
its giving error "can not resolve symbol 'LithoWebKitInspector' "
Most helpful comment
This is actually only needed as temporary workaround. If you build from litho master then this won't happen any longer.
We'll try to get a
0.2.1release out soon to address this. Thanks for bringing this to our attention!