Can';t在脱机模式下生成&引用;没有androidx的缓存版本列表。fragment:fragment:[1.2.0]可用于脱机模式;

Can';t在脱机模式下生成&引用;没有androidx的缓存版本列表。fragment:fragment:[1.2.0]可用于脱机模式;,android,android-studio,Android,Android Studio,我希望能够脱机处理我的项目。因此,我禁用脱机模式,按下“与gradle文件同步项目”按钮,然后启用脱机模式并尝试构建。但是,每次我这样做时,都会出现以下错误: FAILURE: Build failed with an exception. *What went wrong: Could not determine the dependencies of task ':app:compileDebugRenderscript'. > Could not resolve all ta

我希望能够脱机处理我的项目。因此,我禁用脱机模式,按下“与gradle文件同步项目”按钮,然后启用脱机模式并尝试构建。但是,每次我这样做时,都会出现以下错误:

FAILURE: Build failed with an exception.

*What went wrong:

Could not determine the dependencies of task ':app:compileDebugRenderscript'.
  > Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
      > Could not resolve androidx.fragment:fragment:[1.2.0].
        Required by
           project :app > androidx.fragment:fragment-ktx:1.2.0
               > No cached version listing for androidx.fragment:fragment:[1.2.0] available for offline mode.
               > No cached version listing for androidx.fragment:fragment:[1.2.0] available for offline mode. 
我还尝试过在启用脱机模式之前使缓存/重新启动无效,然后进行梯度同步,得到了相同的结果

我正在运行Android Studio 3.6.3

gradle-wrapper.properties包含以下文件夹:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

如何使androidx.fragment:fragment可用于脱机模式?

很可能存在依赖项解析问题。当多个组件使用相同的依赖项但版本不同时,Gradle会联机确定要使用哪个版本。这在离线模式下显然不起作用

我假设您正在其他地方使用不同的片段依赖项(
androidx.fragment:fragment
),默认情况下在联机模式下选择该依赖项。现在处于脱机模式,由于无法进行此类检查,Gradle查找版本
1.2.0
(androidx.fragment:fragment ktx:1.2.0)但找不到,因为从未下载/缓存过

更好的解决方案是尝试使依赖项引用冲突子依赖项的相同版本。您可以使用
/gradlew app:dependencies
检查依赖关系树,并更新冲突的依赖关系,以便它们使用相同的版本(如果可能)

另一种解决方案是在Gradle中强制实施依赖关系。您可以向
build.gradle
文件中添加类似的内容:

configurations.all {
    resolutionStrategy {
        if (project.gradle.startParameter.offline) {
            // x.y.z being the version that Gradle picks in the online mode.
            force 'androidx.fragment:fragment:x.y.z'
        }
    }
}


希望您已经完成了这里提到的所有解决方案。完整构建而不是渐变同步是否正确地准备缓存?