Execution failed for task 'apCompileDebugWithJavac' error when building gradle in android studio - android-studio-2.0

I am a new to android developing. I have been trying to Build the Gradle in android studio but it always returns an error. I have not been able to run my app even a single type on my android device. Thus, need some help. This time, I am getting this error
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Could not open local class set analysis write cache (F:\ANDROID_PROGRAMS_BEGGINER.gradle\2.10\tasks_app_compileDebugJavaWithJavac\localClassSetAnalysis).
Unexpected lock protocol found in lock file. Expected 3, found 0.
I have tried the following steps , but still facing the same issue :-
Invalidate Cache/Restart
Delete .gradle folder in C://Users/User_Profile directory
Here is my build.gradle file :-
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.example.android.justjava"
minSdkVersion 15
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.0.0'
}
My gradle .properties file is quite simple . It has just the following one line :-
org.gradle.daemon=true
I have been using the latest android studio version
Looking for an answer.
Thanks
UPDATE : Just now when I again deleted both .gradle folders, I am getting another error which is
Error:Execution failed for task ':app:clean'.
Unable to delete file: F:\ANDROID_PROGRAMS_BEGGINER\app\build\generated\source\r\androidTest\DefaultConnectionReuseStrategy.html

Try deleting your .gradle folder in project root. Got same error for me and tried clean build project but no effect. Then i found that the problem is with gradle files. So deleted the .gradle folder and got it running. Dont worry about deleting Android Studio will automatically generate deleted folders

Related

tns run android with a specific sdk

I just created a new application and added android platform. Since I failed to install API 28 for days, I want to run the project against the working SDK 21. How can I configure the application to run with sdk 21?
My app/App_resources/android/app.gradle is the default one with:
android {
defaultConfig {
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
in platforms/android/.gradle/ I see 4.10.2
while my build.gradle is:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
When i run tns run android --emulator
the message is:
Gradle build...
+ setting applicationId
+ applying user-defined configuration from D:\pyworks\agrigo7\mobileapp\agrigo\app\App_Resources\Android\app.gradle
Using support library version 28.0.0
+ adding nativescript runtime package dependency: nativescript-optimized-with-inspector
+ adding aar plugin dependency: D:\pyworks\agrigo7\mobileapp\agrigo\node_modules\tns-core-modules-widgets\platforms\android\widgets-release.aar
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to find Platform SDK with path: platforms;android-28
In my Android SDK, I tried to install API 28 but it kept on failing and failing. My current SDK looks like:
given API 21 is installed, I tried:
tns run android --compileSdk 21 --emulator
It first does show 28.0.0. then gives a lot of errors:
+ setting applicationId
+ applying user-defined configuration from D:\pyworks\agrigo7\mobileapp\agrigo\app\App_Resources\Android\app.gradle
**Using support library version 28.0.0**
+ adding nativescript runtime package dependency: nativescript-optimized-with-inspector
+ adding aar plugin dependency: D:\pyworks\agrigo7\mobileapp\agrigo\node_modules\tns-core-modules-widgets\platforms\android\widgets-release.aar
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
Output: error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
I think you are getting confused between the support library and SDK version. They are different and your support library's major version should always match your SDK's major version which means you can't use support library 28.x with SDK 21.x.
#Jenlooper had given a brief about this breaking change at the 5.0 launch, you must specify the right support library version in the gradle file (project.ext.supportVersion).
Besides, Google Play restricts all new app submissions to target SDK 26 (Android 8.0) so I would recommend you to try SDK 26 instead of 21 which you can't use to publish.

Android Studio Execution failed for task ':app:dexDebug'

I'm trying to start my first Android Studio app and coming across the same error over and over when I try to run or debug. I'm building a music app using the Spotify API and have imported the zipped jar files in the correct directory (under libs in my app).
What seems to be the problem is that maybe my SDK folder is in another drive? I don't think so, but it was the only thing I can think it would be. I even moved over my Android Studio folder and tried running it from the same D: drive but didn't make any difference.
I also have all the appropriate SDKs installed incl. SDK Tools, Platform-tools, SDK Build-tools 19.1, 20, API 19, 20, Android Support Repository, Library, Google Play serivces, Repository, USB Driver, and Intel Emulator.
This is the error I am getting:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
D:\adt-bundle-windows-x86_64-20140702(2)\adt-bundle-windows-x86_64-20140702\sdk\build-tools\19.1.0\dx.bat --dex --output C:\Users\Jesse\AndroidStudioProjects\SubRosa\app\build\intermediates\dex\debug C:\Users\Jesse\AndroidStudioProjects\SubRosa\app\build\intermediates\classes\debug C:\Users\Jesse\AndroidStudioProjects\SubRosa\app\build\intermediates\dependency-cache\debug C:\Users\Jesse\AndroidStudioProjects\SubRosa\app\build\intermediates\exploded-aar\com.spotify.sdk\spotifysdk\1.0.0-beta5\libs\jnihelpers-1.0.jar D:\adt-bundle-windows-x86_64-20140702(2)\adt-bundle-windows-x86_64-20140702\sdk\extras\android\m2repository\com\android\support\support-v4\19.0.1\support-v4-19.0.1.jar C:\Users\Jesse\AndroidStudioProjects\SubRosa\app\build\intermediates\exploded-aar\com.spotify.sdk\spotifysdk\1.0.0-beta5\classes.jar C:\Users\Jesse\AndroidStudioProjects\SubRosa\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\19.0.1\classes.jar
Error Code:
1
Output:
'D:\adt-bundle-windows-x86_64-20140702' is not recognized as an internal or external command,
operable program or batch file.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Here is some my code and gradle builds/props:
local.properties
sdk.dir=D\:\\adt-bundle-windows-x86_64-20140702(2)\\adt-bundle-windows-x86_64-20140702\\sdk
build.gradle(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0' // Note: this version should match the latest build-tools version
// that you installed in the SDK manager
defaultConfig {
applicationId "com.jesse.spalding.subrosa"
minSdkVersion 14
targetSdkVersion 19
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
dexOptions {
preDexLibraries = false
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.spotify.sdk:spotifysdk:1.0.0-beta5#aar'
compile 'com.android.support:appcompat-v7:19.0.1'
}
If anyone has any idea what the deal is what this, please let me know. I need to start working on this for a final project and just can't figure this technical thing out for some reason.
The problem seems to be that your SDK is in a path that has a parenthesis in it (D:\adt-bundle-windows-x86_64-20140702(2)\adt-bundle-windows-x86_64-20140702\sdk), which is causing problems in one of the phases of the build process. Move your SDK to a path with a simpler name and update its location in Android Studio (Project Structure > SDK Location) and you should be good to go.

Gradle error on Android Studio startup

Every time I start Android Studio I get the following error:
Gradle 'VertretungsplanProject' project refresh failed: Could not
fetch model of type 'IdeaProject' using Gradle distribution
'http://services.gradle.org/distributions/gradle-1.6-bin.zip'. A
problem occurred configuring project ':Vertretungsplan'. A problem
occurred configuring project ':Vertretungsplan'. Failed to notify
project evaluation listener. A problem occurred configuring project
':libraries:actionbarsherlock'. Failed to notify project evaluation
listener. Could not normalize path for file
'P:\Projekte\VertretungsplanProject\libraries\actionbarsherlock:Vertretungsplan\libs\android-support-v4.jar'.
The syntax for the filename, directoryname or the volume label is
wrong
My project looks like this:
Gradle settings:
build.gradle of :Vertretungsplan:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/commons-io-2.4.jar')
compile project(':libraries:actionbarsherlock')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
}
build.gradle of :VertretungsplanProject is empty.
build.gradle of :actionbarsherlock:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile files(':Vertretungsplan/libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
When I want to compile now this error appears:
Deprecated make implementation
Old implementation of "Make" feature is enabled for this project.
It has been deprecated and will be removed soon.
Please enable newer 'external build' feature in Settings | Compiler.
After changing this setting to Use external build everything is working fine.
But this appears every time I start Android Studio and this is really annoying.
UPDATE
I deleted the android-support-v4.jar from the libs folder and simply wrote compile 'com.android.support:support-v4:18.0.0' to the build.gradle of ActionbarSherlock. Then the android-support-v4.jar is used from the installed SDK.
EDIT
Go to File > Settings > "Build,Execution,Deployment"> Compiler
Click compiler directly.
Check the option: Use external build > Apply > OK.
It worked for me !! :)
You seem to have more than one issue. Problems loading gradle on startup and problems resolving the dependency path name in your environment.
I recently found a fix for the "Failed to import Gradle project" issue, which could be linked to your dependency issue.
At least if you fix one, you know your issue could specifically be the dependency path resolution rather than a gradle/android studio issue...
Check out the troubleshooting section here:
http://developer.android.com/sdk/installing/studio.html#Troubleshooting
The basic steps are:
1. Close android studio
2. Open the SDK manager
(run android binary/executable which should be in /tools)
3. Scroll down the list and expand extras
4. Tick the "Android Support Repository"
5. Click Install Packages.. etc etc...
You need to download this as Android Studio 0.2.x needs a new maven repository used by the new build system for the support library, instead of using support library jar's.
Let us know if anything changes after trying this fix.
In the error message, the path appears: 'P:\Projekte\VertretungsplanProject\libraries\actionbarsherlock\:Vertretungsplan\libs\android-support-v4.jar'
It looks like you're on Windows. The semicolon before Vertretungsplan is not a legal filesystem character. This appears in your script as
compile files(':Vertretungsplan/libs/android-support-v4.jar')
Try changing this to
compile files('Vertretungsplan/libs/android-support-v4.jar')

Gradle/Android: Specify 'root' as a dependency of subproject

First of all, I've got an Android Studio project setup that works fine from within Studio. I can build it and run it on a device and in the emulator without problem and can also build a release APK.
I'm now trying to get to the point where I can have some command-line tools that will handle my build for me. All the reading I've done suggests that Android Studio uses gradle, but from what I've seen that's clearly not the case for my project -- as I had to create my build.gradle, settings.gradle files before gradlew would even attempt to build anything -- and yet Android Studio could still compile and deploy just fine.
Here's my project structure (as it sits physically on disk):
Root Project (Android library project, contains all the src, logic, UI, activities, etc.)
\--- WrapperProject (Android app, depends on the root project)
\--- SubProject1 (Android library, used by root)
\--- SubProject2 (Android library, used by root)
This is my root project's settings.gradle file
include ':SubProject1', ':SubProject2'
Likewise, here's my root project's build.gradle file. Note that this project is marked as an android-library and does not reference the WrapperProject in any way (should it?)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile project(':SubProject1')
compile project(':SubProject2')
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
I'm able to build my root project successfully using gradlew build -- but my ultimate goal is to build the APK from the WrapperProject that has a dependency on the root project. Can you suggest what my WrapperProject's build.gradle file should contain?
I'm here because of searching for similar answers, although my problem is primarily the opposite. I'm finding that the integration between command-line builds (gradlew) and Android Studio 0.2.2 is full of secrets.
One thing I see that stands out in your config file: this is pretty beta/alpha stuff. You have not revised your project to the latest Android Studio 0.2.0 notes. In particular, the 'com.android.tools.build:gradle:0.4' should be revised. Reference: http://tools.android.com/recent
There is an open source application that has the same basic need as yours. It is a Grocery Shopping app that is provided as a sample for CouchDBLIte https://github.com/couchbaselabs/GrocerySync-Android
it has to reference the existing projects. It seems to use a more explicit syntax for the dependencies than you did. example: "compile 'com.couchbase.cblite:CBLiteEktorp:0.7.4'" - including the full class paths. But they define two basic approaches, direct integration and artifact integration.
Sorry I can't provide a more precise answer to your syntax issue - but I'm sharing what I know so far.

Android Studio update today with regression

Started Android Studio today, and it popped up an update notice. Since I'm eager to explore new features and bug fixes, I clicked yes. Now the Project Structure dialog where you setup dependencies is missing, and has been replaced by a message:
We will provide a UI to configure project settings later. Until then, please manually edit your build.gradle file(s.)
So, I go out to try to figure out how to add ActionBarSherlock to my project as a project dependency, and have hit a brick wall. I have no idea how to import ActionBarSherlock project as a Library Project, and configure my project to use it. There isn't much documentation on this at Google, IntelliJ, and the Gradle docs assume a LOT of pre-existing knowledge of build systems.
There are plenty of posts on SO how to do this (although referenced with already missing Project structure dialog)
How do I add a library project to Android Studio?
Android-Studio ActionBar sherlock error with gradle
Installing ActionbarSherlock with Android Studio?
Problems importing project into Android Studio regarding ActionBarSherlock
In short:
Create a folder (i.e. /libraries) in your root.
Extract actionbarsherlock there
Create a new file build.gradle in actionbarsherlock root with the following contents
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
In your project's build.gradle
dependencies {
//NOTE that "libraries" is actually a folder name you created in step 1
compile project(":libraries:actionbarsherlock")
//Any other dependencies here
//Make sure there is no android-support-v4.jar in this build file
//as it is already contained in actionbarsherlock project
}
In settings.gradle
//NOTE that "libraries" is actually a folder name you created in step 1
include ':libraries:actionbarsherlock', ':<Your project name>'
EDIT
Last step: Close your project and open it back again for Studio to pick up the Intelli-sense data

Resources