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!
Related
I've switched to release build variant and configured signingConfigs. Now when I try to check the debug build variant from the drop down menu it switches immediately back to the release build variant. So I'm not able to run my app in debug mode any more.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
android {
signingConfigs {
config {
...
}
}
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.kost.foo"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
externalNativeBuild {
cmake {
...
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
signingConfig signingConfigs.config
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main {
jniLibs.srcDirs = ['src/main/jni']
}
}
externalNativeBuild {
cmake {
path 'src/main/jni/CMakeLists.txt'
}
}
}
kapt {
generateStubs = true
}
repositories {
maven { url 'https://github.com/linchaolong/stetho-realm/raw/master/maven-repo' }
mavenCentral()
}
I've tried to revert all changes in build.gradle as it was before configuring, but with no luck.
Any ideas how to fix the issue?
I had a similar problem where most of the Build menu items were greyed out.
'Sync project with Gradle files' didn't fix.
I noticed a 'Build Variants' toggle button on the bottom left of Android Studio (v 3.1.2) and with this was finally able to choose the variant I needed.
Maybe this will work for you too.
Maybe you have got your solution to this, just in case, i provide my solution here.
For Android Studio 2.x
It may because that you compile your dependent project using:
compile project('module_a')
Above setting will force your project to compile the release version of your modules. Just change it to below:
releaseCompile project(path: ':module_a', configuration: 'release')
debugCompile project(path: ':module_a', configuration: 'debug')
For Android Studio 3.x
You don't need to explicitly specify the build variant for a "module project". Just using
implementation project(':library')
will automatically help select the correct build variant.
Here is a detailed explanation: https://developer.android.com/studio/build/?utm_source=android-studio#variant_aware
For Android Studio 3.x Upgraded from 2.x
Delete the .idea folder under your project root directory and restart your Android Studio.
Below is the GUI screenshot:
Hope it helps!
Just need to cut ".idea" Folder and paste it outside Project root folder( For Back up if you need).These files will be auto regenerated. On Opening the project it"ll ask add module (app) to your project. You can ignore the same.
It set set default build variant to be "debug".
You can see build variant tab on left corner or hover on "Monitor" Symbol on left bottom to get build variant option.
I just had the same issue. Solved it by closing Android Studio, removing the generated files and folders: .gradle, .idea, app/.externalNativeBuild, app/build, build, app/app.iml, ProjectName.iml, local.properties, then relaunching Android Studio and allowing it regenerate all these files from scratch.
Had the same problem, solved creating a new temporary Build Type, Build > Edit Build Types, select Build Types and add a new one. Sync, then you can select the new build type, and then revert back to original Debug build type.
Open your module setting. (Click F4)
Go to build types and create a new Build by clicking on plus(+) sign.
Name it anything, like "demo".
Duplicate all the data of debug build.
Now when you open Build Variant you will be able to switch to Debug as well as Demo.
For me I was unable to switch to our 'devDebug' variant but I could switch to another variant like 'devRelease' and then 'devDebug'. So try switching to another variant first.
I ran into a similar issue. My module level build.gradle reflected configurations specified for "debug" AND "release" accordingly. I was able to successfully run my app on emulator and device (LG) prior To Building and Signing My Release Version Of My App. After Building and Signing The Release Version and attempting to Run The Signed APK on My Phone and Device, i received an Error PM Session 'mobile': Error Launching activity....Error while Launching activity..So I started retracing my steps and realized that before deploying the signed release variant, i opened up the run/debug Configurations Dialog
and mistakenly selected the the Value APK from app bundle value From The Deploy attribute, under the Installation category
I Signed My APK In its ENTIRETY and NOT Via Bundle, so the option selected was attempting to Deploy an invalid App Bundle That Was Never Generated To Begin With, even if it was for the correct Build Variant.
I have this question too. My solution is checkout to the branch which i had changed the build variants. And at that branch, I can change from release back to debug. Then just checkout to current branch and everything is OK. It seems to be a Android Studio bug.
English is not my native language; please excuse typing errors.
I also meet this situation. i do this to solv .
Solv:
1. delete each module's impl suffix type file and build folder;
2. then click this button to sync project with gradle build file. button position
finally. and then this problem will be fix.
I fixed this issued by:
Add a new build type named debug1 via edit build.gradle;Enable debug function of this build type;
Sync and select the new build type debug1;
This issue seems to occur when opening the project in a symlinked location on linux. Opening the project directly fixed this issue for me.
relevant link: https://issuetracker.google.com/issues/156857164
For me, it was an issue with the gradle version. Make sure your plugin version and the required gradle version fit together, as defined here.
https://developer.android.com/studio/releases/gradle-plugin
You can find out which gradle versions you are using under:
File -> Project Structure... -> Project
I tried all the above to no effect. Eventually stumbled across File > Invalidate Caches/Restart... for other reasons and found it worked for me.
in main root of app in build.gradle
replace it from:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
to my Android Studio v3.0.1 in my case:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
March 26, 2021:
Would not switch from Release to Debug,
File | Invalidate Caches fixed it for me
Unrelated to your build.gradle file,
Sharing hoping it might help someone else -
I was having similar issue it was because one of the line in build.gradle -
android {
...
publishNonDefault true // remove this line and it should work!
}
Here you can get more detail about publishNonDefualt -
It is also possible to publish all variants of a library. We are planning to allow this while using a normal project-to-project dependency (like shown above), but this is not possible right now due to limitations in Gradle (we are working toward fixing those as well).
Publishing of all variants are not enabled by default. The snippet below enables this feature:
the event log say
5:11:08 PM Gradle sync started
5:11:35 PM Gradle sync failed: Process 'command '/usr/local/android-studio/jre/bin/java'' finished with non-zero exit value 2
Consult IDE log for more details (Help | Show Log)
delete .gradle file (fail)
restart android studio/pc (fail)
offline work (fail)
use local gradle distro (fail)
reinstall (fail)
update android studio (fail)
for more information : this is the first time im using android studio.
edit : sorry for my formatting
I did this in Android studio 2.3:
Download new version of gradle from http://services.gradle.org/distributions/ and extract it. Open your project go to file>settings choose build, execution, deployment select gradle choose 'use local gradle distribution' and set the path to the updated gradle. Import project again (make sure you're connected to the internet).
I have found the answer for me on askubuntu, but since I found this thread first, I'll post it here for others:
The problem is there in the error report:
/usr/local/android-studio/jre/bin/java
It tries to find a java runtime in its own folder, while you probably have java installed elsewhere. Simply go to File -> Other Settings -> Default Project Structure, and set the JDK folder to the root folder of your JDK. (e.g. C:\Program Files\jdk1.8.0_111)
I just wish it was more clear on what its problem was...
Try below codes in your app level build.gradle file
multiDexEnabled = true
dexOptions {
preDexLibraries = false
incremental true
javaMaxHeapSize "4g"
}
This issue is quite possibly due to exceeding the 65K methods dex limit imposed by Android. This problem can be solved either by cleaning the project, and removing some unused libraries and methods from dependencies in build.gradle, OR by adding multidex support.
So, If you have to keep libraries and methods, then you can enable multi dex support by declaring it in the gradle config.
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
Also it is possible that two or more liabraries conflict (same library but different versions). Check your app build.gradle in dependencies block.
Here are possibility of mulitple reasone for Gradle Sync Failed.
1) You have same library or jar file included several places and some of them conflicting with each other.
2) Check if you have 2 classes with same name.
Solutions
1) Remove unnecessary complie library code in build.gradle
dependencies { compile 'com.google.android.gms:play-services:7.5.0' } which was causing over 65k methods, so removed it,gradle sync, cleaned project, and then ran again and then this error stopped. I needed just maps and gcm so i put these lines and synced project
compile 'com.google.android.gms:play-services-gcm:7.5.0' compile 'com.google.android.gms:play-services-location:7.5.0'
2) Add below code to your build.gradle file.It may manage duplication of libraries
packagingOptions { exclude 'META-INF/NOTICE' exclude 'META-INF/notice.txt' exclude 'META-INF/NOTICE.txt' }
defaultConfig { ... ... multiDexEnabled true }
For Reference Java finished with non-zero exit value 2 - Android Gradle
I installed Android Studio on my computer. I created a new project but that got me the error below. What can I do?
Error:Execution failed for task ':app:compileDebugAidl'.
> aidl is missing
My Android Studio version is 1.1.0.
This is my build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
And :
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "24.1.2"
defaultConfig {
applicationId "com.example.jo.cloning_a_login_screen"
minSdkVersion 13
targetSdkVersion 21
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.android.support:appcompat-v7:22.0.0'
}
In my case I downloaded version 22 of Android M and Android 5.1.1 using Android Studio 1.2.1.1 but when I try to do a Hello World this same error showed me
So the solution for me was doing right click in app like the image below and choose "Open Module Settings"
then there you have 2 options. I've changed both with the last version I had.
Compile SDK version to API 21 Lollipop
and Build Tools Version to 21.1.2
Finally clean the project and Build
UPDATED
TO Get Android Studio 1.3 follow these steps
Open the Settings window by choosing File > Settings.
Choose the Appearance & Behavior > System Settings > Updates panel.
On the Updates panel, choose the option Automatically check updates for: Canary Chanel.
On the Updates panel, select Check Now to check for the latest canary build. Download and install the build when you are prompted.
Then you'll have something like this to update your Androud Studio to 1.3 and with this you can test Android M
Update: Real Cause
This bug happens when the versions of SDK, Build Tools and Gradle Plugins doesn't match (in terms of compatibility). The solution is to verify whether you are using the latest version of them or not. The gradle plugins are placed in the build.gradle of the project, and the other versions are on the build.gradle of the module. For example, for SDK 23, you must use the Build Tools 23.0.1 and gradle plugins version 1.3.1.
It has been fixed two days ago, so you can use:
buildToolsVersion '23.0.0 rc2'
with the newest android gradle plugin:
classpath 'com.android.tools.build:gradle:1.3.0-beta2'
Note:
I had some weird problems with gradle 2.4 distribution, but trying to build the project again has fixed that for me.
EDIT
There is a newer version of build-tools 23, so you should probably use:
buildToolsVersion '23.0.0 rc3'
EDIT 2
And yet again, there are newer version of both gradle plugin and build-tools, so you can switch to using:
classpath 'com.android.tools.build:gradle:1.3.0'
and
buildToolsVersion '23.0.0'
I had a similar error with a fresh install of Android Studio 1.2.1.1 attempting to build a new blank app for API 22: Android 5.1 (Lollipop).
I fixed it by simply changing the Build Tools Version from "23.0.0 rc1" to "22.0.1" and then rebuilding.
On Windows, F4 opens the Project Structure and the Build Tools Version can be set in the Modules > app section:
I think all this does is change the setting in the build.gradle file in the app but I didn't want to change that manually just in case it does something more.
I tried to uninstall/install and it did not work. I am running OSX 10.10.3 with Android Studio 1.2.1.1 on JDK 1.8.0_45-b14 and the solution I found to work is similar to Jorge Casariego's recommendation. Basically, out of the box you get a build error for a missing 'aidl' module so simply changing the Build Tools Version to not be version 23.0.0 rc1 will solve your problem. It appears to have a bug.
UPDATE
After commenting on an Android issue on their tracker (https://code.google.com/p/android/issues/detail?id=175080) a project member from the Android Tools group commented that to use the Build Tools Version 23.0.0 rc1 you need to be using Android Gradle Plugin 1.3.0-beta1 (Android Studio comes configured with 1.2.3). He also noted (read the issue comments) that the IDE should have given an notification that you need to do this to make it work. For me I have not seen a notification and I've requested clarification from that project member. Nonetheless his guidance solved the issue perfectly so read on.
Solution: Open your build.gradle for your Project (not Module). Find the line classpath com.android.tools.build:gradle:xxx under dependencies where xxx is the Gradle Plugin version and make the update. Save and Rebuild your project. Here is the Android Gradle docs for managing your Gradle versions: https://developer.android.com/tools/revisions/gradle-plugin.html
I was able to get build to work with Build Tools 23.0.0 rc1 if I also opened the project level build.gradle file and set the version of the android build plugin to 1.3.0-beta1. Also, I'm tracking the canary and preview builds and just updated a few seconds before, so perhaps that helped.
// 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:1.3.0-beta1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Quick fix that worked for me:
Right click on project->"Open Module Settings"->Build Tools Version change to: 22.0.1
To build your application without aidl is missing error with compileSdkVersion 23 and buildToolsVersion "23.0.1" you should specify latest versions for Android Gradle plugin (and Google Play Services Gradle plugin if you are using it) in main build.gradle file:
buildscript {
repositories {
...
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.google.gms:google-services:1.3.1'
}
}
I had the same error i fixed it by going to the build.gradle (Module: app) and changed this line from :
buildToolsVersion "23.0.0 rc1"
to :
buildToolsVersion "22.0.1"
You will need to go the SDK Manager and check if you have the 22.0.1 build tools. If not, you can use the right build tools but avoid the 23.0.0 rc1.
Essentially Matt Daley/Johnny Mohseni's solution worked for me.
I faced exactly the same problem on a fresh Android Studio V 1.2.1.1 installation. I created a new project (blank activity) and straightaway god this build error.
Error:Execution failed for task ':app:compileDebugAidl'.
> aidl is missing
As suggested, changing the gradle dependency from 1.2.3 to 1.3.0-beta1 fixed it.
classpath 'com.android.tools.build:gradle:1.3.0-beta1' // <--- WORKS!
//classpath 'com.android.tools.build:gradle:1.2.3' // <--- default - failed
Once 1.3.0-beta1 change was saved, I got a prompt to upgrade dependencies. Upon accepting the request to upgrade, the gradle build status bar at the bottom tracked the packages being synced. When that completed, the build was automatically triggered and completed successfully.
Use your file browser and copy-paste the IInAppBillingService.aidl into /app/src/main/aidl/com/android/vending/billing/
The problem was actually in the version Android Studio 1.3 updated from the canary channel. I updated my studio to 1.3 and got the same error but reverting back to studio 1.2.1 made my project run fine.
buildtools layout in 23.0.0.rc2 was reverted
so to be able to use it, you need to upgrade the plugin to 1.3.0-beta2 or higher as i show below:
I am working with sdk 23.1.0 and gradle 1.3.1. I created a new project edited nothing and got the aidl error. I went into my project gradle file and changed tool to 22.0.1 instead of 23.1.0 and it worked:
compileSdkVersion 23
buildToolsVersion "22.0.1" //"23.1.0"
Check if you actually have installed the buildVersionTools you are using. In my case I tried 25.0.1 whilst I only had 25.0.2.
To check it go to the SDK Manager, clicking the icon:
Then click Launch Standalone SDK Manager at the bottom:
Now check whatever you need and install packages.
Hope it helps!
i just switched to intellij and pretty new to android development.. I've been working on one app for 5 moth and now that i moved it to intellij android studio my options menus became invisible. I've been reading a lot and trying to catch up with newest features that are available now today.
By biggest pain is that im hitting this error ->
Failed to refresh Gradle project 'ActionBarCompat-ListPopupMenu' You are using Gradle version 1.8, which is not supported. Please use version 1.9. Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (
I did search on this problem and some pages suggesting changing classpath to soething like
build:gradle:0.7.+ but that doest help..
What am i doing wrong? All i need is just to make those examples from android to work..
Thanks
The Gradle wrapper file is at the path (project-root)/gradle/wrapper/gradle-wrapper.properties. The distributionUrl property is where you set the Gradle version; it's embedded in the URL:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip
First make sure you've updated to the newest Android SDK Build-tools version, the most current one is 19.0.3; if you haven't, then open the Android SDK manager and update.
Then look in the build.gradle file inside your project folder (not the one in the root folder). This first couple of lines should resemble something like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
Set the class path to com.android.tools.build:gradle:0.9.+.
Then further along in the same file:
android {
compileSdkVersion 18
buildToolsVersion "19.0.3"
...
}
Set buildToolsVersion to 19.0.3 (the newest version).
Make sure Android Studio syncs the Gradle file changes. If it doesn't, restart Android Studio and/or rebuild the project. Then you should be good to go.
I think i figured this out.. Big thanks to Scott and Jaap.
I did updateof my intellij to 0.5.2, also i installed 19.0.3 ( newest build tools).
On few of the existing projects i had to change distributionUrl to
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
After rebuilding the project it worked like a charm.
Just a note to say : Scorr Berba's reply was probably the correct one. Also I'm not sure 1.11 can be used - I used the wrapper (there is a lot of confusion here : the wrapper is the gradlew ["gradle*w*"rapper] to set the gradle used for my samples to 1.10 and you must set up your project to use the wrapper OR you can build from the command line e.g "./gradlew build".
I would like to create a properties file named "dev.properties" using gradle. Here is my build.gradle code:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 16
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 16
}
def prop = new Properties()
def propFile = new File("dev.properties");
propFile.createNewFile();
prop.store(propFile.newWriter(), null);
buildTypes {
release {
runProguard false
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
}
The file is created when I right click on the build.gradle and choose run. However it's not created when I make the entire project. How come?
I'm using android studio 0.4.6 with gradle 1.10.
It's creating the file, just not where you expect. Your script is creating the file inside the current working directory, and in Android Studio, that will be in Android Studio's distribution. There's a bug filed to make Android Studio consistent with the command line (https://code.google.com/p/android/issues/detail?id=65552) and put the working directory at the project root (well, that's assuming your working directory is set there when you issue Gradle commands), but the fix is actually difficult, and the real answer is you should probably never implicitly rely on the working directory, so that you can make your builds as bulletproof as possible.
If you do something like this:
def propFile = new File("${project.rootDir}/dev.properties")
it will put the file in your project's root directory. There's also project.projectDir, which will be your module directory; see http://www.gradle.org/docs/current/dsl/org.gradle.api.Project.html for more details on what's available to you.
As a side note, you should keep in mind this will run every time the build file is evaluated (because the android block is executed every time the build script is run), which could be more often than you want. It's more than just build time; it's project import time as well, and any time Android Studio decides to evaluate the build file, which happens when you open the project and also when you click the Sync Project with Gradle Files button.
Additionally, you should consider at what phase of the build process you want it to happen: is it script evaluation time, or do you want it to run after Gradle has done its analysis and is ready to actually start building things? You can read http://www.gradle.org/docs/current/userguide/build_lifecycle.html to find out more about that.
Sorry, I know it's a lot of information to drop on you when you're just trying to get something going, but those concepts will help you out pretty soon down the road.