android studio 1.2 gradle is very slow - android

it's been a while that I'm using Android Studio, and up until now I was using 1.0.1,
gradle was a bit slow, around 1.5 minute for assembleDebug (my project is really big!)
but today I updated my AS to 1.2 and now same process takes about 7 to 10 minutes, and sometimes even with no result!
is there any setting I have to change to make it faster ?
honestly taking 10 minute for every debug run is a nightmare !
Also most of the time, my cpu usage is arround 10 percent! (it is actually idle!)
cause before when gradle was working it was on 100% almost all the time

had the same problem.
What I did was to change the global gradle settings to offline work which can be done by going to Preferences => Gradle. This did make a difference.
Another method I have seen people use, but which I have not used yet is to create a gradle.properties in the gradle folder like so:
Just 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
Please check out this link for more options as well as a detailed explanation on speeding up gradle.
Hope this helps!.

I was testing my app with Google+ log in. So I added release signing to debug version. App compiling in ~ 26 seconds.
build.gradle Module: app file
signingConfigs {
debug {
storeFile file(project.property("MyApp.signing"))
storePassword project.property("MyApp.signing.password")
keyAlias project.property("MyApp.signing.alias")
keyPassword project.property("MyApp.signing.password")
}
}
When I remove that ~ 7.5 seconds.
Next I tested offline grade
File - Settings - Build, Execution... - Build Tools - Gradle - Offline work
Now my app compiling in ~ 4.5 seconds.
Of course I also added turn on
- Compile independent modules in parallel (may require larger heap size)
- Make project automatically (only works while not running / debugging)
File - Settings - Build, Execution... - Compiler

Complete answer for this issue is as below:
Upgrade android studio to version 1.3(stable) or above 1.4(beta at the time of writing this).
Upgrade gradle to 1.3.+(+ can be replaced with some positive number) change it in your build.gradle file.
change your gradle-wrapper.properties files and add distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip in last(you can remove any old entry).
Go to Preference -> Gradle and set it to work offline.
woila!!! I am able to compile and run the code in less then ~5 sec (I really mean it)

The reason could be multiDex,
turn multiDexEnabled to false in your build.gradle file (for debug only, keep it for release).
android {
...
defaultConfig {
...
multiDexEnabled false
...
}
}
In addition you should consider to use the lastest version (2.4 at the moment) by editing the gradle-wrapper.properties file and set gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
What is MultiDex : https://developer.android.com/tools/building/multidex.html

From settings go to HTTP connection and disable any proxy and you will find speed you want

Related

maven-metadata.xml keeps getting requested when building

AGP 4.2.2
gradle-6.7.1
arcticfox 2020.3.1
Everytime I build my android project I see this maven-metadata.xml and it just seems to slow the build and it just seems to hang there. Which can take 10 minutes for each build.
Is there a way to avoid this?
Gradle: Download maven-metadata.xml...
When I run one the command line I see this:
This is my gradle.properties
org.gradle.jvmargs=-Xmx8g -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=256m -XX:+UseCompressedOops -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true
kotlin.coroutines=enable
kotlin.code.style=official
kapt.use.worker.api=true
kapt.incremental.apt=true
android.enableD8.desugaring=true
android.useAndroidX=true
android.enableJetifier=true
I am using some maven repositories as specified here in build.gradle(app):
maven { url "https://www.jitpack.io" }
maven { url 'http://......./repo/maven2' }
maven { url "https://....../repositories/snapshots" }
maven { url 'https://....../maven/release' }
maven { url "http://......./bintray.com/maven" }
maven { url "https://....../objectbox/objectbox" }
Gradle usually needs to download a maven-metadata.xml file, if
you use a dynamic/changing version for one of your dependencies, and
the time to live (TTL) in the dependency cache is over.
For (1) you should look for versions like 1.2.3-SNAPSHOT or 1.2.+ on your declared dependencies (or at ./gradlew dependencies for simplicity). If you have any such versions, do you really need them? Using fixed versions like 1.2.3 should be faster.
For (2), have you maybe changed the default TTL threshold or do you maybe always build with --refresh-dependencies? If not, then the slowness should at least not occur more often than once a day.
If the above doesn’t help, then maybe try running your build with --info or --info --refresh-dependencies and carefully watch the log output. That should show which dependency and/or which repository is the culprit (i.e., the one on which the logging is stuck for the longest time). If you find such a culprit, then you could look into things like
replacing the dependency (or the repository),
improving the speed of the repository server or the network, or
pruning old snapshot versions from the problematic maven-metadata.xml file (if you control the repository).
If all this still doesn’t turn up actionable items, then maybe it could be worth looking for bigger maven-metadata.xml files in your Gradle dependency cache. Maybe the repeated download of such big files is the issue and one of the approaches from the previous list could help. Here’s an idea for how to find the ten biggest maven-metadata.xml files (with a Unix shell command):
find ~/.gradle/caches/modules-2/resources-* \
-name maven-metadata.xml \
-printf '%s\t%p\n' \
| sort -k1 \
| tail
The question is kind of insufficient to tell, because no build.gradle had been provided. But I'd assume, that the reason is any -SNAPSHOT dependency, which is not being cached. Building against a local copy of that dependency should result in not downloading the maven-metadata.xml over and over again; or use mavenLocal(). Building against a stable version should also result in caching.
Other answers give very good context on why this happens. Especially when using -SNAPSHOT dependencies, if you have no other way, I have a trick for you that might help a lot.
It is to use offline mode 🎉
When running via CLI, do
./gradlew someTask --ofline
When running via IDE, enable offline mode.
The cause of slow downloads for maven-metadata.xml files is that one of your proxy repositories has a very slow remote.
This problem will be compounded if either of the "metadata max age" and "not found cache ttl" settings is set too low. Thus it will check the circle too fast and download it everytime from scratch. Turn it up to 12 hours. Default should be 30min (1800sec) what is a too short period of time.
For setting the max age you can simple follow along this site.
Another good article to manage Http Cache Headers.
Chriki answer directed me in the right direction to find a simple solution. After you have downloaded all dependencies (in my case, I am using -SNAPSHOT library, which wants to be updated on every run), you can set Gradle in offline mode. This will prevent Gradle to download new metadata, etc.
In Android Studio you have a dedicated button to toggle online mode (see image
Android studio settings).

Installation failed due to: 'null':Android Studio 3.5.1 Failled in a real device [duplicate]

I tried to install my app into Android L Preview Intel Atom Virtual Device, it failed with error:
INSTALL_FAILED_NO_MATCHING_ABIS
What does it mean?
INSTALL_FAILED_NO_MATCHING_ABIS is when you are trying to install an app that has native libraries and it doesn't have a native library for your cpu architecture. For example if you compiled an app for armv7 and are trying to install it on an emulator that uses the Intel architecture instead it will not work.
INSTALL_FAILED_NO_MATCHING_ABIS is when you are trying to install an app that has native libraries and it doesn't have a native library for your cpu architecture. For example if you compiled an app for armv7 and are trying to install it on an emulator that uses the Intel architecture instead it will not work.
Using Xamarin on Visual Studio 2015.
Fix this issue by:
Open your xamarin .sln
Right click your android project
Click properties
Click Android Options
Click the 'Advanced' tab
Under "Supported architectures" make the following checked:
armeabi-v7a
x86
save
F5 (build)
Edit: This solution has been reported as working on Visual Studio 2017 as well.
Edit 2: This solution has been reported as working on Visual Studio 2017 for Mac as well.
I'm posting an answer from another thread because it's what worked well for me, the trick is to add support for both architectures :
Posting this because I could not find a direct answer and had to look at a couple of different posts to get what I wanted done...
I was able to use the x86 Accelerated (HAXM) emulator by simply adding this to my Module's build.gradle script Inside android{} block:
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
Run (build)... Now there will be a (yourapp)-x86-debug.apk in your output folder. I'm sure there's a way to automate installing upon Run but I just start my preferred HAXM emulator and use command line:
adb install (yourapp)-x86-debug.apk
If you using Genymotion you need Installing ARM Translation and GApps
This is indeed a strange error that can be caused by multidexing your app. To get around it, use the following block in your app's build.gradle file:
android {
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
...[rest of your gradle script]
On Android 8:
apache.commons.io:2.4
gives INSTALL_FAILED_NO_MATCHING_ABIS, try to change it to implementation 'commons-io:commons-io:2.6' and it will work.
This solution worked for me. Try this,
add following lines in your app's build.gradle file
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
I know there were lots of answers here, but the TL;DR version is this (If you're using Xamarin Studio):
Right click the Android project in the solution tree
Select Options
Go to Android Build
Go to Advanced tab
Check the architectures you use in your emulator (Probably x86 / armeabi-v7a / armeabi)
Make a kickass app :)
i had this problem using bitcoinJ library (org.bitcoinj:bitcoinj-core:0.14.7)
added to build.gradle(in module app) a packaging options inside the android scope.
it helped me.
android {
...
packagingOptions {
exclude 'lib/x86_64/darwin/libscrypt.dylib'
exclude 'lib/x86_64/freebsd/libscrypt.so'
exclude 'lib/x86_64/linux/libscrypt.so'
}
}
this worked for me ... Android > Gradle Scripts > build.gradle (Module:app)
add inside android*
android {
// compileSdkVersion 27
defaultConfig {
//
}
buildTypes {
//
}
// buildToolsVersion '27.0.3'
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
}
The comment of #enl8enmentnow should be an answer to fix the problem using genymotion:
If you have this problem on Genymotion even when using the ARM translator it is because you are creating an x86 virtual device like the Google Nexus 10. Pick an ARM virtual device instead, like one of the Custom Tablets.
Visual Studio mac - you can change the support here:
this problem is for CPU Architecture and you have some of the abi in the lib folder.
go to build.gradle for your app module and in android, block add this :
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
In the visual studio community edition 2017, sometimes the selection of Supported ABIs from Android Options wont work.
In that case please verify that the .csproj has the following line and no duplicate lines in the same build configurations.
<AndroidSupportedAbis>armeabi;armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
In order to edit,
Unload your Android Project
Right click and select Edit Project ...
Make sure you have the above line only one time in a build configuration
Save
Right click on your android project and Reload
In my case, in a xamarin project, in visual studio error removed by selecting properties --> Android Options and check Use Share run Times and Use Fast Deployment, in some cases one of them
In my case, I needed to download the x86 version of the application.
Go to https://www.apkmirror.com/
Search for the app
Select the first one in the list
Look at the top of the page, where is has [Company Name] > [Application Name] > [Version Number]
Click the Application Name
Click 'All Variants'
The list should contain an x86 variant to download
For genymotion on mac, I was getting INSTALL_FAILED_NO_MATCHING_ABIS error while installing my apk.
In my project there wasn't any "APP_ABI" but I added it accordingly and it built just one apk for both architectures but it worked.
https://stackoverflow.com/a/35565901/3241111
Basically if you tried Everything above and still you have the same error "Because i am facing this issue before too" then check which .jar or .aar or module you added may be the one library using ndk , and that one is not supporting 8.0 (Oreo)+ , likewise i am using Microsoft SignalR socket Library adding its .jar files and latterly i found out app not installing in Oreo then afterwards i remove that library because currently there is no solution on its git page and i go for another one.
So please check the library you are using and search about it if you eagerly needed that one.
In general case to find out which library dependency has incompatible ABI,
build an APK file in Android Studio (menu Build > Build Bundle(s)/APK(s) > Build APK(s)) // actual on 01.04.2020
rename APK file, replacing extension "apk" with extension "zip"
unpack zip file to a new folder
go to libs folder
find out which *.jar libraries with incompatible ABIs are there
You may try to upgrade version / remove / replace these libraries to solve INSTALL_FAILED_NO_MATCHING_ABIS when install apk problem
Just in case, this might help someone like me.
I had this same issue in Unity 3D. I was attempting to use the emulators from Android Studio.
So I enabled Target Architecture->x86 Architecture(although deprecated) in Player Settings and it worked!
In my case(Windows 10, Flutter, Android Studio), I simply created a new emulator device in Android Studio. This time, I have chosen x86_64 ABI instead of only x86. It solved my issue.
My emulator devices are shown in the screenshot below.
I faced this issue when moved from Android 7(Nougat) to Android 8(Oreo).
I have tried several ways listed above and to my bad luck nothing worked.
So i changed the .apk file to .zip file extracted it and found lib folder with which this file was there /x86_64/darwin/libscrypt.dylib so to remove this i added a code in my build.gradle module below android section (i.e.)
packagingOptions {
exclude 'lib/x86_64/darwin/libscrypt.dylib'
exclude 'lib/x86_64/freebsd/libscrypt.so'
exclude 'lib/x86_64/linux/libscrypt.so'
}
Cheers issue solved
Hi if you are using this library;
implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'
Replace it with:
implementation 'commons-io:commons-io:2.6'
And the problem will be fixed.
This happened to me. I checked the SDK Manager and it told me the one I was using had a update. I updated it and the problem went away.
Quite late, but just ran into this. This is for Xamarin.Android. Make sure that you're not trying to debug in release mode. I get that exact same error if in release mode and attempting to debug. Simply switching from release to debug allowed mine to install properly.
In my case setting folowing options helpet me out
Somehow, this fix the issue out of no reason.
./gradlew clean assemble and then install the app.

Debugging native library: breakpoint is hit in C++, but "Step ..." commands unavailable

I'm using the default "app-native" debug configuration. I simply select it, click "Debug", the app starts and the native breakpoint gets hit soon enough:
However, I cannot step anywhere. It's as if the IDE does not recognize that debugging is already in progress and the execution is halted. As you can see, all the step over / step into and similar actions are unavailable:
Pressing Pause does nothing.
How to fix this?
NDK features are already experimental, but it seems a weird error.
Maybe you have than this steps but, just in case:
Define your as lldb the debugger.
Define your NDK in the path that
you downloaded (NDK11c should be enough)
Use gradle experimental 0.4.0 or 0.7.0 on android root build.gradle project.
Define your ndk module node in app/build.gradle.
gradle experimental:
dependencies
{
classpath 'com.android.tools.build:gradle-experimental:0.4.0'
}
//android ndk-module
android.ndk {
moduleName = "sensorgraph"
cppFlags.add("-Werror")
}
If you try default debug with android studio native examples, the problem should be in LLDB debugger.
Cheers.

Android Studio: Snapshot Dependencies Don't Update properly

I'm working With Android Studio 8.9
I've got a build.gradle with the following dependency defined:
compile ('my.program.commons:my-program-commons:0.0.2-SNAPSHOT#jar')
This dependency is stored in a private Sonatype nexus repository.
When I make changes in the my.program.commons code, I upload to nexus.
The problem is that when I then try to compile against the new SNAPSHOT android studio will fail to pick up changes.
When run from the command line gradle will build succesfully - but Android Studio will not recognize the new files.
If i do a version tick - say from 0.0.2-SNAPSHOT to 0.0.3-SNAPSHOT Android Studio will understand the new version and download and everything works out fine.
I don't want to have to do a minor version tick on every single change.
In my case, use changing = true not work for me. But configure cache changing modules solve my problem. Sample code below, add in build.gradle file:
configurations.all {
// Don't cache changing modules at all.
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
See: https://docs.gradle.org/current/userguide/dependency_management.html
You can also put a flag called "changing" that will trigger Gradle to always pull the latest, for example:
compile ('my.program.commons:my-program-commons:0.0.2-SNAPSHOT#jar') {
changing = true;
}
You need to configure the cache duration, by default gradle won't look for updates for 24 hours:
http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:controlling_caching
In my case, removing the whole <project_root>/.idea/libraries directory, was the only solution that worked. AndroidStudio stores some cached dependencies configurations there. Removing the directory makes it refetch all of them one more time.
You can write some script/task that will automate this removal and run it as part of the Gradle clean task.

Android Gradle Issue

I know there are 100's of questions/answers around this topic, but none of them seem to give me an answer. I know some(if not all) of my problems are around my lack of understanding of gradle in general. BUT, i'm hoping for some help.
I've got my project working just fine on my desktop. I'm traveling this week, and wanted to work on it some on my laptop. I have all the files, and have the same version of Android Studio on both machines. I kept getting all kinds of gradle errors when opening my project. I think I've went on several wild goose chases at this point.
So I decided to step back and just create a NEW basically blank project in Studio. That ALSO has all kinds of gradle issues. I tried uninstalling Android Studio and re-insatlling, and still no dice even getting a basic project to not give the gradle errors.
I am getting
11:12:27 PM Gradle 'MyApplication' project refresh failed:
A fatal exception has occurred. Program will exit.
: Gradle settings
As the error.
Below is my two gradle files.
Top Level File(which was blank in my actual project, but has something in it in the default one)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
The next build file
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:18.0.0'
}
I am using Android Studio 0.4.2
I am at a complete loss of what is going on. I think it could be that Studio is not actually recognizing that this is an android project. I tried some of the gradlew.bat commands and I got an error mentioning that it does not like the "apply plugin: 'android'" entry. But, I have no idea why that would be.
Any thoughts on where I should start would be greatly appreciated. I have no ideas of where to go next, and guessing at it anymore is not an option.
I've got the same issue with IntelliJ IDEA(which Android Studio is based on) on my laptop and found a solution here: https://code.google.com/p/android/issues/detail?id=65219
Set File -> Settings -> Compiler -> Java Compiler -> Additional command line parameters
-Xms256m -Xmx512m
File -> Settings -> Compiler -> Gradle -> VM Options
-XX:MaxHeapSize=256m -Xmx256m
and in YourAppName/build.gradle update dependencies to use newer gradle version
classpath 'com.android.tools.build:gradle:0.9.+'
Then restart Android Studio and everything should be fine. Otherwise you can take a look at full log file by going to Help -> Show Log in Explorer
To add a little more knowledge to the 'Gradle XXXX project refresh failed'
.
Adding following line to
File -> Settings -> Compiler -> Gradle -> VM Options:
-Xmx256m
seems to solve the problem.
.
It is worth noting that it fixes only certain cause of the problem - and there may be many. In my case: the machine I'm using is 32-bit and has very little memory. As a result my compiler couldn't reserve enough memory on the heap and so refused to compile.
Therefore if you don't have much RAM try adding the above line.
If still stuck, try:
https://stackoverflow.com/a/21168562/3508719
Did you verify that you have buildToolsVersion 19.0.1 and compileSdkVersion 19 is available on you machine, since you are working on laptop I believe this is new setup.
Can you go to Tools -> Android -> SDK Manager and see if you need to install any version specified in your gradle script. Or update gradle script as per SDK and build tools you have.
My couple of issue were resolved by updating SDK and tools!

Categories

Resources