【问题标题】:Android Studio using http version of mavenCentralAndroid Studio 使用 http 版本的 mavenCentral
【发布时间】:2021-09-28 23:48:28
【问题描述】:

我刚刚从 Android Studio 4.1.1 更新到 4.2.2。下面是我的项目 build.gradle 文件。由于更新,运行我的应用程序工作正常,但运行测试失败。运行测试的装有 Android Studio 4.1.1 的机器仍然可以工作。

我知道对 maven repo 的请求现在需要 https,但我没有 gradle 文件中的引用。好像 4.2.2 更改了 mavenCentral 存储库以使用 http 而不是 https,否则,我不确定为什么这在 4.1.1 中有效,但在 4.2.2 中无效。有没有办法强制回购是https?

build.gradle

buildscript {
    ext {
        kotlinVersion = '1.3.72'
    }
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:perf-plugin:1.3.1'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
        flatDir {
            // Needs to be here to be included in both misnap and app modules
            dirs project(':misnapworkflow_UX2').file('libs')
        }
    }
}

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

ext {
    buildToolsVersion = '29.0.2'
    compileSdkVersion = 29
    minSdkVersion = 21
    targetSdkVersion = 29

    daggerVersion = '2.27'
    okHttpVersion = '4.7.2'
}

运行测试时出错

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.robolectric.util.ReflectionHelpers$6 (file:/Users/jwhitsit/.gradle/caches/modules-2/files-2.1/org.robolectric/shadowapi/4.3.1/a93e55b36c418aa3afc17c26eac82590a3bfb63e/shadowapi-4.3.1.jar) to method java.lang.ClassLoader.getPackage(java.lang.String)
WARNING: Please consider reporting this to the maintainers of org.robolectric.util.ReflectionHelpers$6
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[Robolectric] com.commercebank.honeybadger.chat.ChatWindowFragmentTest.whenMinimizeClicked_CloseFragment: sdk=28; resources=BINARY
Downloading from maven 
Downloading: org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.pom from repository sonatype at https://oss.sonatype.org/content/groups/public/
Error transferring file: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
[WARNING] Unable to get resource 'org.robolectric:android-all:pom:10-robolectric-5803371' from repository sonatype (https://oss.sonatype.org/content/groups/public/): Error transferring file: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
Downloading: org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.pom from repository central at http://repo1.maven.org/maven2
Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.pom
[WARNING] Unable to get resource 'org.robolectric:android-all:pom:10-robolectric-5803371' from repository central (http://repo1.maven.org/maven2): Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.pom
Downloading: org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.jar from repository sonatype at https://oss.sonatype.org/content/groups/public/
Error transferring file: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
[WARNING] Unable to get resource 'org.robolectric:android-all:jar:10-robolectric-5803371' from repository sonatype (https://oss.sonatype.org/content/groups/public/): Error transferring file: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
Downloading: org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.jar from repository central at http://repo1.maven.org/maven2
Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.jar
[WARNING] Unable to get resource 'org.robolectric:android-all:jar:10-robolectric-5803371' from repository central (http://repo1.maven.org/maven2): Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.jar

Unable to resolve artifact: Missing:
----------
1) org.robolectric:android-all:jar:10-robolectric-5803371

  Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=org.robolectric -DartifactId=android-all -Dversion=10-robolectric-5803371 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=org.robolectric -DartifactId=android-all -Dversion=10-robolectric-5803371 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
    1) org.apache.maven:super-pom:pom:2.0
    2) org.robolectric:android-all:jar:10-robolectric-5803371

----------
1 required artifact is missing.

for artifact: 
  org.apache.maven:super-pom:pom:2.0

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



    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.whileLocked(MavenDependencyResolver.java:95)
    at org.robolectric.internal.dependency.MavenDependencyResolver.getLocalArtifactUrls(MavenDependencyResolver.java:74)
    at org.robolectric.internal.dependency.MavenDependencyResolver.getLocalArtifactUrls(MavenDependencyResolver.java:39)
    at org.robolectric.internal.dependency.MavenDependencyResolver.getLocalArtifactUrl(MavenDependencyResolver.java:107)
    at org.robolectric.internal.dependency.CachedDependencyResolver.getLocalArtifactUrl(CachedDependencyResolver.java:44)
    at org.robolectric.plugins.CachedMavenDependencyResolver.getLocalArtifactUrl(CachedMavenDependencyResolver.java:32)
    at org.robolectric.plugins.LegacyDependencyResolver.getLocalArtifactUrl(LegacyDependencyResolver.java:86)
    at org.robolectric.plugins.DefaultSdkProvider$DefaultSdk.getJarPath(DefaultSdkProvider.java:127)
    at org.robolectric.android.internal.AndroidTestEnvironment.loadAppPackage_measured(AndroidTestEnvironment.java:309)
    at org.robolectric.android.internal.AndroidTestEnvironment.lambda$loadAppPackage$1(AndroidTestEnvironment.java:284)
    at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
    at org.robolectric.android.internal.AndroidTestEnvironment.loadAppPackage(AndroidTestEnvironment.java:282)
    at org.robolectric.android.internal.AndroidTestEnvironment.installAndCreateApplication(AndroidTestEnvironment.java:178)
    at org.robolectric.android.internal.AndroidTestEnvironment.setUpApplicationState(AndroidTestEnvironment.java:169)
    at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:301)
    at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:243)
    at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    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.lang.Thread.run(Thread.java:834)
Caused by: org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
----------
1) org.robolectric:android-all:jar:10-robolectric-5803371

  Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=org.robolectric -DartifactId=android-all -Dversion=10-robolectric-5803371 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=org.robolectric -DartifactId=android-all -Dversion=10-robolectric-5803371 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
    1) org.apache.maven:super-pom:pom:2.0
    2) org.robolectric:android-all:jar:10-robolectric-5803371

----------
1 required artifact is missing.

for artifact: 
  org.apache.maven:super-pom:pom:2.0

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


    at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:360)
    at org.apache.maven.artifact.ant.DependenciesTask.doExecuteResolution(DependenciesTask.java:263)
    ... 23 more


【问题讨论】:

    标签: maven android-studio gradle


    【解决方案1】:

    请尝试将您的 Android Gradle 构建插件升级到

    classpath 'com.android.tools.build:gradle:4.2.2'
    

    或者,作为一种解决方法,您可以尝试将 mavenCentral() 替换为

    maven { url "https://repo.maven.apache.org/maven2" }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-09
      • 2017-07-26
      • 2018-02-09
      • 2013-05-17
      • 2018-12-30
      • 1970-01-01
      • 2020-02-28
      • 2019-04-19
      相关资源
      最近更新 更多