如何使用Gradle构建离线构建Android Cordova项目?

时间:2016-11-29 14:51:32

标签: android cordova maven android-gradle

我有一个Ionic / Cordova项目,Android版本是用Gradle完成的。

我安装了所有必要的Android SDK,该项目已经构建好几个月了,但今天它失败并出现以下错误:

Running: d:\git\myproject\platforms\android\gradlew cdvBuildDebug -b d:\git\myproject\platforms\android\build.gradle -Dorg.gradle.daemon=true

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:1.0.0+.
     Required by:

BUILD FAILED

Total time: 26.792 secs
         :android:unspecified
      > Failed to list versions for com.android.tools.build:gradle.
         > Unable to load Maven meta-data from https://repo1.maven.org/maven2/com/android/tools/build/gradle/maven-metadata.xml.
            > Could not GET 'https://repo1.maven.org/maven2/com/android/tools/build/gradle/maven-metadata.xml'.
               > Connection to https://repo1.maven.org refused

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

d:\git\myproject\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                    ^
Error code 1 for command: cmd with args: /s /c "d:\git\myproject\platforms\android\gradlew cdvBuildDebug -b d:\git\myproject\platforms\android\build.gradle -Dorg.gradle.daemon=true"
Error: cmd: Command failed with exit code 1
Cordova command failed with error code 1, aborting!

显然,由于项目构建好几个月,所有需要构建的东西已经在磁盘上,但构建可能正在检查Maven仓库中是否有更新版本的工件,这是失败。

这有时不是一种非常理想的行为。

是否可以将构建配置为始终脱机构建?

1 个答案:

答案 0 :(得分:0)

所以我为com.android.tools.build:gradle搜索了我的回购邮件,我在几个文件中找到了它:

D:\git\myproject\platforms\android\build.gradle\build.gradle
D:\git\myproject\platforms\android\cordova\lib\plugin-build.gradle\plugin-build.gradle
D:\git\myproject\platforms\android\CordovaLib\build.gradle\build.gradle

我改变了

dependencies {
    classpath 'com.android.tools.build:gradle:1.0.0+'
}

dependencies {
    classpath 'com.android.tools.build:gradle:1.0.0'
}

希望这可以解决我的问题,虽然问题现在已经消失,即使1.0.0+,所以我无法轻易验证。

在Windows上,您可以在以下文件夹中查看本地可用的com.android.tools.build:gradle的确切版本:

$HOME\.gradle\caches\modules-2\files-2.1\com.android.tools.build\gradle