XAdapter 是一个对 Android RecyclerView Adapter 的轻量级封装库,基于kotlin特性,可以做到
。
1. 添加 JitPack 仓库
Gradle 7+(settings.gradle / settings.gradle.kts )
在 dependencyResolutionManagement { repositories { ... } } 中增加:
Groovy
maven { url 'https://jitpack.io' }
Kotlin DSL
maven { url = uri("https://jitpack.io") }
2. 添加依赖(坐标以 JitPack 页面为准)
- 打开 JitPack - XAdapter
- 选择一个 已构建成功的 Git 提交或 Tag(页面会显示绿色
Get it) - 点击 Gradle,复制页面生成的依赖行;或按下文格式自行替换
<Tag>。
Groovy(app 模块 dependencies)
dependencies {
// 必选:核心 SDK
implementation 'com.github.xiaohaozi9825.XAdapter:smart:<Tag>'
// 可选:树形 / 多级列表
implementation 'com.github.xiaohaozi9825.XAdapter:node:<Tag>'
}
Kotlin DSL
dependencies {
implementation("com.github.xiaohaozi9825.XAdapter:smart:<Tag>")
implementation("com.github.xiaohaozi9825.XAdapter:node:<Tag>")
}
说明:
-
<Tag>与你在 GitHub 打的 Tag 名 或 commit hash 一致即可(例如2.1.0)。 - 子模块坐标格式为:
com.github.<GitHub用户名>:<仓库名>:<子模块名>:<版本>。 - 若 JitPack 页面展示的字符串与上文略有差异,以页面一键复制为准。
3. 工程侧必开能力:ViewBinding
本库列表项基于 ViewBinding(ViewBinding 泛型)。请在 使用到 XAdapter 的模块(一般是 app)开启:
Groovy
android {
buildFeatures {
viewBinding true
}
}
若你同时使用 DataBinding,可与本库并存,按需同时打开 dataBinding true(与 Demo app 模块一致即可)。
4. 混淆配置
仅使用 smart
# ---------- 由 SDK consumer-rules.pro 自动合并,一般无需手写 ----------
-keepattributes Signature, InnerClasses, EnclosingMethod
-keep class pw.xiaohaozi.xadapter.smart.** { *; }
-keep,allowobfuscation class * extends pw.xiaohaozi.xadapter.smart.provider.XProvider { *; }
-keep,allowobfuscation class * extends pw.xiaohaozi.xadapter.smart.provider.SmartProvider { *; }
-keep,allowobfuscation class * extends pw.xiaohaozi.xadapter.smart.adapter.SmartAdapter { *; }
-keep,allowobfuscation class * extends pw.xiaohaozi.xadapter.smart.adapter.XAdapter { *; }
-keepclassmembers class * implements androidx.viewbinding.ViewBinding {
public static ** inflate(android.view.LayoutInflater, android.view.ViewGroup, boolean);
public static ** inflate(android.view.LayoutInflater);
public static ** bind(android.view.View);
}
# ---------- 集成方必改:自己的 ViewBinding 生成包 ----------
-keep class com.yourcompany.yourapp.databinding.** { *; }
同时使用 smart + node
在smart基础上增加:
-keep class pw.xiaohaozi.xadapter.node.** { *; }
-keep,allowobfuscation class * extends pw.xiaohaozi.xadapter.node.NodeProvider { *; }
-keep,allowobfuscation class * extends pw.xiaohaozi.xadapter.node.NodeAdapter { *; }