我已经使用Android Studio(当前版本为1.5)已有2年了。一切都很好,但是当我下载Canary(2.1 p5)时,一切都出错了。每当我想创建一个新项目或打开一个项目或同步或导入一个新的lib或依赖项时,gradle的构建时间都太长了-将近20分钟。
我什么也没做,只是下载了Canary版本并运行了。
症状 :
注意:当我断开Internet连接时,gradle将尽快完成
我试图通过以下方法解决此问题:
我在中创建了一个新文件(文件名为gradle.properties
),C:\Users\username\.gradle
然后将这些行写入其中
org.gradle.parallel=true
org.gradle.daemon=true
我删除了该版本,然后安装了可以正常运行的旧版本,但问题仍然存在:(
禁用/启用防火墙
禁用/启用防病毒(Nod32)
重新安装Windows OS(8.1)
我已经下载了所有版本(1.0.0,...,1.5.1、2.0.0、2.1)
我已经使用了代理
系统信息:
build.gradle(Project:appName)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle.build(模块:应用程序)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.test.myapplication"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.3.0'
}
构建后的Gradle报告
Dependencies Duration
All dependencies 14m3.43s
:app:_releaseCompile 3m30.96s
:app:_debugCompile 3m30.73s
:app:_debugApk 3m30.69s
:app:_releaseApk 3m30.62s
:classpath 0.428s
:app:_debugAndroidTestCompile 0.001s
:app:_debugAndroidTestApk 0s
:app:_debugUnitTestApk 0s
:app:_debugUnitTestCompile 0s
:app:_releaseUnitTestApk 0s
:app:_releaseUnitTestCompile 0s
:app:releaseWearApp 0s
:app:wearApp 0s
安装android studio 2.0稳定版后
经过2天的搜索,我找到了解决方案,所以我想与所有可能遇到相同问题的人分享。问题是gradle
在某些国家/地区无法连接到中心存储库。当您创建一个新项目或import时,jcenter()
默认情况下,您的中心存储库是默认的,并且每当您要构建或同步或添加新的外部依赖项时,gradle
它都会连接到https://bintray.com/,但无法进行构建过程将要等到连接jcenter()
,所以此过程可能需要很长时间(+30分钟),即使您不能添加新的依赖项也是如此。
解决方案 :
classpath 'com.android.tools.build:gradle:2.0.0'
)中为2.0.0因此,您可以在3秒内轻松添加新的依赖项并同步项目!
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
玩得开心
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句