由于gradle,无法在Mac上使用android studio

时间:2015-11-09 03:50:57

标签: android android-studio gradle

  

错误:无法使用指定的Gradle分发' https://services.gradle.org/distributions/gradle-2.4-all.zip'来创建工具API实施的实例。

尝试了一切,Android Studio仍然无效。重新安装10次,清除所有.gradle .android文件夹。从头开始创建示例项目。尝试更改gradle版本。什么都没有效果。

没有系统gradle,我的Java版本是javac 1.8.0_40

gradle配置的内容

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

以下是idea.log的内容

2015-11-08 22:40:39,654 [ 471024]   WARN - nal.AbstractExternalSystemTask - Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'. 
com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectImportErrorHandler.createUserFriendlyError(AbstractProjectImportErrorHandler.java:106)
    at org.jetbrains.plugins.gradle.service.project.BaseProjectImportErrorHandler.getUserFriendlyError(BaseProjectImportErrorHandler.java:158)
    at org.jetbrains.plugins.gradle.service.project.BaseGradleProjectResolverExtension.getUserFriendlyError(BaseGradleProjectResolverExtension.java:438)
    at com.android.tools.idea.gradle.project.AndroidGradleProjectResolver.getUserFriendlyError(AndroidGradleProjectResolver.java:348)
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.getUserFriendlyError(AbstractProjectResolverExtension.java:164)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:366)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:332)
    at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:225)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:97)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:65)
    at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:41)
    at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:37)
    at com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:59)
    at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:37)
    at com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:49)
    at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:51)
    at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:138)
    at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:124)
    at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$4.execute(ExternalSystemUtil.java:540)
    at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$5$2.run(ExternalSystemUtil.java:621)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:563)
    at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:152)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$1.run(ProgressManagerImpl.java:126)
    at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:400)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)
    at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)

2015-11-08 22:40:39,655 [ 471025]   WARN - radle.project.ProjectSetUpTask -  
2015-11-08 22:40:39,655 [ 471025]   INFO - radle.project.ProjectSetUpTask - Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.

Consult IDE log for more details (Help | Show Log) 
2015-11-08 22:40:39,655 [ 471025]   INFO - ls.idea.gradle.GradleSyncState - Sync with Gradle for project 'My Application' failed: Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.

根据我单独安装gradle的建议,我必须修复此错误https://issues.gradle.org/browse/GRADLE-1451但我现在有ANDROID_HOME,gradle定义和gradle --version工作。

------------------------------------------------------------
Gradle 2.7
------------------------------------------------------------

Build time:   2015-09-14 07:26:16 UTC
Build number: none
Revision:     c41505168da69fb0650f4e31c9e01b50ffc97893

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_40 (Oracle Corporation 25.40-b25)
OS:           Mac OS X 10.9.5 x86_64

**但我仍然从Android Studio收到同样的错误。同样以奇怪的方式,它只是拒绝接受gradle主文件夹,总是显示Gradle主文件夹不正确的错误,即使我使用lib或bin子目录时仍然存在错误。它会自动切换回包装器。 **

错误:无法使用指定的Gradle安装' / Users / aub3 / gradle'创建工具API实施的实例。

根据使用' gradle build'等命令构建时我收到以下错误

:app:compileReleaseSources
:app:preDexRelease
:app:dexRelease
:app:packageRelease
:app:assembleRelease
:app:assemble
:app:compileLint
:app:lint
Ran lint on variant debug: 4 issues found
Ran lint on variant release: 4 issues found
Wrote HTML report to file:/Users/aub3/IdeaProjects/Dsdsadasd/app/build/outputs/lint-results.html
Wrote XML report to /Users/aub3/IdeaProjects/Dsdsadasd/app/build/outputs/lint-results.xml
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:processDebugUnitTestJavaRes UP-TO-DATE
:app:compileDebugUnitTestJavaWithJavac
:app:compileDebugUnitTestSources
:app:mockableAndroidJar
:app:assembleDebugUnitTest
:app:testDebugUnitTest
java.lang.ClassCastException: ch.qos.logback.classic.LoggerContext cannot be cast to org.gradle.logging.internal.slf4j.OutputEventListenerBackedLoggerContext
    at org.gradle.logging.internal.slf4j.Slf4jLoggingConfigurer.configure(Slf4jLoggingConfigurer.java:42)
    at org.gradle.logging.internal.DefaultLoggingConfigurer.configure(DefaultLoggingConfigurer.java:34)
    at org.gradle.logging.internal.LoggingSystemAdapter.setLevel(LoggingSystemAdapter.java:55)
    at org.gradle.logging.internal.LoggingSystemAdapter.on(LoggingSystemAdapter.java:42)
    at org.gradle.logging.internal.DefaultLoggingManager$StartableLoggingSystem.start(DefaultLoggingManager.java:191)
    at org.gradle.logging.internal.DefaultLoggingManager.start(DefaultLoggingManager.java:60)
    at org.gradle.logging.internal.DefaultLoggingManager.start(DefaultLoggingManager.java:31)
    at org.gradle.process.internal.child.ImplementationClassLoaderWorker.execute(ImplementationClassLoaderWorker.java:58)
    at org.gradle.process.internal.child.ImplementationClassLoaderWorker.execute(ImplementationClassLoaderWorker.java:41)
    at org.gradle.process.internal.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:49)
    at org.gradle.process.internal.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:33)
    at jarjar.org.gradle.process.internal.launcher.GradleWorkerMain.run(GradleWorkerMain.java:69)
    at jarjar.org.gradle.process.internal.launcher.GradleWorkerMain.main(GradleWorkerMain.java:74)
:app:testDebugUnitTest FAILED

FAILURE: Build failed with an exception.

我终于通过gradle installDebug任务使用命令行来组装android项目并安装在devide上。然而,Android Studio仍然不起作用。

  

错误:无法使用指定的Gradle安装' / Users / aub3 / gradle'创建工具API实施的实例。

解决

我可以让gradle包装器使用以下

  

DEFAULT_JVM_OPTS =" -Djava.ext.dirs ="

但是,无法在Android Studio中使用此设置。 与我在网上看到的不同,有多个目录

[java.ext.dirs] = /Users/aub3/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java.

我去了每个目录并删除了Loggers,sl4j和其他人的Jar文件。有了这个,我就能让Android Studio工作。

2 个答案:

答案 0 :(得分:2)

检查/ Library / Java / Extensions中的冲突。

就我而言,我有一些logback-classic.jar,logback-core.jar,slf4j-api.jar和xuggle-xuggler.jar都是从某个目录/ usr / local / xuggler / share / java /软链接的jars /(我不记得可能已安装它的东西)。

我只是将这些文件(或链接)放在一边,现在我可以从命令行和Android Studio中使用Gradle。 (我创建了一个脚本来恢复软链接以防我的设置在其他地方被破坏,但到目前为止,我没有遇到任何问题。)

答案 1 :(得分:0)

您可以在网站上下载GRADLE。 Gradle Download。 保存在任何目录上(例如:/Users/ihojose/Documents/gradle)。

  1. 打开控制台并添加系统变量。
  2. vi ~/.profile
    
    1. 将以下文本复制并粘贴到.profile文件中:
    2. GRADLE_HOME=/Users/ihojose/Documents/gradle;
      export GRADLE_HOME
      export PATH=$PATH:$GRADLE_HOME/bin
      
      1. 在控制台中测试gradle
      2. gradle -version
        
        1. 如果结果与此类似:
        2. ------------------------------------------------------------
          Gradle 1.0-rc-3
          ------------------------------------------------------------
          
          Gradle build time: Monday, Novenber 9, 2015 16:10:52 PM UTC
          Groovy: 1.8.6
          Ant: Apache Ant(TM) version 2.6.0 compiled on October 21 2015
          Ivy: 2.2.0
          JVM: 1.8.0_68 (Apple Inc. 20.6-b01-415)
          OS: Mac OS X 11.0.1 x64
          
          1. 定义ANDROID_HOME Click here for How to define ANDROID_HOME
          2. 现在您可以使用Android Studio。