Why write an article about upgrading an IDE?

Every time I upgrade Android Studio, I will encounter a bunch of bugs. There are lots of bugs on the Internet, some have been stepped on to solve, and some can’t find a solution, so I have to try it myself. This has persuaded many partners who want to upgrade. This time I also kept track of the potholes I stepped in while upgrading from version 4.0.

1. Android Studio 4.0.2 to 4.1.2

A few months ago, I was browsing Android Developers on a daily basis when I saw a new feature in Studio4.1.2, updated it on a whim, and got stuck.

Studio plug-ins are all missing

Studio4.1 starts. The plug-in directory is changed. Plug-ins may be lost or damaged. So don’t check the upgrade plugin check when upgrading, just upgrade the IDE, and then reinstall the plugin. Note the backup configuration! Note the backup configuration! Note the backup configuration! (The painful experience is that I didn’t expect such a situation at that time, so I just exported the setting file as a habit, and then I had to find the plug-in from memory.)

Many plug-ins are not supported for 4.1

Before a few good to generate Java template code plug-ins, are not able to use, also did not find an alternative plug-in, the tragedy of the future can only write their own [crying halo], too affect the efficiency

Gradle compile problem
  1. In Sync Project with Gradle Files, downloading third-party dependencies always fails for no reason, and I didn’t find anyone who had similar experience. Finally, I accidentally found that I changed HTTP to HTTPS, and it can be downloaded normally, which is kind of magical.

  2. With a period of time project cut to AndroidX, but also maintain Android Support version, Git branch frequently switched, some classes began to report red, how to treat is not good, but it does not affect the project run, slowly only when did not see [wu face], forced to die ocD.

  3. An error occurs when downloading third-party dependencies during Build Project

Could not HEAD ‘xxx.pom'. Received status code 502 from server: Bad Gateway
Copy the code

The reason: Setting -> Appearance & Behavior -> System Settings -> HTTP Proxy If there is no continue to look for projects of gradle. The properties files or/Users/username /. Gradle/gradle. The properties, to get rid of the following:

systemProp.https.proxyHost=mirrors.neusoft.edu.cn
systemProp.https.proxyPort=80
systemProp.http.proxyHost=mirrors.neusoft.edu.cn
systemProp.http.proxyPort=80
Copy the code
  1. Maven download address forced to change to HTTPS error
allprojects {
    repositories {
        ...
        maven {
            url "http://xxx.com/xxxx/"
        }
    }
}

sun.security.validator.ValidatorException: 
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Copy the code
Of course, despite these drawbacks, the new Studio features work well, at the very least they are less likely to be annoying.

2. Upgrade Android Studio 4.1.2 to 4.2.1

All Gradle commands are missing from Gradle panel

Solution:

Experimental => Do not build Gradle task XXX => Deselect the check box, and then Rebuild

The IDE uses the built-in Open JDK by default, but the 4.2 IDE uses JDK 11 by default
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptOnlineDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)
Copy the code
Java. Lang. NoClassDefFoundError: javax.mail/XML/bind/JAXBException,Copy the code

The reason is that the default configuration of Studio has changed after the upgrade. By default, JDK of a higher version will be used for compilation, so this class cannot be found and an error occurs. Therefore, we just need to change the compilation version of local JDK back to 1.8 to solve the problem.

file -> project structure -> sdk location -> jdk location

Change the default JDK Location in the figure

2.3 Code reference relationship error: X related problems, but does not affect the project running

Studio three basic operations: Clean project, Snyc Project, Invalidate Caches and Restart

More bugs are on their way….

Some bugs may not have been found, can be used normally at present. Much better than the 4.1.x Nightmare version. Note: You are advised to back up all configurations before upgrading. If necessary, you can use the dual-application mode.