I use Android Studio to build my android application. But my laptop take 5 mins to build app. I don't know why. It's always load to build gradle too slow. Here is my code Build Gradle :
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
repositories { mavenCentral() }
defaultConfig {
applicationId "thsoft.com.sosme"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.wang.avi:library:1.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.jakewharton:disklrucache:2.0.2'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.crittercism:crittercism-android-agent:5.5.0-rc-1'
}
Could you help me to solved it? Thank you!
There is nothing wrong with the gradle code, but way too many dependencies. It depends on your processor's speed and memory. Try getting 8gb of memory and you'll be just fine. According to official site, minimum requirement is 4gb!!
Try enable offline mode to ignore up-to-date checks:
http://tools.android.com/recent/androidstudio040released
Or change build type to Debug :
Build Variants - > Debug ( Bottom Left corner AS)
Gluck!
Install the latest Android Studio 2.0 preview release. Its just awesome and it will reduce the gradle build time for sure. Let's try
to increase your build time you just need to increase your RAM
and in your gradle file remove those dependencies which are not required.
You have used play services which is huge. If you are using Google Cloud Messaging use com.google.android.gms:play-services-gcm:8.3.0. definitely it will reduce your build time. Don't put whole play services. Be specific which play service you are using.
this Link may help you https://developers.google.com/android/guides/setup
Good Luck
Related
Receving this error on KitKat and lower version running perfectly on Lollipop and above
I have included all the required jars in th gradle and Firebase json file to receive GCM.
my app gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
defaultConfig {
applicationId ""
minSdkVersion 13
targetSdkVersion 23
versionCode 6
versionName "1.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
defaultConfig {
multiDexEnabled true
}
useLibrary 'org.apache.http.legacy'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':httpmime-4.2.5')
compile project(':universal-image-loader-1.9.3')
compile project(':universal-image-loader-1.9.3')
compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.3'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.android.support:design:23.4.0'
compile 'com.google.android.gms:play-services:9.0.0'
testCompile 'junit:junit:4.12'
}
This dependency includes the code for all of the Google Play Services APIs:
compile 'com.google.android.gms:play-services:9.0.0'
This is very likely causing your app to exceed the 65K method reference limit, requiring you to use Multidex to run on pre-Lollipop devices.
You have two choices. You can include only the Play Services APIs you actually need. The list is here in the section titled Selectively compiling APIs into your executable. Or you can enable Multidex following the instructions here. Although you have multiDexEnabled true in your build.gradle file, that is only one of the three steps required to configure Multidex. You also need to include the library as a dependency and update your manifest.
If you are using Android Studio 2.2.2, you can see how many method references are in your app using the APK Analyzer. From the menubar, select Build > Analyze APK. The APK is in folder .../app/build/outputs/apk. Select the APK file, and in the resulting window, click on classes.dex to see the number of methods and method references.
Please update the firebase dependencies
dependencies {
...
compile 'com.google.firebase:firebase-messaging:9.6.0'
...
}
apply plugin: 'com.google.gms.google-services'
Hope it helps..
Working on a project pulled from bitbucket. Whenever I'm trying to build the gradle, the following error shows.
Gradle sync failed: Illegal char at index 2: C\:\\Program Files (x86)\\Android\\android-sdk\analytics.settings
This project is working absolutely fine in other member's computer who pulled from the same repository. (one of them is actually the one who uploaded everything in the first place, works obviously fine in his system).
Now I am not able to understand the error message at all. I don't know what illegal character it's mentioning of.
Thank you in advance!
build.gradle(Project)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.firebase:firebase-config:9.4.0'
compile 'com.google.firebase:firebase-invites:9.4.0'
compile 'com.google.firebase:firebase-ads:9.4.0'
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.vinaygaba:creditcardview:1.0.3'
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
}
apply plugin: 'com.google.gms.google-services'
Edit
I tried deleting the project and tried checking out from version control again. But now it wont even open the project since gradle cant be built.
I tried both the options but it always shows the following error
Edit 2
Please note that my others projects are building fine. So the problem has to be with this particular project
I too faced the same issue and now its resolved.Check if you are using the latest sdk version or not and update it if not.After you update the sdk, also cross check if your system environment variables are located properly.Then restart the project.
My app is working properly. There is no problem. i want to build generated signed apk. The problem is building take too long and completed with errors.
Please check the image. Thanks.
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
here my gradle;
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "umut.com.anyidea"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.firebase:firebase-messaging:9.6.0'
compile 'com.google.firebase:firebase-core:9.6.0'
compile 'com.google.firebase:firebase-crash:9.6.0'
compile 'com.google.android.gms:play-services:9.6.0'
compile 'com.google.android.gms:play-services-auth:9.6.0'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.afollestad.material-dialogs:core:0.9.0.1'
compile 'com.google.firebase:firebase-database:9.6.0'
compile 'com.google.firebase:firebase-auth:9.6.0'
compile 'com.firebaseui:firebase-ui-database:0.6.0'
}
apply plugin: 'com.google.gms.google-services'
In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.
From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs,
Please refer this document:
https://developers.google.com/android/guides/setup
for example if you need Google Account Login then just use :
com.google.android.gms:play-services-auth:9.6.1 not use compile 'com.google.android.gms:play-services:9.6.1'
just add this and try.
its works for me.
defaultConfig {
multiDexEnabled true
}
// multidex issues
compile 'com.android.support:multidex:1.0.0'
or
dexOptions {
javaMaxHeapSize "4g"
}
Have you add this in Application class
MultiDex.install(this);
Put this line in defaultConfig block
multiDexEnabled true
And add the following dependencies
compile 'com.android.support:multidex:1.0.0'
After this rebuild your project. Hopefully this should resolve your error.
Just remove unused libraries (or dependencies) from app's build.gradle file and again try to generate signed apk. It will work. :)
I tried to add a CardView in my app so I added the following dependency in my gradle
compile 'com.android.support:cardview-v7:22.2.1'
I realised that an error is caused because I have given the wrong version number. After taking a look at the official google docs I came to know that Android Support Repository is used to hold appcompat libraries.
As you can see the Support repository that I have installed is version 33. But if I change my gradle to version 33 it is still showing error.
How can I check what version of AppCompatLibrary I have in android studio?
EDIT:
build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 22
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.spintum.preexam"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
// compile fileTree (dir:'libs',include:'achartengine-*.jar')
//compile fileTree('libs/achartengine-1.1.0.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:percent:22.2.0'
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:cardview-v7:+'
//compile 'com.android.support:recyclerview-v7:22.2.+'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-location:8.3.0'
compile 'com.android.support:multidex:1.0.0'
compile 'com.github.markushi:circlebutton:1.1'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32#aar'
}
Check your SDK folder and see which is the highest existing number:
e.g
B:\android-sdk\extras\android\m2repository\com\android\support\appcompat-v7
There will be a folder for each installed version. At the time of writing, 24 is the latest version.
Update:
Now Google use their own Maven repository, this no longer works.
Instead, check this site for the available versions.
https://maven.google.com/
It is not about the installed version of the Android Support Repository.
The version that should be in the Gradle Build Files should be the number highest version corresponding to your
compileSdkVersion
in your AppLevel Gradle Build File.(by default it is the app module).
Example:
If you are using compileSdkVersion 23 , then you should check your following directory for the highest 23.x.x folder.
\ YOUR-SDK-PATH
\extras\android\m2repository\com\android\support\cardview-v7
Suppose that your highest number starting from 23 is 23.4.0 , then you should use this version number(23.4.0 replacing the 33.0.0) for your Gradle Build File(Not the verison of Android Support Repository Installed).
It means you have to use the Android Support Repository Libraries according to your compileSdkVersion.
The easist way is to use + which means the newest one (of the API level) on your machine, then you do not need to check the SDK folder anymore. e.g.,
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.android.support:support-v4:21.+'
However, there is an warning void using 21.+ ....".
I'm hoping someone might shed some light on this issue. I am trying to change the support library versions from:
compile 'com.android.support:support-annotations:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:support-v13:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
to
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:support-v13:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
What usually seems like a simple minor upgrade has caused me the entire day. Basically upon updating the gradle.build file, I sync -> clean, and there appears a bunch of Cannot Resolve Symbol errors appearing on the IDE for classes from the support library.
What's further interesting about this is that if I try to run the code on my phone through adb, despite AS showing up as "Cannot resolve symbol", it runs perfectly fine on my phone.
Among the things I've tried:
Clean / Rebuild
Invalidate cache / restart
Delete all the .iml files and the .idea folder
Reinstalling of Android Studio, reimport of project
Rebooting
Digging further into the build directory, they are similar in the sense that both
build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.1.0\jars\classes.jar
and
build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.1.1\jars\classes.jar
were generated respectively. What's different is that in AS, for the previous version, the "classes.jar" can be opened in AS where as with the new version, they cannot be opened in AS.
I feel that I have pretty much exhausted all available options so if anyone can shed some light on how to resolve this, I would really much appreciate it.
My full gradle.build file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.XXX"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.1.1"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':XXX', configuration: 'android-endpoints')
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.4'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.balysv:material-ripple:1.0.2'
compile 'net.sf.flexjson:flexjson:3.3'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.android.support:support-annotations:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:support-v13:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
}
I have finally solved:
First of all, I updated the gradle plugin.
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
Then just Build->Clean project and everything works again.
I think I have solved this problem guys. Go to the main module in your project, it's usually have the name app.
Then go to > Open Module Settings > in Properties change the Build Tools Version to 23.0.1.
Then to make sure open the build.gradle file, and change compileSDKVersion & buildToolsVersion to 23 and 23.0.1 respectively.
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "id.web.twoh"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
You should also make sure that all modules in your project have the compileSdkVersion and buildToolsVersion begin with 23, as you will use the 23th version of the support library.
I know it's late but I had a similar issue. It turned out that the issue was caused by the Data binding library. I had an error in the code that referenced in an invalid reference in the generated binding class. My layout file defined a webview with id webview but in the code I referenced it as webView. After correcting the error and cleaning and doing full rebuild Android Studio started recogninsing all the packages and seeing support libraries.
I had exactly the same problem, and to solve it I have just changed the BuildDebug Configuration spinner to MainActivity :
I solved my problem by changing the Run/Debug Configuration spinner to MainActivity (instead of app[androidDepedencies]) in the ToolBar...