Android studio tools & tips

Dung Tran Van
Chim cu chăm code
Published in
4 min readMar 19, 2020

--

1. Offline mode

· From Gradle tab -> Toggle offline mode

Toggle offline mode

· With offline mode, IDE will execute faster because of ignoring loading gradle and dependencies

2. ADB tool

· Installing

ADB will be included in Android sdk .

- Window: C:\Users\user_name\AppData\Local\Android\Sdk

- Mac: /Users/user_name/Library/Android/sdk

· Setup global environment

- Window: Environment variables -> Path -> New -> Insert adb path (path to sdk/platform-tools)

- Mac:

§ echo ‘export ANDROID_HOME=/Users/$USER/Library/Android/sdk’ >> ~/.bash_profile

§ echo ‘export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools’ >> ~/.bash_profile

· How to use

- Install/uninstall apps

$adb install package.apk

$adb uninstall package_name

- Shell

$adb shell : access to device OS

- Logcat

Using to dump device’s logs

$adb logcat > logcat.txt

Using filter: *:D, *:E … to filter logs as debug, error …

3. Git tool

Find all git command in Menu -> VCS -> Git

Git options

· Add, commit, revert, reset

· Fetch, pull, push, rebase

· Compare sources

4. Hotkeys

Keep in mind the hotkeys which be used frequently. From the menu, we can see hotkeys right of each feature.

· Double shift: search files

· Ctrl + Shift + F/R, Ctrl + F/R

· Cmd/Ctrl + E: Recent files

· Ctrl + Alt + <- : Last edit location

· Ctrl + F12 : File structure

5. Refactor

· Move/rename/copy

Using for change file location, rename files/packages, copy files.

· Safe delete: To prevent wrong deleting, we should use safe delete to find all affect locations.

· Remove unused resources: Unused resources are not bound by others via resource id. To prevent the wrong removal, we shouldn’t use the name of resources inside the project. If still need to use resources by name, we need to add them to lint file to ignore removing task.

· Code cleanup

When you clean up your code using ‘Android Studio’, It starts inspecting code defined rules.

For list of defined rules check, File -> Settings -> Editor -> Inspection. (For Mac, Android Studio -> Preferences -> Editor -> Inspection) Here you can find all rules like: non-used variables, non-used import, Abstraction issues, Code style issues, Java Beans issues etc.

After inspection of code, Android Studio will remove such code from your files that are not necessary.

· Reformat code : Keep source code beautifier and clean, we should use the same code formator inside the project and format code usually.

6. Build apps

· Make app: compile the adding source code into current source

· Build variants: config type of build (dev, stage, release …)

· Build apk/bundle: genarate apk/bundle files

· Analyze apk: Allow analyze app to the path of source or resource. We can determine where are the large paths to optimize them.

· Clean/rebuild project: In some cases of build errors, we should clean and rebuild the project to clear errors.

7. Debugging

· Attach process: Allow attach to process which we want to debug by steps

· Tracking debugging: Add breakpoints and next step by step to check current status, the value of variable …

· Evaluate expression:

You can just use “evaluate expression” button while debugging.

8. Layout inspector

· Using for capture layout view tree

· Allows you to compare your app layout with design mockups, display a magnified view of your app, and examine details of its layout at runtime. This is useful when your layout is built at runtime rather than entirely in XML and the layout is behaving unexpectedly.

Layout inspector

9. Others

· Firebase: Tools -> Firebase, use to install/config google services (Cloud messaging, In-App messaging …)

· App links assistant

Android App Links enable your users to launch directly into your app when they click on URLs that your app supports and they can also make your app content searchable.

--

--