Gradle gets stuck when I try to build on the task [:android:generateDebugSources].
I've left it running for hours without a successful build.
I've tried it in Android Studio 1.0.0, 0.8.1, with Gradle versions 2.1.1, 1.12, 1.14, Android plugin versions 0.12.+ and 0.14.4 using the default wrapper as well as local distributions. I've reinstalled Android Studio and rebooted without any luck. Also tried File --> invalidate caches/Restart.
Here is my android package's build.gradle:
buildscript {
repositories
{
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/repo' }
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
minSdkVersion 11
targetSdkVersion 21
versionCode 13
versionName "onBoarding"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/android-query-full.0.26.8.jar')
compile files('libs/gson-2.3.jar')
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.android.support:support-v4:21.+'
compile 'com.android.support:recyclerview-v7:21.+'
compile 'com.google.android.gms:play-services:6.1.71'
}
And then my project-level gradle.build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Any advice greatly appreciated.
Got it! Changing the buildToolsVersion from 21.1.1 to 20 yielded a successful build.
You can also, just install the correct version of the tools.
I know this is an old question, but I spent a lot of time in this problem and read at least 30 answers until I found out what was hapenning.
I constantly got a message that another aplication was locking a file that Android-Studio needed to complete gradle building. Finally, I found out that it was Avast. So I simply deactivated it and the build finished successfully, but it still took a long time (about 10 minutes).
Tried below option and it worked!
Add below properties to your .gradle file
org.gradle.daemon=true
org.gradle.parallel=true
Set SLAVE_AAPT_TIMEOUT environment variable to 30 in windows and restart your system.
Second solution credit goes to semuzaboi.
Related
I'm really frustrated. I'm new to Android development and Gradle. Last week I was able to download Android Studio and created a simple app that contains a few buttons. I had no trouble creating and running this.
This week I decided to create another, simpler app with no activities, to check whether my environment is set up properly. After a couple of days, I cannot get the IDE to build the app, and the problems appear to be Gradle-related.
Here is my gradle-wrapper.properties file:
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Here is my app-level build.gradle file:
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
And here is the top-level gradle.build file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I read up on additional repositories that are needed, and tried inserting this code into the top-level Gradle build file:
repositories {
google()
jcenter()
maven { url "https://www.jitpack.io" }
}
}
But this does not help. When I try to build the project, I get errors saying that Gradle cannot find files (if I check the "offline" option) or when online, I see errors like this:
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all artifacts for configuration ':classpath'
In Settings, I have "Auto-detect proxy settings" checked (I'm not behind a firewall), and I'm using Gradle from the gradle-wrapper.properties file.
Given that I'm able to rebuild the app I created last week, but cannot build this new app whatever I try, I'm wondering whether file caching might be causing this trouble. I did try deleting the cached Gradle files from .gradle (I'm running on Windows 10) but that did not help. Multiple times, I have tried invalidating the cache and restarting the IDE but this does not make a difference.
After opening an older project for the first time after a few weeks/months (very busy with work) Android Studio asked me to upgrade to the latest gradle plugin.
Gradle Upgrade promt
I didn't really think anything of it and hit "Update". After Gradle finished updating and syncing I noticed that most of my layout and java class files vanished. They're simply gone.
However, in my project's directory a folder called "projectFilesBackup" appeared. I assume that restoring the backup contained in this folder might bring my missing files back.
projectFilesBackup Folder
So my question is: Does anyone know how I actually tell Android Studio to restore to the backup? It only contains an ".idea" folder which contains "workspace.xml". Any help would be greatly appreciated.
I've already tried using "Local History" to undo any changes done on the day of the Gradle Update as detailed in this SO post.
Edit:
As requested my build.gradle files:
// 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:2.2.1'
classpath "io.realm:realm-gradle-plugin:1.2.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
}
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.tools.awesome.cs.grademanager"
minSdkVersion 23
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'io.realm:android-adapters:1.3.0'
}
Change the realm-gradle-plugin to the most dated one and see if it brings up the files again.
classpath "io.realm:realm-gradle-plugin:2.0.2"
I am quite new to Android development and trying to write some test code. I have downloaded Android Studio 1.3 version and created testapp. I am trying to add com.facebook.android:facebook-android-sdk:4.1.0 depedency but somehow it's not getting downloaded.
Here is Project level build.gradle file.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}}
Here is Module level build.gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.testapp"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.android.support:appcompat-v7:22.2.1'
}
After reading other posts on similar topics I also confirmed that Gradle > Global Gradle settings > Offline work is not checked. Still somehow facebook depedency is not getting downloaded.
Any suggestions what could be the issue? Appreciate any pointers.
Thanks.
In your build.gradle you have to add
repositories {
jcenter()
}
It this way gradle knows where are the dependencies to download.
It is somenthing different from the repositories inside the buildscript block.
Otherwise you can add in the top-level build.gradle file:
allprojects {
repositories {
jcenter()
}
}
In this case, the repository block is valid for all modules in the project.
Could you post the error AndroidStudio is showing? (check on the Gradle Console, on the Run section and Android Monitor section)
One possible option that comes to my mind is that you don't have the lastest Android Support repository / Google repository installed: Check for updates on your Android SDK Manager.
I updated to Android Studio 1.0 today from 0.8.14. Most of the update was seamless, the IDE fixed a few things itself. I was using an older version of the gradle build tools, 0.12 and had to change this to 1.0.0. I also upped the buildToolsVersion defined in my inner build.gradle to 21.1.1
One project I'm working on is exhibiting very strange behaviour since I updated. I can push it to a device and it will install and open, but after I kill the app any subsequent attempts to open it don't work. A plain white screen is displayed instead. The app doesn't hit my launch activity, it doesn't instantiate the application. I can't get any information through debugging, nothing is reported from the device. This happens with both debug and release builds, and across the three flavours I've defined. I've tested on multiple phones running Lollipop and Kitkat and on Genymotion VMs.
I've included my build.gradle files below as I feel this must be something to do with the build steps taken to make the apk, but I don't know where to begin fixing this. Any help would be greatly appreciated.
// 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:1.0.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
inner build.gradle
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.2'
compile "com.android.support:appcompat-v7:21.0.2"
compile 'com.google.android.gms:play-services:6.5.87'
compile 'io.keen:keen-client-api-android:2.0.1#aar'
compile 'com.google.code.gson:gson:2.3'
compile(name: 'my-lovely-aar', ext: 'aar')
}
repositories {
flatDir {
dirs 'libs'
}
mavenCentral()
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
productFlavors {
beta {
applicationId 'com.project.beta'
}
prod {
applicationId 'com.project.prod'
}
dev {
applicationId 'com.project.dev'
}
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 8
versionName "1.1.1"
}
signingConfigs {
release {
// details for release builds
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
lintOptions {
abortOnError false
}
}
I found my problem.
compile 'com.google.android.gms:play-services:6.5.87' is the guy that broke it. I still don't know the why, but having that dependency stops my app from opening. Including earlier version of the play services lib, like 6.1.11, works perfectly. I don't have 6.1.88/83/74 to test with but I suspect they'd all be fine too.
Gradle no longer finds dependencies declared in the build.gradle. Everything was working fine and today when I open Android Studio I get an error :
Error:Failed to find: com.readystatesoftware.systembartint:systembartint:1.0.3
The library referenced is SystemBarTint. I had the library work previously using the same build.gradle file but now it no longer works.
My app/build.gradle looks like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.adnan.systembartintdemo"
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
}
My root/build.gradle looks like this :
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
Any ideas what I am doing wrong here? Thanks !
Edit : Tried importing a project which I work on daily at my work, it fails to find any dependencies in that project either. Tried re installing Android Studio, still the same error
Ok finally got this fixed.The problem was weird, for some reason it was trying to pick up a local offline copy of the dependency, I went to Settings -> Compiler -> Gradle -> Enabled offline Work and disabled it again. Save and Apply changes.
And now it works !