nowinandroid 一个完全由 Kotlin 和 Jetpack Compose 构建的功能完整的 Android 应用程序。它遵循 Android 设计和开发的最佳实践,旨在为开发者提供有用的参考。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Go to file
Don Turner 14e53e2bb7
Remove problematic API 23 device from FTL tests
1 year ago
.github Merge branch 'main' into patch-2 1 year ago
.google Revert "Revert "Revert "Revert "New build trigger"""" 2 years ago
.idea Add IntelliJ IDEA icons 1 year ago
.run Switch GMD to use a convention plugin 2 years ago
app Merge branch 'github/main' 1 year ago
app-nia-catalog Merge branch 'main' into patch/proguard 1 year ago
benchmarks Baseline Profiles API change 'collectStableBaselineProfile()' is changed to 'collect()' 1 year ago
build-logic Merge branch 'baseline-profile-api-change' of https://github.com/android/nowinandroid into baseline-profile-api-change 1 year ago
core Merge pull request #812 from Askeri-Muhendis/main 1 year ago
docs fix: close tag 1 year ago
feature Merge pull request #808 from SimonMarquis/compose-bom-2023-06-00 1 year ago
gradle Merge pull request #828 from SimonMarquis/kotlin-1.8.22 1 year ago
kokoro Remove problematic API 23 device from FTL tests 1 year ago
lint Remove redundant suppressions 1 year ago
spotless Configure spotless for kts and xml files 3 years ago
sync PR feedback 1 year ago
tools Create hooks folder if doesn't exist 2 years ago
ui-test-hilt-manifest ui-test-hilt-manifest uses `nowinandroid.android.hilt` plugin 2 years ago
.editorconfig Create .editorconfig, enable trailing commas 2 years ago
.gitignore Make code style default for project (#67) 3 years ago
CODE_OF_CONDUCT.md Add github-specific setup (#1) 3 years ago
CONTRIBUTING.md Fix markdown links in CONTRIBUTING.md 3 years ago
LICENSE Add initial app scaffolding 3 years ago
README.md remove M1 Mac Rosetta caution in README.md 1 year ago
build.gradle.kts Replace hardcoded license file with OSS licenses plugin 2 years ago
build_android_release.sh Change JAVA_HOME path to use JDK 17 from prebuilts repo 2 years ago
gradle.properties Merge pull request #781 from SimonMarquis/patch-5 1 year ago
gradlew Update Gradle 8.2 1 year ago
gradlew.bat Update to AGP 8.0 2 years ago
secrets.defaults.properties Add staging build variant, move staging URL out of source control 3 years ago
settings.gradle.kts Implement search feature (#685) 2 years ago

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 demoRelease variant is available on the Play Store in open beta.

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.

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:

  • In instrumentation tests, a temporary folder is used to store the user's preferences, which is wiped after each test. This allows using the real DataStore and exercising all related code, instead of mocking the flow of data updates.

  • There are Test implementations of each repository, which implement the normal, full repository interface and also provide test-only hooks. ViewModel tests use these Test repositories, and thus can use the test-only hooks to manipulate the state of the Test repository and verify the resulting behavior, instead of checking that specific repository methods were called.

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:

  • Dynamic color - uses colors based on the user's current color theme (if supported)
  • Default theme - uses predefined colors when dynamic color is not supported

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 analyse compose compiler metrics:

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

The reports files will be added to build/compose-reports in each module. The metrics files will be added to build/compose-metrics in each module.

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.