新创建的Android项目上的Gradle项目同步失败

时间:2017-11-14 15:00:47

标签: android intellij-idea

我在Intellij Idea中创建了一个Android项目(我使用的是Android Studio而不是Android Studio,因为我还需要在项目中管理一些React代码)。我创建了一个基本的Activity,它是构建项目的默认设置:

package com.example.mypackage.reacttoastex;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

但是,我在Intellij中收到此错误消息:

Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly

如果我运行Build Project,我会得到这个:

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
   > Could not find any version that matches com.android.support:appcompat-v7:27.+.
     Versions that do not match:
         26.0.0-alpha1
         25.3.1
         25.3.0
         25.2.0
         25.1.1
         + 31 more
     Required by:
         project :app

在日志中,我得到了这个:

2017-11-14 14:31:38,156 [4841535]  ERROR - .intellij.util.io.HttpRequests - IntelliJ IDEA 2017.2.5  Build #IU-172.4343.14 
2017-11-14 14:31:38,156 [4841535]  ERROR - .intellij.util.io.HttpRequests - JDK: 1.8.0_152-release 
2017-11-14 14:31:38,156 [4841535]  ERROR - .intellij.util.io.HttpRequests - VM: OpenJDK 64-Bit Server VM 
2017-11-14 14:31:38,156 [4841535]  ERROR - .intellij.util.io.HttpRequests - Vendor: JetBrains s.r.o 
2017-11-14 14:31:38,156 [4841535]  ERROR - .intellij.util.io.HttpRequests - OS: Mac OS X 
2017-11-14 14:31:38,156 [4841535]  ERROR - .intellij.util.io.HttpRequests - Last Action: GotoAction 
2017-11-14 14:31:38,434 [4841813]   INFO - ea.sdk.wizard.SdkQuickfixUtils - Downloading https://dl.google.com/android/repository/repository2-1.xml 
2017-11-14 14:31:38,434 [4841813]  ERROR - .intellij.util.io.HttpRequests - Assertion failed: Network shouldn't be accessed in EDT or inside read action 
java.lang.Throwable
    at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:168)
    at com.intellij.util.io.HttpRequests.process(HttpRequests.java:384)
    at com.intellij.util.io.HttpRequests.access$100(HttpRequests.java:60)
    at com.intellij.util.io.HttpRequests$RequestBuilderImpl.connect(HttpRequests.java:262)
    at com.intellij.util.io.RequestBuilder.saveToFile(RequestBuilder.java:67)
    at com.android.tools.idea.sdk.StudioDownloader.downloadFully(StudioDownloader.java:86)
    at com.android.tools.idea.sdk.StudioDownloader.downloadFully(StudioDownloader.java:98)
    at com.android.tools.idea.sdk.StudioDownloader.downloadAndStream(StudioDownloader.java:54)
    at com.android.repository.impl.manager.RemoteRepoLoaderImpl.fetchPackages(RemoteRepoLoaderImpl.java:100)
    at com.android.repository.impl.manager.RepoManagerImpl$LoadTask.run(RepoManagerImpl.java:550)
    at com.android.repository.api.RepoManager$DummyProgressRunner.runSyncWithProgress(RepoManager.java:397)
    at com.android.repository.impl.manager.RepoManagerImpl.load(RepoManagerImpl.java:364)
    at com.android.repository.api.RepoManager.loadSynchronously(RepoManager.java:290)
    at com.android.tools.idea.sdk.wizard.SdkQuickfixUtils.createDialog(SdkQuickfixUtils.java:129)
    at com.android.tools.idea.sdk.wizard.SdkQuickfixUtils.createDialogForPaths(SdkQuickfixUtils.java:85)
    at com.android.tools.idea.gradle.project.sync.hyperlink.InstallRepositoryHyperlink.execute(InstallRepositoryHyperlink.java:41)
    at com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink.executeIfClicked(NotificationHyperlink.java:38)
    at com.android.tools.idea.gradle.notification.QuickFixNotificationListener.hyperlinkActivated(QuickFixNotificationListener.java:37)
    at com.intellij.notification.NotificationListener$Adapter.hyperlinkUpdate(NotificationListener.java:31)
    at com.intellij.openapi.externalSystem.service.notification.NotificationData$1.hyperlinkActivated(NotificationData.java:77)
    at com.intellij.notification.NotificationListener$Adapter.hyperlinkUpdate(NotificationListener.java:31)
    at com.intellij.openapi.externalSystem.service.notification.EditableNotificationMessageElement$MyCellEditor$ActivatedHyperlinkListener.hyperlinkUpdate(EditableNotificationMessageElement.java:186)
    at javax.swing.JEditorPane.fireHyperlinkUpdate(JEditorPane.java:342)
    at javax.swing.text.html.HTMLEditorKit$LinkController.activateLink(HTMLEditorKit.java:875)
    at javax.swing.text.html.HTMLEditorKit$LinkController.mouseClicked(HTMLEditorKit.java:674)
    at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
    at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:269)
    at java.awt.Component.processMouseEvent(Component.java:6544)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6306)
    at java.awt.Container.processEvent(Container.java:2237)
    at java.awt.Component.dispatchEventImpl(Component.java:4897)
    at java.awt.Container.dispatchEventImpl(Container.java:2295)
    at java.awt.Component.dispatchEvent(Component.java:4719)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4889)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4467)
    at java.awt.Container.dispatchEventImpl(Container.java:2281)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4719)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
    at java.awt.EventQueue.access$500(EventQueue.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:715)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
    at java.awt.EventQueue$4.run(EventQueue.java:737)
    at java.awt.EventQueue$4.run(EventQueue.java:735)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
    at com.intellij.ide.IdeEventQueue.d(IdeEventQueue.java:821)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:645)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:365)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

这可能是什么原因? 也许没有看到Android SDK?

1 个答案:

答案 0 :(得分:6)

今天这是一个类似的问题 通过添加google maven repo解决了这个问题:

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        url 'https://maven.google.com/' 
        name 'Google'
    }
} 

虽然不是我的想法(我是Android开发的新手,而且只是熟悉Java),我在这里找到答案: https://stackoverflow.com/a/47165271/8036618

不确定原因是什么,但我在代理后面,所以也许IDEA无法从其默认仓库下载,但可以从google maven repo下载?