Programing

Android Studio gradle을 빌드하는 데 시간이 너무 오래 걸림

lottogame 2020. 5. 1. 07:58
반응형

Android Studio gradle을 빌드하는 데 시간이 너무 오래 걸림


Android Studio 프로젝트는 더 빨리 빌드하는 데 사용되었지만 이제는 빌드하는 데 시간이 오래 걸립니다. 지연을 일으킬 수있는 아이디어가 있습니까? https://stackoverflow.com/a/27171878/391401 을 시도 했지만 효과가 없습니다. 빌드를 방해 할 수있는 안티 바이러스가 실행 중이 아닙니다. 내 앱은 크기가 크지 않고 (약 5MB ) 몇 초 내에 빌드되었지만 무엇이 변경되었는지 확실하지 않았습니다.

10:03:51 Gradle build finished in 4 min 0 sec  
10:04:03 Session 'app': running  
10:10:11 Gradle build finished in 3 min 29 sec  
10:10:12 Session 'app': running  
10:20:24 Gradle build finished in 3 min 42 sec  
10:28:18 Gradle build finished in 3 min 40 sec  
10:28:19 Session 'app': running  
10:31:14 Gradle build finished in 2 min 56 sec   
10:31:14 Session 'app': running  
10:38:37 Gradle build finished in 3 min 30 sec  
10:42:17 Gradle build finished in 3 min 40 sec  
10:45:18 Gradle build finished in 3 min 1 sec  
10:48:49 Gradle build finished in 3 min 30 sec  
10:53:05 Gradle build finished in 3 min 22 sec  
10:57:10 Gradle build finished in 3 min 19 sec  
10:57:11 Session 'app': running  

Android Studio에서 파일-> 설정-> 빌드, 실행, 배포-> 빌드 도구-> Gradle로 이동하십시오.

(Mac의 경우) Android Studio- > 환경 설정 ...-> 빌드, 실행, 배포-> 빌드 도구-> Gradle

'전 세계 Gradle 설정'에서 '오프라인 작업'을 확인하십시오.

gradle 빌드 시간이 90 % 단축됩니다.

빌드 시간을 줄이려면 이것을 확인하십시오

gradle에 새 종속성을 방금 추가 한 경우 오프라인 작업 을 선택 취소해야합니다. 그렇지 않으면 gradle이 종속성을 해결할 수 없습니다. 완전한 해결 후 더 빠른 빌드를 위해 오프라인 작업확인할 수 있습니다


Google Play 서비스를 사용하는 경우 Gradle 빌드 스크립트에서이를 사용하지 않아야합니다.

compile 'com.google.android.gms:play-services:8.3.0'

앱에서 실제로 사용중인 Google API 만 사용하십시오. 사용중인 모든 것이 Google지도 인 경우 다음을 사용합니다.

com.google.android.gms:play-services-maps:8.3.0

이 작업을 수행 할 때 컴파일 시간이 2 분 이상에서 약 25 초로 단축되었습니다. 선택적으로 컴파일 할 수있는 Google API 목록은 다음을 참조하십시오.

https://developers.google.com/android/guides/setup


gradle을 만드는 가장 쉽고 쉬운 방법을 찾았습니다.

go to your app >> open your gradle.properties and change few lines from it [remove #]

else you may copy paste my below snippet as well

    # Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx2048m -XX:MaxPermSize=512m
 org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
 org.gradle.parallel=true

it worked for me earlier it take almost 2-3 minutes now it is taking only 5-6 second

in above scenario my mac machine have 8GB ram so i assigned 4gb for gradle


Found the reason!! If Android Studio has a proxy server setting and can't reach the server then it takes a long time to build, probably its trying to reach the proxy server and waiting for a timeout. When I removed the proxy server setting its working fine.

Removing proxy: File > Settings > Appearance & Behavior > System settings > HTTP Proxy


Following the steps will make it 10 times faster and reduce build time 90%

First create a file named gradle.properties in the following directory:

/home/<username>/.gradle/ (Linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)

Add this line to the file:

org.gradle.daemon=true

org.gradle.parallel=true

Enabling Java 8 features caused deadly slow build

gradle

 jackOptions {
        enabled true
  }

  compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
}

After deleting above lines, it builds in seconds.

There is issue Compiling with Jack takes very long time

Project Manager's Answer

We're aware that build times are an issue with Jack right now. We have improvements in the 2.4 Gradle plugin that should be a significant improvement for incremental builds.

As of now, latest Gradle version i can find is 2.3.0-beta4


Recommended Reading: How I save 5h/week on Gradle builds!

According to this excellent post you should try to optimized the following:

  • Gradle Daemon
  • Parallel Project Execution
  • Configure projects on demand
  • Modules are expensive...

@AndroidDev solution worked for me. I had included the whole lib in gradle.

compile 'com.google.android.gms:play-services:8.4.0'

Changing to solved the problem. From 4 min to 1 min.

compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'

Thnx


Check your Internet connection. If internet speed is very slow gradle build will also take long time to build. I check by change my wifi internet connection with another one good speed connection. Now build time is normal. Please try this before you go to other solutions. somebody will take wrong decision to reinstall or change settings. I hope it will help. Thanks and regards.


1) My build time severely increased after i added some new library dependencies to my gradle file, what turned out that i need to use multidex after that. And when i set up multidex correctly then my build times went up to 2-3 minutes. So if you want faster build times, avoid using multidex, and as far as possible, reduce the number of library dependencies.

2) Also you can try enabling "offline work" in android studio, like suggested here, that makes sense. This will not refetch libraries every time you make a build. Perhaps slow connection or proxy/vpn usage with "offline work" disabled may lead to slow build times.

3) google services - as mentioned here, dont use the whole bundle, use only the needed parts of it.


In the beta version of Android studio 2.0, they've rolled out a feature called Instant Run. It reduces the build time by a big factor. The core concept is, Android Studio only pushes the small changes made into an already running app.

It classifies the changes we make in our code to three parts: hot swap, warm swap and cold swap, based on how much load would the change would put on the build. After that, it simply swaps the code in the already running app and we get could see the changes running a few seconds. See their doc for more information.

Here you can download Android Studio 2.0 preview.

PS: There are a few issues with this feature. They've listed it out at the docs. Check it out before installation.


  1. Go to File->Setting-->Gradle-->Set it to offline mode and check

I was facing the same problem for a long time but I solved it by adjusting the settings in gradle.

Step 1:In Module app add dependency in BuildScript

buildscript {
 dependencies {
         classpath 'com.android.tools.build:gradle:2.0.0-alpha9'
}
}

Step 2: Add dexOption and give the following heapSize

  dexOptions {
    incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "4g"
}

Step 3: Add productFlavors

    productFlavors {
    dev {
        minSdkVersion 23
        applicationId = "com.Reading.home"
    }
    prod {
        minSdkVersion 15
        applicationId = "com.Reading.home" // you don't need it, but can be useful

    }
}

This should reduce your build time.


If you're using Windows 8...

DroidArc and AndroidDev solutions where useful, but not enougth. My problem was related with my Windows 8 OS and its 100% disk usage.

Especially the Windows Search service, was the most consuming. Disable it with: cmd(Admin) >net.exe stop "Windows search"

I followed the directions in this link and it solved the problem for real 4 Tips to Fix 100% Disk Usage & Improve Windows Performance

Hope this helps.


I had the same issue in kotlin. Updating the outdated kotlin runtime solved it for me


I had issues like this especially when debugging actively through my phone; at times it took 27 minutes. I did the following things and take note of the explanation under each - one may work for you:

  1. Changed my gradle.properties file (under Gradle scripts if you have the project file view under Android option OR inside your project folder). I added this because my computer has some memory to spare - you can assign different values at the end depending on your computer specifications and android studio minimum requirements (Xmx8000m -XX:MaxPermSize=5000m) :

org.gradle.daemon=true

org.gradle.configureondemand=true

org.gradle.parallel=true

android.enableBuildCache=true

org.gradle.caching=true

org.gradle.jvmargs=-Xmx8000m -XX:MaxPermSize=5000m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

  1. This did not completely solve my issue in my case. Therefore I also did as others had suggested before - to make my builds process offline:

File -> Settings/Preferences -> Build, Execution, Deployment -> Gradle

Global Gradle Settings (at the bottom)

Mark the checkbox named: Offline Work.

  1. This reduced time substantially but it was erratic; at times took longer. Therefore I made some changes on Instant Run:

File -> Settings/Preferences -> Build, Execution, Deployment -> Instant Run

Checked : Enable Instant Run to hot swap code...

Checked: restart activity on code changes ...

  1. The move above was erratic also and therefore I sought to find out if the problem may be the processes/memory that ran directly on either my phone and computer. Here I freed up a little memory space in my phone and storage (which was at 98% utilized - down to 70%) and also on task manager (Windows), increased the priority of both Android Studio and Java.exe to High. Take this step cautiously; depends on your computer's memory.

  2. After all this my build time while debugging actively on my phone at times went down to 1 ~ 2 minutes but at times spiked. I decided to do a hack which surprised me by taking it down to seconds best yet on the same project that gave me 22 - 27 minutes was 12 seconds!:

Connect phone for debugging then click RUN

After it starts, unplug the phone - the build should continue faster and raise an error at the end indicating this : Session 'app': Error Installing APKs

Reconnect back the phone and click on RUN again...

ALTERNATIVELY

If the script/function/method I'm debugging is purely JAVA, not JAVA-android e.g. testing an API with JSONArrays/JSONObjects, I test my java functions/methods on Netbeans which can compile a single file and show the output faster then make necessary changes on my Android Studio files. This also saves me a lot of time.

EDIT

I tried creating a new android project in local storage and copied all my files from the previous project into the new one - java, res, manifest, gradle app and gradle project (with latest gradle classpath dependency). And now I can build on my phone in less than 15 seconds.


You could try the tips in this post Why your Android Studio takes forever to build - Part 2 One of the tips recommmends "Enable offline mode" among other things.


In my case Gradle sync was so long because of one dependency that is located on amazonaws. It was a transitive dependency that can be disabled


In your build.gradle, if you have minifyEnabled for debug, remove it. I had it in my project and it took ~2-3 minutes to build. After looking at build progress, I found this as culprit, so deleting the commented line below, my issue was fixed.

buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }//debug{
         //   minifyEnabled true
         //   proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}

I had a similar issue on my computer. Windows Defender was blocking some part of Gradle Building. I've disabled it, worked fine after that.


Try restarting your computer and running Android Studio again. Worked for me when trying to build a Cordova / Phonegap project with an Android target codebase.

참고URL : https://stackoverflow.com/questions/29391421/android-studio-gradle-takes-too-long-to-build

반응형