Skip to content

Commit

Permalink
📝(content) Add ChromeOS lint rules in Android Studio (chromeos#576)
Browse files Browse the repository at this point in the history
* 📝(content) ChromeOS lint rules in Android Studio

* Update contributors.js

* 📝(content)  Lint rules for ChromeOS in Android Studio

* Update site/en/android-environment/lint-rules-for-ChromeOS-in-Android-Studio.md

Co-authored-by: Sam Richard <[email protected]>

* Update site/en/posts/chromeos-lint-rules-in-android-studio.md

Co-authored-by: Sam Richard <[email protected]>

* Update site/en/android-environment/lint-rules-for-ChromeOS-in-Android-Studio.md

Co-authored-by: Sam Richard <[email protected]>

* Update site/en/android-environment/lint-rules-for-ChromeOS-in-Android-Studio.md

Co-authored-by: Sam Richard <[email protected]>

* Update site/en/posts/chromeos-lint-rules-in-android-studio.md

Co-authored-by: Sam Richard <[email protected]>

* Update site/en/android-environment/lint-rules-for-ChromeOS-in-Android-Studio.md

Co-authored-by: Sam Richard <[email protected]>

* Update site/en/android-environment/lint-rules-for-ChromeOS-in-Android-Studio.md

Co-authored-by: Sam Richard <[email protected]>

* Update site/en/posts/chromeos-lint-rules-in-android-studio.md

Co-authored-by: Sam Richard <[email protected]>

* Update site/en/android-environment/lint-rules-for-ChromeOS-in-Android-Studio.md

Co-authored-by: Sam Richard <[email protected]>

* Rename lint-rules-for-ChromeOS-in-Android-Studio.md to lint-rules-for-chromeos-in-android-studio.md

* Change to capitalization in file names.

* Update site/en/posts/chromeos-lint-rules-in-android-studio.md

* Update site/en/android-environment/lint-rules-for-chromeos-in-android-studio.md

Co-authored-by: Sam Richard <[email protected]>
  • Loading branch information
jkcinouye and Snugug committed Jan 20, 2023
1 parent 337d48c commit c9c7f17
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 0 deletions.
11 changes: 11 additions & 0 deletions site/_data/contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,17 @@ const contributors = {
title: 'Product Manager',
},
},
jhale: {
name: {
given: 'Josh',
family: 'Hale',
},
work: {
company: 'Google',
org: 'ChromeOS',
title: 'Software Engineer',
},
},
};

module.exports = () => contributors; // By making this a function, it'll force Eleventy to reevaluate it every time it gets recompiled
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
---
title: ChromeOS lint rules in Android Studio
metadesc: An in-depth guide on how to improve the experience of large screens on ChromeOS with lint rules in Android Studio.
date: 2023-01-20
weight: 1
tags:
- android studio
- large screens
---

We, at ChromeOS, are committed to enhancing developer tools and frameworks that
enable Android app developers to optimize their apps for Chromebooks seamlessly.
In doing so, we need to look consistently at ways to bring impactful tool sets
to developers to enhance the experience of building for large screens and
ChromeOS.

ChromeOS has evolved through the years as new challenges have presented
themselves. One of these challenges is identifying critical issues to engineers
early and often. Lint rules are at the heart of quality, as they provide flare
signals to developers for issues that will arise if not remedied. Our updated
lint rules provide developers with more visibility into how their apps run on
ChromeOS, showcasing issues, both software and hardware, that will undoubtedly
cause issues for Android applications that are run on any ChromeOS device.

To get more background context on the existence of these lint rules and their
importance, read through our blog post.

# Where are these lint rules?

We have been in active development for a few months now. With the release
schedule of Android Studio, some lint rules are being introduced with the
Electric Eel Canary builds. A few of these lint rules are also now available in
the Flamingo Canary releases. We will continue to build towards having these in
the stable versions of Android Studio in the coming months.

Another major thing to note is that these rules will be **_enabled by
default_** in newer versions of Android Studio. The goal of this is to have more
strongly opinionated guidance on how we want to help engineers build for
ChromeOS and larger screens going forward.

# New lint rules (updated as of Flamingo Canary 3)

### x86/x86_64 ABI support

The majority of Chromebooks run on the Intel architecture, thus making them a
predominantly x86 architectural platform. For ChromeOS to properly be supported
when NDK code is included as part of the binary, having x86 is a performance
boost due to removing the translation required from ARM libraries. Therefore, it
is strongly recommended that your development team adds `x86` or preferably
`x86_64` architecture support as it would be a performance boon for any native
code on ChromeOS or any Intel device.

#### Remedy

If possible, add `x86` and `x86_64` inside of your `abiSplits` within your
`build.gradle`. Also, ensure that you are adding the code to the appropriate
folders to support these ABIs. To get more information, reference the
documentation on [Android ABIs](https://developer.android.com/ndk/guides/abis)
and the talk on [ABI Support from ADS](https://youtu.be/C0IuT0O2wlM?t=229).

!!! aside.message--note
**Note:** Ensure that whatever included third-party libraries that are being
utilized also have x86 and x86_64 binaries.
!!!

### ChromeOS hardware limitation

The majority of ChromeOS devices come with a smaller sample set of hardware
sensors and other features compared to an Android phone. The goal of this rule
is to flag to developers that if you are using the flag `<uses-feature>` with
`android:required=true`, your app will not be available on the Google Play Store
on ChromeOS. A strong recommendation to ensure that your app can be accessed on
as many devices as possible is to ensure that the hardware feature is not
required by default. Instead, you can add defensive code to check for specific
hardware at run time rather. An example of this would be

```
%lt;uses-feature android:name="android.hardware.camera" android:required="true"%gt;
```

#### Remedy

Ensure that the features that are within your application are actually
required, and if they are not, change the `android:required` parameter to
`false` and add defensive programming when API calls are required. To get more
information, reference the documentation on
[explicitly declared features.](https://developer.android.com/guide/topics/manifest/uses-feature-element#declared)

![Feature 'camera flash required' rule, showcasing the lint warning and the inspection description](ix:https://posts/android-studio-lint-rules/lint.gif)

### Non-resizable activities

By default, Android Runtime for ChromeOS, running Android R or higher on
Chromebooks, starts an Android app in either the phone or tablet version of the
application, based on the default UI state. However, there is a third option
that is a better experience for ChromeOS users, the Resizable mode. By enabling
this flag as part of your Activity, users that can use your application in any
multi-window environments can take advantage of resizing your application to the
appropriate size. These changes will allow users to scale the UI to meet their
needs. After adding these changes to your Manifest, test your application
against the Desktop Emulator referenced below.

![Android Virtual Device Creation for Desktop Emulator](ix:https://posts/android-studio-lint-rules/avd.gif)

#### Remedy

Add the `resizableActivity="true"` attribute to your Activity in your
`AndroidManifest.xml` file. To get more information, reference the documentation
on
[large screen restrictions](https://developer.android.com/guide/topics/large-screens/multi-window-support#resizeableActivity).

### Configuration changes

One major caveat to resizable screens is that every time a user changes the
size of the application, `onConfigurationChanged()` is called. If your app is
issuing a full redraw inside of that method, there will be performance
implications associated with it. Currently, we are checking to ensure that
`finish()` is not called within `onConfigurationChanged`, as you should be
handling the savedInstanceState with more granularity versus enforcing a full
redraw. We will continue to find cases where performance degradation will occur
and update this rule accordingly.

#### Remedy

Ensure that `finish()` is not called within the `onConfigurationChanged()` API
in your Activities and Fragments. To get more information, reference the
documentation on
[handling configuration changes](https://developer.android.com/guide/topics/resources/runtime-changes).

### Keyboard and mouse support

With the increased adoption of Jetpack Compose, we wanted to ensure that
building with those libraries also included functionality for mouse and keyboard
support going forward. Over time, we will continue to increase the usability of
mouse, keyboard, trackpad, and other peripheral interactions. In order to get
the baseline experiences, you'll have to update your Gradle dependencies to the
minimum required versions.

#### Remedy

Update `androidx.compose.foundation:foundation` to a minimum version of 1.2. To
get more information, reference the
[compose version release notes](https://developer.android.com/jetpack/androidx/releases/compose#versions).

!!! aside.message--tip
**Tip:** 90% of users interact with apps on Chromebooks by using a keyboard and
mouse. (Source:
[2022 Google Internal Data\*](https://chromeos.dev/en/posts/game-controls-for-android-games#fn1))
!!!

## Feedback

The team is constantly looking to improve these tools and documentation
surrounding optimizations for large screens. A critical step in this process is
to give us feedback on the accuracy and usefulness of the lint rules that are
deployed in Android Studio. You can do this by providing feedback for the rule.
When the lint rule shows up in Android Studio, click on "Provide feedback on
this warning". You should be taken to a dialog that looks similar to the one
below. The more accurate and descriptive the information given, the more we are
able to iterate quickly on making the appropriate changes.

![Provide Feedback Dialog in Android Studio](ix:https://posts/android-studio-lint-rules/feedback.png)
85 changes: 85 additions & 0 deletions site/en/posts/chromeos-lint-rules-in-android-studio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
title: ChromeOS lint rules in Android Studio
metadesc: Use lint rules in Android Studio to enhance the experience of building for large screens and ChromeOS.
tags:
- android
- large screens
authors:
- jhale
date: 2023-01-20
---

At ChromeOS, we are committed to enhancing developer tools and frameworks that
enable Android app developers to seamlessly optimize their apps for Chromebooks.
In doing so, we need to explore ways to bring impactful tool sets to developers
to enhance the experience of building for large screens and ChromeOS.

## What are lint rules?

Linting is an automated checking of your source code for various programmatic
and stylistic errors such as correctness, security, performance, usability,
accessibility, and internationalization. A lint rule is the code that backs any
individual potential error. Android Studio has a built in lint tool that
notifies developers of any errors and the severity of those errors.

For more information on lint rules in your Android Studio environment, refer to
the documentation on
[improving your code with lint checks](https://developer.android.com/studio/write/lint).

## Linting for large screen testing

One of the largest challenges we face on ChromeOS is that the vast majority of
app developers are not aware that their app is automatically deployed to the
ChromeOS Play Store. As such, the normal development and testing processes of
many apps omit testing on large screens or ChromeOS. As a result, the overall
app experience on these devices will trail behind their phone counterparts, and
users on those platforms will suffer from a poor experience.

The goal of these initial lint rules is to start the process of bringing
ChromeOS and large screens to the forefront of app development, and start to
create a unified toolkit that developers can leverage easily to kickstart the
process of developing a great ChromeOS or other large screen application.

## How to test with lint rules

When you upgrade your development environment to Electric Eel or Flamingo
versions of Android Studio, you will get these lint rules for free. These lint
rules are enabled by default; if your application was violating these rules
previously you will be notified as soon as your application is done building and
the static analysis tools can be run.

Another way to test these is by launching your application on the Desktop
Emulator in Android Studio and seeing how your application performs in this
specialized environment. You can create a new Desktop emulator through the AVD
menus built into Android Studio.

![Android Virtual Device Creation for Desktop Emulator](ix:https://posts/android-studio-lint-rules/avd.gif)

## Feedback

The team is constantly looking to improve these tools and documentation
surrounding optimizations for large screens. A critical step in this process is
to give us feedback on the accuracy and usefulness of the lint rules that are
deployed in Android Studio.

You can do this by providing feedback for the rule. When the lint rule shows up
in Android Studio, click on "Provide feedback on this warning". You should be
taken to a dialog that looks similar to the one below. The more accurate and
descriptive the information given, the more we are able to iterate quickly on
making the appropriate changes.

![Provide Feedback Dialog in Android Studio](ix:https://posts/android-studio-lint-rules/feedback.png)

## What's next?

Optimizing for
[ChromeOS and Large Screen Guidance](https://developer.android.com/guide/topics/large-screens/get-started-with-large-screens)
will continue to evolve. We want to continue to improve our existing toolkits to
bring more awareness to developers early and often.
We want developers to feel empowered to make large screen improvements for their
apps. Showcasing potential issues earlier in the development process is one way
to achieve this.

For further reading and a detailed recommendation on best practices for
ChromeOS and large screen guidance, refer to the
[large screen documentation](https://developer.android.com/guide/topics/large-screens/get-started-with-large-screens).

0 comments on commit c9c7f17

Please sign in to comment.