nowinandroid README

The project's README from github.com/android/nowinandroid. As one markdown file: README.md.

Now in Android

Now in Android App

Learn how this app was designed and built in the design case study, architecture learning journey and modularization learning journey.

This is the repository for the Now in Android app. It is a work in progress 🚧.

Now in Android is a fully functional Android app built entirely with Kotlin and Jetpack Compose. It follows Android design and development best practices and is intended to be a useful reference for developers. As a running app, it's intended to help developers keep up-to-date with the world of Android development by providing regular news updates.

The app is currently in development. The prodRelease variant is available on the Play Store.

Features

Now in Android displays content from the Now in Android series. Users can browse for links to recent videos, articles and other content. Users can also follow topics they are interested in, and be notified when new content is published which matches interests they are following.

Screenshots

Screenshot showing For You screen, Interests screen and Topic detail screen

Development Environment

Now in Android uses the Gradle build system and can be imported directly into Android Studio (make sure you are using the latest stable version available here).

Change the run configuration to app.

image

The demoDebug and demoRelease build variants can be built and run (the prod variants use a backend server which is not currently publicly available).

image

Once you're up and running, you can refer to the learning journeys below to get a better understanding of which libraries and tools are being used, the reasoning behind the approaches to UI, testing, architecture and more, and how all of these different pieces of the project fit together to create a complete app.

Architecture

The Now in Android app follows the official architecture guidance and is described in detail in the architecture learning journey.

Modularization

The Now in Android app has been fully modularized and you can find the detailed guidance and description of the modularization strategy used in modularization learning journey.

Build

The app contains the usual debug and release build variants.

In addition, the benchmark variant of app is used to test startup performance and generate a baseline profile (see below for more information).

app-nia-catalog is a standalone app that displays the list of components that are stylized for Now in Android.

The app also uses product flavors to control where content for the app should be loaded from.

The demo flavor uses static local data to allow immediate building and exploring of the UI.

The prod flavor makes real network calls to a backend server, providing up-to-date content. At this time, there is not a public backend available.

For normal development use the demoDebug variant. For UI performance testing use the demoRelease variant.

Testing

To facilitate testing of components, Now in Android uses dependency injection with Hilt.

Most data layer components are defined as interfaces. Then, concrete implementations (with various dependencies) are bound to provide those interfaces to other components in the app. In tests, Now in Android notably does not use any mocking libraries. Instead, the production implementations can be replaced with test doubles using Hilt's testing APIs (or via manual constructor injection for ViewModel tests).

These test doubles implement the same interface as the production implementations and generally provide a simplified (but still realistic) implementation with additional testing hooks. This results in less brittle tests that may exercise more production code, instead of just verifying specific calls against mocks.

Examples:

To run the tests execute the following gradle tasks:

[!NOTE] You should not run ./gradlew test or ./gradlew connectedAndroidTest as this will execute tests against all build variants which is both unnecessary and will result in failures as only the demoDebug variant is supported. No other variants have any tests (although this might change in future).

Screenshot tests

A screenshot test takes a screenshot of a screen or a UI component within the app, and compares it with a previously recorded screenshot which is known to be rendered correctly.

For example, Now in Android has screenshot tests to verify that the navigation is displayed correctly on different screen sizes (known correct screenshots).

Now In Android uses Roborazzi to run screenshot tests of certain screens and UI components. When working with screenshot tests the following gradle tasks are useful:

[!NOTE] Note on failing screenshot tests
The known correct screenshots stored in this repository are recorded on CI using Linux. Other platforms may (and probably will) generate slightly different images, making the screenshot tests fail. When working on a non-Linux platform, a workaround to this is to run recordRoborazziDemoDebug on the main branch before starting work. After making changes, verifyRoborazziDemoDebug will identify only legitimate changes.

For more information about screenshot testing check out this talk.

UI

The app was designed using Material 3 guidelines. Learn more about the design process and obtain the design files in the Now in Android Material 3 Case Study (design assets also available as a PDF).

The Screens and UI elements are built entirely using Jetpack Compose.

The app has two themes:

Each theme also supports dark mode.

The app uses adaptive layouts to support different screen sizes.

Find out more about the UI architecture here.

Performance

Benchmarks

Find all tests written using Macrobenchmark in the benchmarks module. This module also contains the test to generate the Baseline profile.

Baseline profiles

The baseline profile for this app is located at app/src/main/baseline-prof.txt. It contains rules that enable AOT compilation of the critical user path taken during app launch. For more information on baseline profiles, read this document.

[!NOTE] The baseline profile needs to be re-generated for release builds that touch code which changes app startup.

To generate the baseline profile, select the benchmark build variant and run the BaselineProfileGenerator benchmark test on an AOSP Android Emulator. Then copy the resulting baseline profile from the emulator to app/src/main/baseline-prof.txt.

Compose compiler metrics

Run the following command to get and analyze compose compiler metrics:

./gradlew assembleRelease -PenableComposeCompilerMetrics=true -PenableComposeCompilerReports=true

The reports files will be added to build/compose-reports. The metrics files will also be added to build/compose-metrics.

For more information on Compose compiler metrics, see this blog post.

License

Now in Android is distributed under the terms of the Apache License (Version 2.0). See the license for more information.

nowinandroid (android/nowinandroid)

Searching Database…

这是什么?Now in Android 是一个完全用 Kotlin 和 Jetpack Compose 构建的功能完整的 Android 应用。它既是 Android 设计和开发最佳实践的官方参考示例,同时作为一个实际运行的应用,提供 Android 开发方面的新闻资讯。
这是可以安装的应用,还是只是用来阅读的示例代码?两者都是:它是一个能正常运行的新闻应用——prodRelease 变体已上架 Play Store——同时也是一套参考代码,展示一个完整的现代 Android 应用是如何搭建起来的。
我怎样才能把它跑起来?把项目导入最新稳定版 Android Studio,将运行配置切换为 app,然后构建 demoDebug 变体——它开箱即用,也是日常开发推荐的变体。
除了 Android Studio,我还需要别的东西吗?不需要——项目使用 Gradle 作为构建系统,demo 变体加载的是本地静态数据,所以无需任何后端或外部服务,就能立即构建并浏览界面。
连接真实后端的那个版本能用吗?你用不了:prod 变体会对一个并未公开的后端服务器发起真实的网络请求,所以本地只能构建和运行 demo 变体。
我能在自己的项目里复用这些代码吗?可以,它基于 Apache License 2.0 发布,你可以在该许可条款下学习、fork 和复用。
在应用里实际能做些什么?你可以浏览 Now in Android 系列最新视频、文章和其他内容的链接,关注自己感兴趣的话题,并在发布了符合你关注兴趣的新内容时收到通知。
这个项目是怎么做测试的?它使用 Hilt 做依赖注入,并且刻意不使用 mock 库:用实现了相同接口的测试替身来替换生产环境的实现,另外还有 Roborazzi 截图测试。通过 testDemoDebug 任务运行测试——直接运行 ./gradlew test 会失败,因为只有 demoDebug 变体带有测试。
界面是用什么做的?所有界面都采用遵循 Material 3 规范的 Jetpack Compose,设备支持时启用动态取色,否则使用预设的默认主题,两套主题都支持深色模式,并且有适配不同屏幕尺寸的自适应布局。
代码库是如何组织的?项目完全模块化,并遵循 Android 官方架构指南;README 中链接了关于架构和模块化的学习路径,讲解了界面、测试和架构这些做法背后的考量。
Creator
android
Size
137.3 MB
Stars
21.9K
Age
4y
Commits · 90 Days