Nice programing

Android 빌드 gradle이 너무 느림 (종속성 해결)

nicepro 2020. 12. 30. 20:22
반응형

Android 빌드 gradle이 너무 느림 (종속성 해결)


저는 2 년 동안 Android Studio (현재 버전 1.5)로 작업했습니다. 모든 것이 괜찮 았지만 Canary (2.1 p5)를 다운로드했을 때 모든 것이 잘못되었습니다. 새 프로젝트를 만들거나 프로젝트를 열거 나 새 라이브러리 또는 종속성을 동기화하거나 가져올 때마다 Gradle은 빌드하는 데 너무 오래 걸립니다 . 거의 20 분 정도 걸립니다 .

나는 아무것도하지 않았고, 카나리아 버전을 다운로드하여 실행했습니다.

증상 :

  1. 인터넷에 연결했을 때 발생했습니다
  2. 첫 번째 지연은 Gradle : 종속성 해결 ': app : _debugCompile'
  3. ...
  4. 25 분 후 거의 완성

참고 : 인터넷 연결을 끊으면 Gradle이 최대한 빨리 완료됩니다.


나는 다음과 같은 방법으로 이것을 고치려고 노력했다 .

  1. gradle을 오프라인 작업으로 변경했습니다 (작동했지만 lib 또는 종속성을 가져오고 싶기 때문에 이런 식으로 원하지 않습니다)
  2. 새 파일 (파일 이름은 gradle.properties)을 C:\Users\username\.gradle만든 다음이 줄을 썼습니다.

    org.gradle.parallel=true
    org.gradle.daemon=true
    
  3. 해당 버전을 제거한 다음 정상적으로 작동하는 이전 버전을 설치했지만 문제는 여전히 존재합니다.

  4. 방화벽 비활성화 / 활성화

  5. 안티 바이러스 비활성화 / 활성화 (Nod32)

  6. Windows OS (8.1) 재설치

  7. 모든 버전 (1.0.0, ..., 1.5.1, 2.0.0, 2.1)을 다운로드했습니다.

  8. 프록시를 사용했습니다


시스템 정보 :

  • CPU : 인텔 코어 i5
  • RAM : 6.00GB
  • 운영체제 : Windows 8.1 64 bit

build.gradle (프로젝트 : 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 (Module : 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'
}

빌드 후 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 안정 버전 설치 후

  • 7:23:47 PM Gradle 동기화 시작 ====> 8:13:21 PM Gradle 동기화 완료

문제가 해결되었습니다!

2 일 검색 후 해결책을 찾았으므로 같은 문제가있을 수있는 모든 사람들과 공유하고 싶습니다. 문제는 gradle일부 국가에서 센터 저장소에 연결할 수 없다는 것입니다. 새 프로젝트를 만들거나 가져올 때 센터 저장소는 jcenter()기본적으로이며 새 외부 종속성을 빌드하거나 동기화하거나 추가 할 때마다 https://bintray.com/gradle 에 연결할 수 있지만 빌드 프로세스는 할 수 없습니다. 연결될 때까지 기다릴 것이므로 새 종속성을 추가 할 수없는 경우에도이 프로세스에 오랜 시간 (+30 분)이 걸릴 수 있습니다.jcenter()

해결책 :

  1. 안정적인 최신 버전 (현재 2.0.0)이 있는지 확인하세요.
  2. gradle 버전이 build.gradle ( classpath 'com.android.tools.build:gradle:2.0.0') 에서 2.0.0인지 확인하십시오.
  3. 마지막 단계이자 가장 중요한 단계는 jcenter ()mavenCentral ()변경하는 것입니다.

따라서 새 종속성을 쉽게 추가하고 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
}

재미있게


gradle 빌드 프로세스를 최적화 할 수 있습니다.

다음과 같이 외부 저장소에 연결하지 않고 빌드하도록 강제로 오프라인 모드로 gradle을 설정하십시오.

여기에 이미지 설명 입력 여기에 이미지 설명 입력

제 작업에서 모든 연결이 프록시 뒤에 있고 빌드 시간이 늘어나 기 때문에 이것은 저에게 많은 도움이되었습니다.

이것이 충분하지 않다면 Gradle> Experimental ...에서 옵션을 테스트하는 데 시간을 할애하십시오. 일부 옵션은 성능을 향상시킬 수 있습니다.

여기에 이미지 설명 입력


위의 @Mehdi Jahed Manesh 답변 외에도.

다음 org.gradle.jvmargs과 같은 속성을 사용하여 Gradle Daemon VM에 할당 된 메모리 양을 최소 2Gb로 1Gb 늘립니다 .

org.gradle.jvmargs=-Xmx2048m

Once the initial build has completed try enabling offline Mode from the gradle settings. So that every consecutive builds will not start resolving dependencies, instead it gets from the cache. If you add a new dependency it will prompt you to disable offline mode and rebuild it. gradle 미리보기 이미지


Like Ismail Iqbal's answer said, put gradle under offline mode works for me.

  1. If you're using android studio, follow Fabio Filho's answer

  2. If you're using command line like me, you can try

gradlew assembleReleaseStaging(your task name) --offline

For those who use repositories that require authentication, this issue may be solved by configuring gradle to use only a single auth scheme:

repositories {
    maven {
        credentials {
            username INTERNAL_REPO_USERNAME
            password INTERNAL_REPO_PASSWORD
        }
        // here comes the important part
        authentication {
            basic(BasicAuthentication)
        }
        url INTERNAL_REPO_URL
    }
}

It turned out that upon authenticating against repositories, gradle attempts authentication using all kind of schemes. The above config makes gradle only use basic auth. Here is the full list of available schemes.


In my case, I solved it by installing a new version of the Java JDK. After installing the new JDK, open AS, go to File→Project Structure→SDK Location, and change JDK location to that of the new version of the Java JDK. Then you will be asked for firewall permission; check Public and apply. Let it resolve gradle.


I have seen another issue. The solution might help someone

Recently i have set http_proxy and https_proxy under system environment variables. I had to remove both of them and then set the proxy in studio settings.


change classpath 'com.android.tools.build:gradle:1.5.0' to

classpath 'com.android.tools.build:gradle:2.0.0'

and change buildToolsVersion "23.0.3" to

buildToolsVersion "23.0.2"

android studio 2.0 안정 버전을 사용하십시오. 더 자세한 정보를 원하거나이 솔루션이 효과가 없음을 알려주십시오.

참조 URL : https://stackoverflow.com/questions/36529301/android-build-gradle-is-too-slow-dependency-resolution

반응형