Meh*_*esh 57 android gradle android-studio build.gradle android-gradle-plugin
我已经使用Android Studio(我目前的1.5版)2年了.一切都很好,但是当我下载Canary(2.1 p5)时,一切都出错了.每次我想创建一个新项目或打开一个项目或同步或导入一个新的lib或依赖项时,gradle都需要很长时间才能构建 - 将近20分钟.
我没有做任何事情,我刚刚下载了Canary版本并运行它.
症状:
注意: 当我断开互联网连接时,gradle将尽快完成
我试图通过以下方式解决这个问题:
我已经创建了一个新文件(文件名是gradle.properties),C:\Users\username\.gradle然后将这些行写入其中
org.gradle.parallel=true
org.gradle.daemon=true
Run Code Online (Sandbox Code Playgroud)我删除了那个版本,然后安装了我的旧版本工作正常但问题仍然存在:(
禁用/启用防火墙
禁用/启用AntiVirus(Nod32)
重新安装Windows操作系统(8.1)
我已经下载了所有版本(1.0.0,...,1.5.1,2.0.0,2.1)
我用过代理
系统信息:
的build.gradle(项目:应用程序名称)
// 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
}
Run Code Online (Sandbox Code Playgroud)
gradle.build(模块:APP)
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'
}
Run Code Online (Sandbox Code Playgroud)
建设后的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
Run Code Online (Sandbox Code Playgroud)
安装android studio 2.0稳定版后
Meh*_*esh 77
经过2天的搜索,我得到了解决方案,所以我想与所有可能遇到同样问题的人分享.问题是gradle无法连接到某个国家/地区的中心存储库.当您创建新项目或导入时,jcenter()默认情况下您的中心存储库,无论何时您想要构建或同步或添加新的外部依赖项,gradle都将连接到https://bintray.com/但它不能和构建过程要等到连接jcenter(),所以这个过程可能需要很长时间(+30分钟),即使你不能添加新的依赖.
方案:
classpath 'com.android.tools.build:gradle:2.0.0')中的gradle版本是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
}
Run Code Online (Sandbox Code Playgroud)
玩得开心
您可以优化gradle构建过程...
尝试将gradle置于脱机模式下,以强制构建而无需与外部存储库建立任何连接,如下所示:
This helped me a lot, because in my work, all connections are behind a proxy and it increase the build time.
If this is not enough for you, take a time testing the options on the Gradle > Experimental ... Some options may improve you performance:
| 归档时间: |
|
| 查看次数: |
49548 次 |
| 最近记录: |