6

I am using Android Studio 1.2 and Windows 7

When running a robolectric test following this example:

@RunWith(CustomRobolectricRunner.class)
@Config(emulateSdk = 21, reportSdk = 21, constants = BuildConfig.class)
public class PasswordProviderTest{

    @Test
    public void testGetPassword() throws Exception {
        Activity activity = Robolectric.setupActivity(LoginActivity.class);
    }

    @Test
    public void testSetPassword() throws Exception {

    }
}

test result or more the error stacktrace:

    Unable to resolve artifact: Unable to get dependency information: Unable to read the metadata file for artifact 'org.robolectric:android-all:jar': Cannot find parent: org.sonatype.oss:oss-parent for project: org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 for project org.robolectric:android-all:jar:5.0.0_r2-robolectric-1
  org.robolectric:android-all:jar:5.0.0_r2-robolectric-1

from the specified remote repositories:
  sonatype (https://oss.sonatype.org/content/groups/public/),
  central (http://repo1.maven.org/maven2)

Path to dependency: 
    1) org.apache.maven:super-pom:pom:2.0


    at org.apache.maven.artifact.ant.DependenciesTask.doExecuteResolution(DependenciesTask.java:268)
    at org.apache.maven.artifact.ant.DependenciesTask.doExecute(DependenciesTask.java:168)
    at org.apache.maven.artifact.ant.AbstractArtifactTask.execute(AbstractArtifactTask.java:751)
    at org.robolectric.internal.dependency.MavenDependencyResolver.getLocalArtifactUrls(MavenDependencyResolver.java:40)
    at org.robolectric.internal.dependency.CachedDependencyResolver.getLocalArtifactUrls(CachedDependencyResolver.java:42)
    at org.robolectric.RobolectricTestRunner.createRobolectricClassLoader(RobolectricTestRunner.java:151)
    at org.robolectric.RobolectricTestRunner.createSdkEnvironment(RobolectricTestRunner.java:122)
    at org.robolectric.RobolectricTestRunner$3.create(RobolectricTestRunner.java:285)
    at org.robolectric.internal.EnvHolder.getSdkEnvironment(EnvHolder.java:18)
    at org.robolectric.RobolectricTestRunner.getEnvironment(RobolectricTestRunner.java:283)
    at org.robolectric.RobolectricTestRunner.access$300(RobolectricTestRunner.java:50)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:193)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:168)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.maven.artifact.resolver.ArtifactResolutionException: Unable to get dependency information: Unable to read the metadata file for artifact 'org.robolectric:android-all:jar': Cannot find parent: org.sonatype.oss:oss-parent for project: org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 for project org.robolectric:android-all:jar:5.0.0_r2-robolectric-1
  org.robolectric:android-all:jar:5.0.0_r2-robolectric-1

from the specified remote repositories:
  sonatype (https://oss.sonatype.org/content/groups/public/),
  central (http://repo1.maven.org/maven2)

Path to dependency: 
    1) org.apache.maven:super-pom:pom:2.0


    at org.apache.maven.artifact.resolver.DefaultArtifactCollector.recurse(DefaultArtifactCollector.java:430)
    at org.apache.maven.artifact.resolver.DefaultArtifactCollector.collect(DefaultArtifactCollector.java:74)
    at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:316)
    at org.apache.maven.artifact.ant.DependenciesTask.doExecuteResolution(DependenciesTask.java:263)
    ... 46 more
Caused by: org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException: Unable to read the metadata file for artifact 'org.robolectric:android-all:jar': Cannot find parent: org.sonatype.oss:oss-parent for project: org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 for project org.robolectric:android-all:jar:5.0.0_r2-robolectric-1
    at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedProject(MavenMetadataSource.java:200)
    at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedArtifact(MavenMetadataSource.java:94)
    at org.apache.maven.artifact.resolver.DefaultArtifactCollector.recurse(DefaultArtifactCollector.java:387)
    ... 49 more
Caused by: org.apache.maven.project.ProjectBuildingException: Cannot find parent: org.sonatype.oss:oss-parent for project: org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 for project org.robolectric:android-all:jar:5.0.0_r2-robolectric-1
    at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1396)
    at org.apache.maven.project.DefaultMavenProjectBuilder.buildInternal(DefaultMavenProjectBuilder.java:823)
    at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromRepository(DefaultMavenProjectBuilder.java:255)
    at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedProject(MavenMetadataSource.java:163)
    ... 51 more
Caused by: org.apache.maven.project.ProjectBuildingException: POM 'org.sonatype.oss:oss-parent' not found in repository: Unable to download the artifact from any repository

  org.sonatype.oss:oss-parent:pom:7

from the specified remote repositories:
  sonatype (https://oss.sonatype.org/content/groups/public/),
  central (http://repo1.maven.org/maven2)

 for project org.sonatype.oss:oss-parent
    at org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:605)
    at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1392)
    ... 54 more
    Caused by: org.apache.maven.artifact.resolver.ArtifactNotFoundException: Unable to download the artifact from any repository

      org.sonatype.oss:oss-parent:pom:7

    from the specified remote repositories:
      sonatype (https://oss.sonatype.org/content/groups/public/),
      central (http://repo1.maven.org/maven2)


        at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:228)
        at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:90)
        at org.apache.maven.pr

oject.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:558)
    ... 55 more
Caused by: org.apache.maven.wagon.ResourceDoesNotExistException: Unable to download the artifact from any repository
    at org.apache.maven.artifact.manager.DefaultWagonManager.getArtifact(DefaultWagonManager.java:404)
    at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:216)
    ... 57 more

gradle build dependencies:

testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
testCompile 'org.apache.maven:maven-ant-tasks:2.1.3'
testCompile "org.robolectric:robolectric:3.0-rc2"

I find out that the resource, robolectric try to get ,is not avaible. When following the url it trys to get it: https://oss.sonatype.org/content/groups/public/org/sonatype/oss/oss-parent/

there is no oss 7. Why does robolectrics try to get a resource that is not there? And how to get it to work?

Visores
  • 4,008
  • 4
  • 18
  • 29
  • I'm guessing that this is AOSP jar that `Robolectric` uses to have realistic tests – Eugen Martynov Apr 29 '15 at 11:28
  • what does this mean regarding to my problem? – Visores Apr 29 '15 at 12:12
  • Ah, sorry I read it like "why it is downloading dependency that is not in my build gradle file". And this dependency is actually available through maven central (http://search.maven.org/#artifactdetails%7Corg.sonatype.oss%7Coss-parent%7C7%7Cpom). So might you have firewall or proxy issues – Eugen Martynov Apr 29 '15 at 12:33
  • Yes I have a unremovalbe proxy.... but what I also told was that when looking up the resource, the resource does not exist – Visores Apr 29 '15 at 12:34
  • It does not exist in sonatype repository but does exist in maven central – Eugen Martynov Apr 29 '15 at 12:37
  • okay, and where I have to configurate, that the proxy get used right? – Visores Apr 29 '15 at 12:42
  • Maybe this could help http://stackoverflow.com/questions/5991194/gradle-proxy-configuration – Eugen Martynov Apr 29 '15 at 12:47
  • adding this to VM-option doesn help and also enter in console does not work. Any other point to add proxy settings? – Visores Apr 29 '15 at 12:51

3 Answers3

5

This seems to be a proxy problem. When behind proxy you have to specify proxy settings for maven at {userHome}/.m2/settings.xml

my settings.xml looks now like:

<settings>
    <proxies>
        <proxy>
            <active>true</active>
            <host>proxy.host</host>
            <port>3128</port>
        </proxy>
    </proxies>
</settings>

below not working !!

<settings>
    <proxies>
        <proxy>
            <id>proxy-https</id>
            <active>true</active>
            <protocol>https</protocol>
            <host>proxy.host</host>
            <port>3128</port>
        </proxy>
        <proxy>
            <id>proxy-http</id>
            <active>true</active>
            <protocol>http</protocol>
            <host>proxy.host</host>
            <port>3128</port>
        </proxy>
    </proxies>
</settings>
Visores
  • 4,008
  • 4
  • 18
  • 29
0

I've been able to fix the same issue by overriding Robolectric Maven repository URL.

Sonatype is not available for some reason and Maven Central moved to HTTPS starting from Jan 15, 2020. So, I've decided to use Maven Central URL but with a secure scheme.

Editing the system property which is used by Robolectric RoboSettings class allowed me to use a different URL.

android {
    testOptions {
        unitTests.all {
            systemProperty 'robolectric.dependency.repo.url', 'https://repo1.maven.org/maven2'
        }
    }
}
Visores
  • 4,008
  • 4
  • 18
  • 29
vchornenyi
  • 336
  • 5
  • 17
  • It works only for Robolectric 4.0+, please check this commit adding those system properties: https://github.com/robolectric/robolectric/commit/5f85c0dcd3642950c458864accf6fea67265f3da#diff-258d2ffac3be70a232b114e76e80588d – Paweł Jan 30 '20 at 15:09
  • 1
    @Pawel that's not correct. Your commit adds other props, but the prop in questions was added 4 years ago in 3.1: https://github.com/robolectric/robolectric/commit/d56f48b520427488f7d406d295cf7bc5ecd12925 – colriot Feb 18 '20 at 13:13
  • 2
    its not working for me.Still android studio try to download from Sonatype and failing. "Downloading: org/robolectric/android-all/4.1.2_r1-robolectric-r1/android-all-4.1.2_r1-robolectric-r1.pom from repository sonatype at https://oss.sonatype.org/content/groups/public/ Error transferring file: Connection timed out: connect [WARNING] Unable to get resource 'org.robolectric:android-all:pom:4.1.2_r1-robolectric-r1' from repository sonatype (https://oss.sonatype.org/content/groups/public/): Error transferring file: Connection timed out: connect " – Sandeep Cg Mar 26 '20 at 16:50
  • 2
    @SandeepCg faced the same thing just a couple of hours ago, but currently it is back to normal, I have performed two test executions and both passed successfully, seems like temporary connection issues with Sonatype repo, huh – RAM237 Mar 30 '20 at 13:31
0

I had this error when i run the Robolectric tests with JRE 11.

Going to Run/Debug Configurations and change it to JRE 1.8 may fix your problem.

Step 1: Run/Debug Configurations

Step 2: Change JRE