Run Android test with Robolectric - dependency error

前端 未结 2 1932
再見小時候
再見小時候 2021-01-12 16:44

I am using Android Studio 1.2 and Windows 7

When running a robolectric test following this example:

@RunWith(CustomRobolectricRunner.class)
@Config(e         


        
相关标签:
2条回答
  • 2021-01-12 17:14

    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>
    
    0 讨论(0)
  • 2021-01-12 17:16

    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'
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题