SoFunction
Updated on 2025-05-04

Android Development Environment Configuration Guide

This article records the problems and solutions encountered in the process of configuring the development environment after I first joined the company, and hopes that it will be helpful to everyone.

Network environment: VPN precautions

If the internal network of the company requires access through a VPN, it is recommended to turn off the VPN used by individuals to avoid conflicts between the two. Also, remember to check and delete the proxy that might have been set through the command line before, andProxy information configured in the file prevents them from interfering with normal network connections.

Check and delete the command line proxy settings:

# Check the current proxy settingsenv | grep -i proxy

# Delete proxy environment variablesunset http_proxy
unset https_proxy
unset HTTP_PROXY
unset HTTPS_PROXY

Check and cleanFile: File location:~/.gradle/and the project root directoryDelete or comment out the following similar configurations:

=xxx
=xxx
=xxx
=xxx

Unified tool version: Android Studio & JDK

When joining a new project or team, please take the initiative to confirm the currently recommended version with your colleagues. To avoid compilation or operational problems due to environmental differences, it is strongly recommended that team members maintain uniformity between Android Studio and JDK versions.

Gerrit's mailbox configuration is crucial

If your company uses Gerrit for code management,Be sure to configure your Git mailbox correctly before submitting the code for the first time, make sure it is consistent with the registered mailbox in the Gerrit system. Gerrit identifies the submitter by mail.

If you accidentally submit the code in the wrong mailbox configuration, don't panic. It is recommended to pass firstgit logOr other ways to save your code modification content (for example, usegit diff > my_changes.patch) and then delete the current local branch (git branch -D <branch_name>), re-pull the branch from the remote repository, apply your modifications, and finally re-submit.

Git pull and submit code: Merge vs Rebase

Be sure to confirm the recommended code merging strategy with team members or project leaders before pulling or submitting code. Some projects require usegit mergeSome tend to usegit rebaseto keep commit history linear.

If the operation fails (such as using merge instead of rebase incorrectly), it can also be remedied by deleting the local branch, re-pulling and operating in the correct way.

When submitting the code for the first time, it is recommended to do it under the guidance of an experienced colleague. This can avoid introducing errors due to improper operation, or even contaminating remote warehouses, causing trouble to other team members.

Resolving the missing Change-Id in message footer error

Sometimes when submitting code to Gerritmissing Change-Id in message footerError. This is because Gerrit needs to include a unique Commit Message at the end of each Git commitChange-IdCome track code review.

Usually, Gerrit will provide acommit-msgHook scripts are automatically generatedChange-Id. If your local repository lacks this hook, you can get and install it from the Gerrit server through the following command (remember to replace the address and username in the command):

gitdir=$(git rev-parse --git-dir)
scp -p -P 29418 xxx@:hooks/commit-msg ${gitdir}/hooks/
# Ensure that the script has execution permissionschmod +x ${gitdir}/hooks/commit-msg

After installing the hook, for the submitted but missingChange-IdThe commit can be corrected using the following command (it will reopen the editor to let you confirm the commit message and then automatically add Change-Id):

git commit --amend

If you don't need to modify the commit message, just want the hook to automatically add Change-Id, you can use:

git commit --amend --no-edit

Does the code run after modification do not take effect?

This is a relatively common "metaphysical" problem. When you modify the code and re-run the application and find that the changes have not taken effect, you can try the following methods:

  • Enable Package Manager installation: in Android StudioRun/Debug Configurations, find your application configuration and checkAlways install with package manager (disables deploy optimizations on Android 11 and later)Options. This option forces installation using the package manager, which can sometimes solve problems caused by deployment optimization.

  • Close HotSwap: If the previous step is invalid, you can try to turn off the HotSwap function. HotSwap is designed to speed up code deployment, but can sometimes lead to inconsistent state.

The above is the detailed content of the Android development environment configuration avoidance guide. For more information about Android configuration avoidance, please pay attention to my other related articles!