一个用于在没有物理设备或模拟器的情况下渲染应用程序界面的 Android 库。
class LaunchViewTest { @get:Rule val paparazzi = Paparazzi( deviceConfig = PIXEL_5, theme = "android:Theme.Material.Light.NoActionBar" // ...更多选项请参阅文档 ) @Test fun launchView() { val view = paparazzi.inflate<LaunchView>(R.layout.launch) // 或者... // val view = LaunchView(paparazzi.context) view.setModel(LaunchModel(title = "paparazzi")) paparazzi.snapshot(view) } @Test fun launchComposable() { paparazzi.snapshot { MyComposable() } } }
有关文 档和 API,请参阅项目网站。
./gradlew sample:testDebug
运行测试并在 sample/build/reports/paparazzi/ 生成 HTML 报告,显示所有测试运行和快照。
./gradlew sample:recordPaparazziDebug
将快照保存为黄金值,存储在预定义的受版本控制的位置(默认为 src/test/snapshots)。
./gradlew sample:verifyPaparazziDebug
运行测试并与先前记录的黄金值进行验证。失败会在 sample/build/paparazzi/failures 生成差异。
更多示例,请查看 sample 项目。
建议使用 Git LFS 来存储快照。以下是快速设置:
brew install git-lfs git config core.hooksPath # 可选,确认 git 钩子的安装位置 git lfs install --local git lfs track "**/snapshots/**/*.png" git add .gitattributes
在 CI 上,你可以设置类似以下内容:
$HOOKS_DIR/pre-receive
# 比较 .gitattributes 过滤器匹配的文件与实际由 git-lfs 跟踪的文件 diff <(git ls-files ':(attr:filter=lfs)' | sort) <(git lfs ls-files -n | sort) >/dev/null ret=$? if [[ $ret -ne 0 ]]; then echo >&2 "此远程仓库检测到文件提交时未使用 Git LFS。运行 'brew install git-lfs && git lfs install' 安装并重新提交文件。"; exit 1; fi
your_build_script.sh
if [[ 正在运行快照测试 ]]; then # 如果文件未使用 git lfs 提交,则快速失败 "$HOOKS_DIR"/pre-receive git lfs install --local git lfs pull fi
如果使用 Jetifier 迁移 Support 库,请在 gradle.properties 中添加以下内容以排除捆绑的 Android 依赖项。
android.jetifier.ignorelist=android-base-common,common
在对 Lottie 动画进行截图时,需要强制 Lottie 不在后台线程上运行,否则 Paparazzi 可能会抛出异常 #494,#630。
@Before fun setup() { LottieTask.EXECUTOR = Executor(Runnable::run) }
某些 Composable(如 GoogleMap())会检查 LocalInspectionMode 以快速切换到适用于 @Preview 的 Composable。
然而,Paparazzi 不会全局设置 LocalInspectionMode,以确保快照代表真实的生产输出,类似于它覆盖传统视图的 View.isInEditMode。
作为解决方案,我们建议将这样的 Composable 包装在带有 CompositionLocalProvider 的自定义 Composable 中,并在那里设置 LocalInspectionMode。
@Test fun inspectionModeView() { paparazzi.snapshot( CompositionLocalProvider(LocalInspectionMode provides true) { YourComposable() } ) }
我们的更新日志包含发布历史。
使用插件应用:
buildscript { repositories { mavenCentral() google() } dependencies { classpath 'app.cash.paparazzi:paparazzi-gradle-plugin:1.3.4' } } apply plugin: 'app.cash.paparazzi'
使用插件 DSL:
plugins { id 'app.cash.paparazzi' version '1.3.4' }
开发版本的快照可在 Sonatype 的 snapshots 仓库中获取snap。
repositories { // ... maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } }
Copyright 2019 Square, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


字节旗下AI内容创作Agent
小云雀是字节跳动旗下剪映团队推出的AI内容创作Agent,主打”一句话打造一个爆款”的零门槛创作体验。用户只需输入一句指令,可自动生成15-60秒短视频、数字人口播视频、风格化海报等内容,支持200+可商用数字人形象和19种语言及方言。小云雀核心功能包括智能成片、AI设计、照片会说话、爆款复刻等,已接入豆包大模型、DeepSeek Chat及自研Seedance 2.0视频生成模型、Seedream 5.0图像生成模型。目前支持安卓APP和网页版,每日登录可领取120积分。适合自媒体创作者、电商营销人员、教育工作者及普通用户使用,近期因用户量激增,视频生成排队时长可达8小时。

