在没有互联网连接的情况下建立项目 [英] Build project without internet connection

查看:76
本文介绍了在没有互联网连接的情况下建立项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于安全原因,我有一个项目需要在脱机模式下进行工作而没有任何互联网连接.我的androidStudio定义为离线模式.当我通过Task/build/assembleRelease运行汇编发布时,一切正常,然后我构建了apk.但是,当通过命令行命令运行时:

I have project that is required to work on in offline mode without any internet connection due to security reasons. My androidStudio defined to offline mode. When I run assemble release via Task/build/assembleRelease everything work just fine and I build my apk. But when running via command line command:

gradlew --offline assembleRelease

我得到了很多错误,而没有这个和那个的兑现版本.当我修复一个错误并将某些文件复制到缓存中时,我得到了新的错误,提示缺少其他内容.

I get bunch of errors than no cashed version of this and that. When I fix one error and copy some files to cache then I get new error that something else missing.

那么,通过androidStudio的assembleRelease如何工作?我如何通过cmd或远程运行同一命令,因为它似乎具有所需的所有缓存.从Studio和从cmd运行assembleRelease有什么区别?

So, how is assembleRelease via androidStudio works? How can I run the same command via cmd or remotely, because it seems have all the cache needed. What is the difference running assembleRelease from studio vs from cmd?

我也知道简单的解决方案,在线运行一次,然后就可以了.无法这样做...

Also I know the simple solution, run it one time online and then it works. Can`t do so...

由于我的PC能够整体构建APK,如果没有androidStudio,我该如何通过cmd或远程构建呢?

As my PC is capable of building APK overall, how can I do so without androidStudio just via cmd or remotely?

推荐答案

首先,让我感到惊讶的是,您可以使用Android Studio构建项目,但不能直接调用Gradle.不同的Gradle版本可能是原因之一,但是由于您已经使用了Gradle包装器,因此不太可能.也许未将Android Studio配置为使用包装器.

First of all, it really surprises me that you can build your project using Android Studio, but not by calling Gradle directly. Different Gradle versions could be one reason, but since you already use the Gradle wrapper, it is rather unlikely. Maybe Android Studio is not configured to use the wrapper.

但是,我绝对建议不要在不同系统的Gradle缓存之间复制依赖项.相反,我鼓励您在离线存储库中收集所需的依赖项,例如 flatDir存储库:

However, I would definitively advise against copying dependencies between the Gradle caches of different systems. Instead, I would encourage you to collect the required dependencies in an offline repository, e.g. a flatDir repository:

repositories {
    flatDir name: 'offlineRepository', dirs: "C:/path/to/repository"
}

遗憾的是,flatDir存储库不支持来自描述符文件(如Maven .pom文件)的传递依赖关系,但是您还可以为本地文件系统位置定义mavenivy存储库:

Sadly, flatDir repositories do not support transitive dependencies from descriptor files like Maven .pom files, but you can also define maven or ivy repositories for a local filesystem location:

repositories {
    maven {
        name = 'offlineRepository'
        url = uri('file:///c:/path/to/repository')
    }
}

如果应该既可以从在线环境也可以从特定的离线环境构建项目,则可以考虑在本地计算机上定义一个初始化脚本,该脚本可以将任何已定义的存储库替换为您的离线环境存储库.

If it should be possible to build your project from both an online and your specific offline environment, you may think about defining an initialization script on your local machine, that substitutes any defined repository with your offline repository.

这篇关于在没有互联网连接的情况下建立项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆