根据官方文档
- gradle导入(准备工作)
// 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'
// For testing
// testCompile 'com.facebook.litho:litho-testing:0.2.0'
PS:
Android Support需要更新到25.3.1
testCompile 'com.facebook.litho:litho-testing:0.2.0'导入的时候会报
Error:Conflict with dependency 'com.google.code.findbugs:jsr305' in project ':app'. Resolved versions for app (2.0.1) and test app (3.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
参见
在APP层级下的build.gradle中增加
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
//resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1'
}
- 初始化SoLoader
首先,初始化SoLoader。Litho依赖于SoLoader来帮助由底层布局引擎Yoga提供的库。
在Application中初始化就可以了
SoLoader.init(this, false);
- 运行
之后在Activity中加入预定义的Litho Text控件
final ComponentContext c = new ComponentContext(this);
final LithoView lithoView = LithoView.create(
this /* context */,
Text.create(c)
.text("Hello, World!")
.textSizeDip(50)
.build());
setContentView(lithoView);