Why is there an "UnknownHostException" in my first flutter project? - android-studio

So I trying to make an app in Flutter SDK and downloaded its plugin in android studio and its SDK from the official website but it is showing an error in the first project I run I didn't write a single piece of code. I don't know why is this error coming up.
Running Gradle task 'assembleDebug'...
Exception in thread "main" java.net.UnknownHostException: services.gradle.org
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
at org.gradle.wrapper.Download.download(Download.java:44)
at org.gradle.wrapper.Install$1.call(Install.java:61)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Finished with error: Gradle task assembleDebug failed with exit code 1

For the record the same error occurred for me. Not sure how it happened but the issue had to do with incorrect lines in "build.gradle".
Project-level build.gradle should have
classpath 'com.google.gms:google-services:4.3.5'
App-level build.gradle should have
apply plugin: 'com.google.gms.google-services'
Mine were changed to different domains. I suspect it was VS Code modifying them as i was jumping between VS Code and Android Studio.

Related

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

I encountered "Gradle project sync failed" on Android Studio 4.2 and some of the class members are mostly red. I have done some troubleshooting as below.
File->Sync Project with Gradle Files
File-> invalidates caches/restart
Restart Android Studio
Clean and Rebuild
Try deleting .gradle
However, the problem still persists. What went wrong actually?
Trace logfiles:
2021-05-12 17:50:44,928 [24467617] WARN - ues.SyncIssueUsageReporterImpl - Multiple sync failures reported. Discarding: SDK_BUILD_TOOLS_TOO_LOW
2021-05-12 17:50:44,928 [24467617] WARN - ues.SyncIssueUsageReporterImpl - Multiple sync failures reported. Discarding: SDK_BUILD_TOOLS_TOO_LOW
2021-05-12 17:50:44,929 [24467618] INFO - adleSyncState$SyncStateUpdater - onFailure(RESOLVE_PROJECT:5, com.intellij.openapi.externalSystem.model.ExternalSystemException: A problem occurred configuring project ':app'.)
2021-05-12 17:50:44,929 [24467618] INFO - cState$SyncStateUpdaterService - stopTrackingTask(RESOLVE_PROJECT:5)
2021-05-12 17:50:44,929 [24467618] WARN - e.project.sync.GradleSyncState - Gradle sync failed: A problem occurred configuring project ':app'. (3 s 326 ms)
2021-05-12 17:50:44,930 [24467619] WARN - e.project.sync.GradleSyncState - A problem occurred configuring project ':app'.
com.intellij.openapi.externalSystem.model.ExternalSystemException: A problem occurred configuring project ':app'.
at org.jetbrains.plugins.gradle.service.execution.GradleExecutionErrorHandler.createUserFriendlyError(GradleExecutionErrorHandler.java:153)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectImportErrorHandler.createUserFriendlyError(AbstractProjectImportErrorHandler.java:46)
at org.jetbrains.plugins.gradle.service.project.BaseProjectImportErrorHandler.doGetUserFriendlyError(BaseProjectImportErrorHandler.java:181)
at org.jetbrains.plugins.gradle.service.project.BaseProjectImportErrorHandler.getUserFriendlyError(BaseProjectImportErrorHandler.java:45)
at org.jetbrains.plugins.gradle.service.project.BaseProjectImportErrorHandler.checkErrorsWithoutQuickFixes(BaseProjectImportErrorHandler.java:59)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$1.getUserFriendlyError(GradleProjectResolver.java:798)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:745)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:720)
at org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper.lambda$execute$0(GradleExecutionHelper.java:128)
at org.jetbrains.plugins.gradle.GradleConnectorService.withGradleConnection(GradleConnectorService.java:246)
at org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper.execute(GradleExecutionHelper.java:114)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:142)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:64)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.lambda$resolveProjectInfo$0(RemoteExternalSystemProjectResolverImpl.java:37)
at com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:43)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:36)
at com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:46)
at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:102)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:147)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:133)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$2.executeImpl(ExternalSystemUtil.java:523)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$2.lambda$execute$1(ExternalSystemUtil.java:372)
at com.intellij.openapi.project.DumbServiceHeavyActivities.suspendIndexingAndRun(DumbServiceHeavyActivities.java:20)
at com.intellij.openapi.project.DumbServiceImpl.suspendIndexingAndRun(DumbServiceImpl.java:153)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$2.execute(ExternalSystemUtil.java:372)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$4.run(ExternalSystemUtil.java:631)
at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:935)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsync$5(CoreProgressManager.java:442)
at com.intellij.openapi.progress.impl.ProgressRunner.lambda$null$3(ProgressRunner.java:235)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:170)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:629)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:581)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:157)
at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:235)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
I had faced the same problem.
Solution:
If your Android Studio version is 4.2.2 and your app contains more than one modules then make sure to keep the targetSdkVersion and compileSdkVersion as same for all your build.gradle files(including your modules).
I have just experienced this issue seemingly out of thin air, and found the cause:
I updated the google play services ads module to:
api 'com.google.android.gms:play-services-ads:20.1.0'
This causes the gradle sync to fail.
Looking into the IDEA log I found the line com.android.tools.idea.gradle.project.sync.idea.issues.SdkPlatformNotFoundException: Module: 'my-module' platform 'android-28' not found.
So I updated my-module to use the targetSdkVersion 29 and the build works again.
Please Downgrade Studio Version to 4.1.3
Currently, 4.2.* versions are having the significant number of issues.
You maybe need to upgrade or downgrade your "targetSdkVersion"
i experienced the same issue and the solution was upgrading my "targetSdkVersion"

How to solve this Error : Gradle task assembleDebug failed with exit code 1

I installed Android Studio 4.1 and installed all of SDK and JDK 8 and etc.
When I want to run this flutter run in my project, I see this error:
C:\Users\Farshad\Desktop\myapp>flutter run
Launching lib\main.dart on Nokia 6 1 in debug mode...
Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 403 Request blocked by Privoxy"
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2152)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2739)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2651)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1830)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:268)
at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
at org.gradle.wrapper.Download.download(Download.java:44)
at org.gradle.wrapper.Install$1.call(Install.java:61)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 17.9s
[!] Gradle threw an error while downloading artifacts from the network. Retrying to download...
Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 403 Request blocked by Privoxy"
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2152)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2739)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2651)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1830)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:268)
at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
at org.gradle.wrapper.Download.download(Download.java:44)
at org.gradle.wrapper.Install$1.call(Install.java:61)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 8.9s
[!] Gradle threw an error while downloading artifacts from the network. Retrying to download...
Exception: Gradle task assembleDebug failed with exit code 1
if you are from iran and cuba or syria or other some other countries
this error will be showing
because of filtering, i think android studio forbade those countries
you can use vpn and try again please tell me the result

I'm new to flutter and I ran into an error while running my first app

Finished with error: ProcessException: Process "C:\Users\Saheed\AndroidStudioProjects\testin_app\android\gradlew.bat" exited abnormally:
Downloading https://services.gradle.org/distributions/gradle-4.10.2-all.zip
Exception in thread "main" java.net.UnknownHostException: services.gradle.org
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)`
You Simply Need to Install android 9 and 8 in SDK Section. After installation restarts your IDE.
Image
Click here for Image Guide

Upgraded AndroidStudio to 3.4.1 and gradle problems

I have upgraded an Android Project from 3.2 to 3.4.1 and now I have gradle Problems.
The only indication is the bar at the top
and a message in the Event Log.
Gradle sync failed: EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue#34e0424
Current thread: Thread[ApplicationImpl pooled thread 19,4,Idea Thread Group] 388194366
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,Idea Thread Group] 847161915 (1 s 526 ms)
I have cleaned rebuilt project.
Clicking on Open Build View -> nothing happens.
Log File contains:
INFO - e.project.sync.GradleSyncState - Finished source generation of project 'Chronica'.
2019-05-26 10:04:57,336 [thread 126] INFO - ule.android.SdkModuleSetupStep - Set Android SDK 'Android API 26 Platform' (C:\Users\andreas\AppData\Local\Android\Sdk) to module 'LVLLibrary'
2019-05-26 10:04:57,340 [thread 126] INFO - ule.android.SdkModuleSetupStep - Set Android SDK 'Android API 28 Platform' (C:\Users\andreas\AppData\Local\Android\Sdk) to module 'app'
2019-05-26 10:04:57,425 [thread 126] INFO - e.project.sync.GradleSyncState - Gradle sync failed: EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue#34e0424
Current thread: Thread[ApplicationImpl pooled thread 126,4,Idea Thread Group] 812028699
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,Idea Thread Group] 847161915 (852 ms)
2019-05-26 10:04:57,425 [thread 126] WARN - ject.sync.ng.SyncResultHandler - Gradle sync failed
com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue#34e0424
Current thread: Thread[ApplicationImpl pooled thread 126,4,Idea Thread Group] 812028699
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,Idea Thread Group] 847161915
at com.intellij.openapi.application.impl.ApplicationImpl.assertIsDispatchThread(ApplicationImpl.java:1133)
at com.intellij.openapi.application.impl.ApplicationImpl.assertIsDispatchThread(ApplicationImpl.java:1122)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:289)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:282)
at com.intellij.openapi.vfs.encoding.EncodingProjectManagerImpl.tryStartReloadWithProgress(EncodingProjectManagerImpl.java:361)
at com.intellij.openapi.vfs.encoding.EncodingProjectManagerImpl.reloadAllFilesUnder(EncodingProjectManagerImpl.java:366)
at com.intellij.openapi.vfs.encoding.EncodingProjectManagerImpl.setEncoding(EncodingProjectManagerImpl.java:180)
at com.intellij.openapi.vfs.encoding.EncodingProjectManagerImpl.setDefaultCharsetName(EncodingProjectManagerImpl.java:408)
at com.android.tools.idea.gradle.project.sync.validation.android.EncodingValidationStrategy.fixAndReportFoundIssues(EncodingValidationStrategy.java:83)
at com.android.tools.idea.gradle.project.sync.validation.android.AndroidModuleValidator$AndroidModuleValidatorImpl.fixAndReportFoundIssues(AndroidModuleValidator.java:63)
at com.android.tools.idea.gradle.project.sync.ng.AndroidModuleProcessor.processAndroidModels(AndroidModuleProcessor.java:63)
at com.android.tools.idea.gradle.project.sync.ng.SyncProjectModelsSetup.setUpModules(SyncProjectModelsSetup.java:143)
at com.android.tools.idea.gradle.project.sync.ng.ProjectSetup$ProjectSetupImpl.setUpProject(ProjectSetup.java:69)
at com.android.tools.idea.gradle.project.sync.ng.SyncResultHandler.setUpProject(SyncResultHandler.java:136)
at com.android.tools.idea.gradle.project.sync.ng.SyncResultHandler.onSyncFinished(SyncResultHandler.java:88)
at com.android.tools.idea.gradle.project.sync.ng.SyncResultHandler.lambda$onCompoundSyncModels$6(SyncResultHandler.java:268)
at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Howto analyse this, How to get a meaningfull message. Its very frustrating to be blind every upgrade of Androidstudio.
Is there a way to execute the sync by console / terminal ?
Update
I could restrict the case. I found out this happens only if I am adding a android library (module). I can't understand why thi happens.
Update 2
I found the solution for me. The upgrade process added the following into my gradle script, which caused the problem. After removing it worked:
compileOptions.encoding = 'ISO-8859-1'
productFlavors {
}
The question is still open. How can we analyse this kind of issue in a professional way. I had to compare files without knowing without any contextual path.
It was good for me.
Download some components:
I used this trick to fix the problem I had with my gradle. First get a good internet connection and go to your local disk C: \Users \YourUsername. You will see a .gradle file there. Delete it and run android studio again for it to download everything again.
Though not in Android Studio 3.4.1, but I got a very similar error message in a newer version (4.1.3), so I ended up here.
For me the problem was that Kotlin version that is used for Gradle differed from the IDE plugin version.
The message was:
Gradle sync failed: EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue#3e2d155f
Current thread: Thread[ApplicationImpl pooled thread 6,4,Idea Thread Group] 219783907
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,Idea Thread Group] 255359391
Make sure that ext.kotlin_version in your buildscript is the same as the plugin version (File/Settings/Plugins in Android Studio 4.1.3).

Gradle robolectric project works on OSX computer but not on Linux

I'm using the same version of Gradle, 1.7 jdk thus not exactly the same version.
The main complain of the testing is :
java.lang.NoClassDefFoundError:
org/apache/maven/artifact/ant/DependenciesTask Caused by:
java.lang.ClassNotFoundException:
org.apache.maven.artifact.ant.DependenciesTask
I've tried to clean gradle cache in order to re download all dependencies.
Also i've tried to clean the project.
This didn't work.
What variables can affect the execution of a gradle test ?
To me there is:
Gradle itself
Java version of the sdk
Internet connections problems
What else can be interfering ? Are plugin versions platform dependant ?
Executing task ':robolectric-tests:test' (up-to-date check took 0.432 secs) due to:
Output file /home/ec2-user/repositories/MyProject/robolectric-tests/build/test-results has changed.
Output file /home/ec2-user/repositories/MyProject/robolectric-tests/build/reports/tests has changed.
Output file /home/ec2-user/repositories/MyProject/robolectric-tests/build/test-results/binary/test has changed.
Starting process 'Gradle Test Executor 1'. Working directory: /home/ec2-user/repositories/MyProject/robolectric-tests Command: /usr/java/jdk1.7.0_72/bin/java -Djava.security.manager=jarjar.org.gradle.process.internal.child.BootstrapSecurityManager -Dfile.encoding=UTF-8 -Duser.country=ES -Duser.language=ca -Duser.variant -ea -cp /home/ec2-user/.gradle/caches/2.3/workerMain/gradle-worker.jar jarjar.org.gradle.process.internal.launcher.GradleWorkerMain 'Gradle Test Executor 1'
Successfully started process 'Gradle Test Executor 1'
Gradle Test Executor 1 started executing tests.
Gradle Test Executor 1 finished executing tests.
com.tubtale.MyProject.robolectrictests.tests.RobTMyAndroidClassTest > testWhenActivityCreatedHelloTextViewIsVisible2 FAILED
java.lang.NoClassDefFoundError: org/apache/maven/artifact/ant/DependenciesTask
Caused by:
java.lang.ClassNotFoundException: org.apache.maven.artifact.ant.DependenciesTask
com.tubtale.MyProject.robolectrictests.tests.RobTMyAndroidClassTest > testWhenActivityCreatedHelloTextViewIsVisible FAILED
java.lang.NoClassDefFoundError: org/apache/maven/artifact/ant/DependenciesTask
2 tests completed, 2 failed
Finished generating test XML results (0.217 secs) into: /home/ec2-user/repositories/MyProject/robolectric-tests/build/test-results
Generating HTML test report...
Finished generating test html results (0.11 secs) into: /home/ec2-user/repositories/MyProject/robolectric-tests/build/reports/tests
:robolectric-tests:test FAILED
:robolectric-tests:test (Thread[main,5,main]) completed. Took 4.005 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':robolectric-tests:test'.
> There were failing tests. See the report at: file:///home/ec2-user/repositories/MyProject/robolectric-tests/build/reports/tests/index.html
* Try:
Run with --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':robolectric-tests:test'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:306)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:169)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: org.gradle.api.GradleException: There were failing tests. See the report at: file:///home/ec2-user/repositories/MyProject/robolectric-tests/build/reports/tests/index.html
at org.gradle.api.tasks.testing.Test.handleTestFailures(Test.java:1118)
at org.gradle.api.tasks.testing.Test.executeTests(Test.java:549)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:218)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:585)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:568)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 44 more
BUILD FAILED
I also ran into this issue on Linux but not OSX. I found a work-around by adding
org.apache.maven:maven-ant-tasks:2.1.3
to my 'testCompile' dependencies.
dependencies {
repositories {
mavenCentral()
}
testCompile 'junit:junit:4.12'
testCompile 'org.apache.maven:maven-ant-tasks:2.1.3'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.mockito:mockito-all:1.9.5'
}
I don't know why maven-ant-tasks isn't getting fetched on linux. It appears to be a valid dependency of robolectric.
The selected answer is correct, and also applies when upgrading Gradle from 2.2.1 to 2.3 on OSX. If you don't add the dependency for testCompile 'org.apache.maven:maven-ant-tasks:2.1.3' then Robolectric tests will fail when the Gradle version is 2.3.
Also noteworthy is that I have a separate module for my Robolectric tests, so I added the new dependency to the build.gradle file in my Robolectric module, NOT my Android app module.
Just got a new Mac, so my old Mac & new Mac are side by side, while I configure the new one. I used Homebrew to build up my new Mac, and wasn't aware that Gradle 2.3 had just been released... That's why the Robolectric tests worked on my old Mac (with Gradle 2.2.1) but not on my new Mac (with Gradle 2.3).

Resources