Under the new project, Gradle sync reports an error Plugin was not found in any of the following sources

Gradle sync error under new project: Plugin [id 'com.android.application' version '7.1.2' apply false] was not found in any of the following sources:

Problem Description

I am a novice who is new to Android development. I am learning to use Android Studio by watching online blog tutorials. the following question.

Plugin [id 'com.android.application' version '7.1.2' apply false] was not found in any of the following sources:

After I operated File->New project->Empty application according to the video teaching, this problem occurred under Gradle sync.

resolution process

In the process of troubleshooting, according to the blog on the Internet, it is guessed that the problem is caused by the mismatch between the version of Gradle and Gradle Plugins, but it is found that in the process of sync, the above phenomenon does not appear in build.gradle and settings.gradle. I can't figure it out. I had to query each file in Gradle Scripts in the project and found that in the gradle.properties file under Gradle Scripts, the following lines of code appeared:

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Tue Mar 29 12:47:27 CST 2022
systemProp.http.proxyHost=mirrors.neusoft.edu.cn
systemProp.https.proxyHost=mirrors.neusoft.edu.cn
systemProp.https.proxyPort=80
systemProp.http.proxyPort=80

It actually hung up the http proxy for me, but when I opened File->settings->Appearance&Beavior->System Settings->HTTP Proxy, it was obviously changed to No proxy, why did it hang up on my plug-in download acting. And before I did Gradle sync, I modified this option so that Gradle can be downloaded normally.

The reason is that when I installed AS according to the blog teaching, the first interface I just opened AS asked me to set the proxy of AS, and according to some outdated blogs, downloading from the official source would be very slow, so I just set up the proxy and specified the port number. At this time, after the setting is completed, it is actually written into the global settings, and the options I modify in the settings are only applied to the current Projects. The HTTP proxy I modified later is only valid for AS.

In other words, when you download Gradle in AS, you use the proxy in AS, and the gradle plug-in I downloaded in gradle sync later uses the global settings.

So in the AS global settings (located C:\Users\Aerith\.gradle\gradle.properties), comment out the above code:

# systemProp.http.proxyHost=mirrors.neusoft.edu.cn
# systemProp.https.proxyHost=mirrors.neusoft.edu.cn
# systemProp.https.proxyPort=80
# systemProp.http.proxyPort=80

Save and the problem will be solved.

Guess you like

Origin blog.csdn.net/qq_41624557/article/details/123848212