Gradle Build Speeds - android

I created a new project in Android Studio yesterday, after creating it with just one blank activity it consistently too in excess of 14 Minutes to build. Looking at a previous project that has multiple activities that compiles in less than 4 Seconds I noticed the following differences in my build.gradle file
Fast Compile(4 Seconds) has the following
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
Slow Compile (>14 Minutes) has the following
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
}
I changed the new project to use the dependencies from the old project and surprise it to built in less than 4 seconds.
What is going on here? Am I doing something wrong, missing something obvious?
Thanks in advance.

When you compile project, it checks dependencies and download if! required. Thats whould be the reason why it took. Since downloading operation is executed once, next builds will be more speedy.
On the other hand if you did download operation before (which is previous project), gradle can use from local disk. It makes it faster.

Related

Android studio broke up my build.gradle file after add a Fragment

Using Android Studio 2.0 over El Capitan like the next screenshot said:
I found a bug that I can't report:
After add a Fragment to my project, AS screw up my module build.gradle file. I mean, before add the fragment they file looks like this screenshot:
but after add the Fragment AS screw it in this way:
The way to reproduce it is like I'm showing in next screenshot:
I can fix it manually, but its so annoying doing it every single time that I add a Fragment. Is there anyway to fix it?
I'm on Mac OX with El Capitan.
It is a still open bug, you can monitor it's state here
The bug is due to the comments in the dependencies section, a temporal fix could be to remove them from there. I placed the comments there for a reason too :)
Delete all comments in your gradle file
put your constraint-layout on the bottom, it will not scramble again (i don't know why, but it works)
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// support lib
compile "com.android.support:appcompat-v7:$supportlib_version"
// kotlin
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
// ...
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
just reformat your project level gradle . It will work fine. These compile statement got dis-formatted. Just hit Enter before every "compile"
it should be like:
compile 'com.android.support:support-v13:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'

Android Unable to execute dex error after cloning correct project

This is a really strange problem and I've been days stuck with it: we've got a working project (no errors whatsoever) in a git repository. Everything is OK (it's even published in Google Play) when executing the project from the creator's equip, but, when we try to clone it in a different equip (we've tried Mac, Linux and Windows), this exception is thrown:
Unable to execute dex: method ID not in [0, 0xffff]: 65536
Hereafter, even if we apply the multidex solution as described in Android Developers or delete the unused dependencies, the app raises an exception when trying to load class android.support.design.widget.NavigationView (coming from a NoClassDefFound in runtime).
I suspect maybe it has something to do with the gradle plugin or appcompat libs version, but so far, nothing we've tried has worked.
Edit: This is not a common multiDex error, I'm pretty familiarized about how to solve them, it's about one computer executing the app without problems but when you clone the same project from git in other computer, it won't run and the MultiDex error is thrown.
EDIT 2: mi dependenvy list is as follows (I ommit the company libs but they're not the problem
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.mo2o.third:valnif:1.0.0'
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile('com.afollestad.material-dialogs:core:0.8.0.1#aar') {
transitive = true
}
compile 'com.android.support:percent:23.0.0'
compile 'se.emilsjolander:stickylistheaders:2.6.0'
compile 'me.grantland:autofittextview:0.2.+'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile "com.google.android.gms:play-services-gcm:8.3.0"
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.squareup.picasso:picasso:2.5.2'

simple login application with parse.jar gives 'java.lang.NoClassDefFoundError: com.parse.ParseUser'

I am working on a simple login android application in android studio with parse. Just a few backs I switched in to studioo from ecclipse so I am not much familier with that. I am refering the following tutorial.parse tutorial
I have done everything as they mentioned. Added parse.jar[add in to libs folder and settings file updated ] and update app gradile file.
But when I tried to run the application , it crashes.java.lang.NoClassDefFoundError: com.parse.ParseUser.
If anybody have any idea about my issue please help me to solve it. I didn't find any similar questions thats why posting.
My app gradile file have below lines.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
} and we can't add dependencies to outer [main] gradile file..right?...there is
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Have you added a compile command to your build.gradle file?
For example:
compile fileTree(dir: 'libs', include: ['*.jar'])

Why my app is errors when I just create it?

I use android studio with sdk v24.
When I create my new application and just go to the MainActivity.jar It shows me many codes red?
Here it is that I'm talking about:(screen shot)
https://dl.dropboxusercontent.com/u/100174344/Screenshot%202015-01-06%2008.06.09.png
I'm really confused. How can I fix these errors?
NOTE: my sdk is up to date (as you see here: https://dl.dropboxusercontent.com/u/100174344/Screenshot%202015-01-06%2008.22.28.png )
and I've added this code to my build.gradle(Module: app) :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3' }
EDIT:
I'm sorry I create a new project and still it show me the codes, red but I can run it in AVD. what's the problem?
You want To add android.support.v7.jar not added that y i think this error occurs.
add this in your project property file
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.+'
}
Did you added android.support.v7.jar? Just make sure your sdk is updated and you've added android.support.v7.jar. Also check the dependencies.
You need to add appcompat v7 dependencies to the app gradle file.
Ensure build.gradle(Module : app) is having the dependency.
If not available then add and sync the project
It should be like-
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.+'
}
I found the problem
I don't know why but when I changed the theme by this structure the issue is up.

Android Studio with Gradle incompatibility (Google Play Services issue)

I am developing an android app with Android Studio 0.8.9. I am using Gradle to build my project.
I want to include google-play-services.jar file into my project in order to use push notification api.
I have added those statements into my gradle (application layer) file as follows:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/google-play-services.jar')
compile files('libs/android-support-v4.jar')
compile files('libs/gson-2.2.3.jar')
compile files('libs/volley_23042014.jar')
compile 'com.google.android.gms:play-services:5.2.08'
}
but it never works. I get the following error:
Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;
I've checked bunch of websites (including Stackoverflow.com). None of them has worked for me.
I have latest versions of Google Support Library, Google Support Repository, Google Play Services.
Here is my libs directory
My SDK version like:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="20" />
What I have done wrong? If anyone has any idea please let me know.
If you're including Play Services via:
compile 'com.google.android.gms:play-services:5.2.08'
you don't need this:
compile files('libs/google-play-services.jar')
so just remove it.
Since the first line of your dependencies will make it automatically pick up any jar files you put in your libs directory:
compile fileTree(dir: 'libs', include: ['*.jar'])
make sure you remove the jars from there as well.
For that matter, there are other libraries you shouldn't include via specific jars.
Instead of this:
compile files('libs/android-support-v4.jar')
compile files('libs/gson-2.2.3.jar')
use this:
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.code.gson:gson:2.2.3
(Note that later versions of GSON are available).

Categories

Resources