I am getting message this error below build failed - android

Task :app:preBuild UP-TO-DATE
Task :app:preDebugBuild UP-TO-DATE
Task :app:compileDebugAidl NO-SOURCE
Task :app:compileDebugRenderscript NO-SOURCE
Task :app:generateDebugBuildConfig UP-TO-DATE
Task :app:javaPreCompileDebug UP-TO-DATE
Task :app:mainApkListPersistenceDebug UP-TO-DATE
Task :app:generateDebugResValues UP-TO-DATE
Task :app:generateDebugResources UP-TO-DATE
Task :app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:mergeDebugResources'.
Could not resolve all files for configuration ':app:_internal_aapt2_binary'.
Could not download aapt2-windows.jar (com.android.tools.build:aapt2:3.6.3-6040484): No cached version available for offline mode
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 258ms
5 actionable tasks: 1 executed, 4 up-to-date

Try Build -> Clean Project.
Than File -> Invalidate caches/Restart.
Than open the project and sync it.

I faced the same error. fixed by
Deleting the caches folder inside bin of the .gradle folder which android studio uses found in File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle User Home
Deleting .gradle folder in project.
Deleting the Build folder in project.
Invalidate cache/ and restart
Rebuild project and done! it works
Ps1: Steps 2 and 3 can be done in projects tab, top left side of android studio.
Ps2: DON'T WORRY ABOUT DELETING THOSE FOLDERS, gradle will download them for you in the next build, provided you have network connection and Offline mode in gradle tab (top right side) is off.

Related

Cause: newPosition < 0: (-1 < 0) in Android Studio

I am getting errors in android studio, I tried all the possible steps but nothing helped me.
[Android Gradle Plugin Version 4.2.2, Gradle Version:7.2-rc-2 and JDK 15.0.2
Error Log File
Executing tasks: [clean, :app:assembleDebug] in project C:\Users\asrar\Desktop\Smart GIT
Task :clean UP-TO-DATE
Task :app:clean
Task :app:preBuild UP-TO-DATE
Task :app:preDebugBuild UP-TO-DATE
Task :app:compileDebugAidl NO-SOURCE
Task :app:compileDebugRenderscript NO-SOURCE
Task :app:generateDebugBuildConfig
Task :app:javaPreCompileDebug
Task :app:checkDebugAarMetadata
Task :app:generateDebugResValues
Task :app:generateDebugResources
Task :app:processDebugGoogleServices
Task :app:createDebugCompatibleScreenManifests
Task :app:extractDeepLinksDebug
Task :app:mergeDebugResources
Task :app:processDebugMainManifest
Task :app:processDebugManifest
Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
Task :app:mergeDebugShaders
Task :app:compileDebugShaders NO-SOURCE
Task :app:generateDebugAssets UP-TO-DATE
Task :app:mergeDebugAssets
Task :app:compressDebugAssets
Task :app:processDebugJavaRes NO-SOURCE
Task :app:mergeDebugJavaResource FAILED
Task :app:checkDebugDuplicateClasses FAILED
Task :app:processDebugManifestForPackage
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
What went wrong:
Execution failed for task ':app:mergeDebugJavaResource'.
A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
newPosition < 0: (-1 < 0)
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Failed to transform work-runtime-2.5.0.aar (androidx.work:work-runtime:2.5.0) to match attributes {artifactType=enumerated-runtime-classes, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for AarToClassTransform: C:\Users\asrar.gradle\caches\modules-2\files-2.1\androidx.work\work-runtime\2.5.0\b878e75e14ee7e745fe120bc78e8db8995064f4d\work-runtime-2.5.0.aar.
> zip END header not found
Failed to transform concurrent-futures-1.1.0.jar (androidx.concurrent:concurrent-futures:1.1.0) to match attributes {artifactType=enumerated-runtime-classes, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.version=7, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for EnumerateClassesTransform: C:\Users\asrar.gradle\caches\transforms-3\a51d8e3d972cee1891837c926b3ae865\transformed\jetified-concurrent-futures-1.1.0.jar.
> zip END header not found
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.2-rc-2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 34s
18 actionable tasks: 17 executed, 1 up-to-date
Stacktrace and info is not a solution, just gives you more information about what went wrong.
Seems really similar to IntelliJ Compilation Error zip END header not found
Which suggests your gradle cache is corrupted. Try clearing it. folder: $HOME/.gradle/caches
Probably there are some corrupted files.
For me invalidating caches and restart worked.
Last option here:
The versions you're using for plugin version and Gradle are not compatible. According to https://developer.android.com/studio/releases/gradle-plugin?
For Gradle Version 7.2 you need at least 7.1 Plugin version

Ionic : Execution failed for task ':app:mergeDebugResources'

When running the cordova build android command i get this error.
Execution failed for task ':app:mergeDebugResources'.
When i tried running this command a few days ago it made the apk, but now it won't anymore. i didn't change anything either
i tried running ionic cordova resources again so that maybe it wouldn't chrash on the image again
Does anyone else have this issue? What causes this?
full stacktrace:
PS C:\school\pokemontest> cordova build android
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\Gebruiker\AppData\Local\Android\sdk (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app
> Task :app:preBuild UP-TO-DATE
> Task :CordovaLib:preBuild UP-TO-DATE
> Task :CordovaLib:preDebugBuild UP-TO-DATE
> Task :CordovaLib:checkDebugManifest UP-TO-DATE
> Task :CordovaLib:processDebugManifest UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :CordovaLib:compileDebugAidl NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :CordovaLib:packageDebugRenderscript NO-SOURCE
> Task :app:compileDebugRenderscript UP-TO-DATE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources UP-TO-DATE
> Task :CordovaLib:compileDebugRenderscript UP-TO-DATE
> Task :CordovaLib:generateDebugBuildConfig UP-TO-DATE
> Task :CordovaLib:generateDebugResValues UP-TO-DATE
> Task :CordovaLib:generateDebugResources UP-TO-DATE
> Task :CordovaLib:packageDebugResources UP-TO-DATE
> Task :CordovaLib:generateDebugRFile UP-TO-DATE
> Task :CordovaLib:prepareLintJar UP-TO-DATE
> Task :CordovaLib:generateDebugSources UP-TO-DATE
> Task :CordovaLib:javaPreCompileDebug UP-TO-DATE
> Task :CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
> Task :CordovaLib:processDebugJavaRes NO-SOURCE
> Task :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> C:\school\pokemontest\platforms\android\app\src\main\res\drawable-pioort-xhdpi: Error: Invalid resource directory name
> Task :app:mergeDebugResources FAILED
C:\school\pokemontest\platforms\android\app\src\main\res\drawable-pioort-xhdpi: Error: Invalid resource directory name
20 actionable tasks: 1 executed, 19 up-to-date
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
C:\school\pokemontest\platforms\android\gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> C:\school\pokemontest\platforms\android\app\src\main\res\drawable-pioort-xhdpi: Error: Invalid resource directory name
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
After a lot of tries, I fix this issue by doing
1- Open the config.xml
2- Change xmlns="http://www.w3.org/ns/widgets" of the widget tag to xmlns:android="http://schemas.android.com/apk/res/android"
3- Rebuild the project
I fixed the problem.
I deleted the plugin and platform map.
After that i ran the commands cordova prepare for the plugins
and cordova build android to set everything up again.
You can try running command cordova clean android && cordova build android.

FAILURE: Build failed with exception

> Executing tasks: [:app:assembleDebug]
>
> WARNING: The option 'android.enableAapt2' is deprecated and should not
> be used anymore. Use 'android.enableAapt2=true' to remove this
> warning. It will be removed at the end of 2018. :app:preBuild
> UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:compileDebugAidl
> UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE
> :app:checkDebugManifest UP-TO-DATE :app:generateDebugBuildConfig
> UP-TO-DATE :app:prepareLintJar UP-TO-DATE
> :app:mainApkListPersistenceDebug UP-TO-DATE
> :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources
> UP-TO-DATE :app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT error: check logs for details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
> BUILD FAILED in 13s 9 actionable tasks: 1 executed, 8 up-to-date
In gradle.properties change android.enableAapt2=false to true
You can actually have problems in the resources but these will not be displayed if you do not correct this problem first:
The option 'android.enableAapt2' is deprecated and should not be used
anymore. Use 'android.enableAapt2 = true' to remove this warning. It
will be removed at the end of 2018.
within your gradle.properties file that is located in the root of the project, replace:
android.enableAapt2
with:
android.enableAapt2 = true
Try updating your gradle plugin. Fixed my error.
within gradle.properties file that is located in the root of the project,
I have just commented on this line, now works perfectly
android.enableAapt2 = true
Please make sure that the images and icons you included in your project is Imported by android studio or Drawable importer plugin.
to install this plugin you have to go File>setting> plugin.
then type Drawable importer
Your problem is with android.enableAapt2 .
You should check what's missing or the package is imported correctly.
Search for file android.enableAapt2 or that keyword.

Android Studio build errors when project is in a subfolder of Github

I created a new project in Android Studio and I put the project folder inside another folder in Github. It's like this Code/ProjectName
However I'm having problems when I try to build my project with Gradle, this is the output in the Gradle Console:
Executing tasks: [:app:generateDebugSources, :app:generateDebugTestSources]
Configuration on demand is an incubating feature.
:app:preBuild
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources
C:\Users\UserName\Documents\ProjectName\Code\ProjectName-Ver-0\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\drawable-mdpi\abc_switch_track_mtrl_alpha.9.png ERROR: Unable to open PNG file
C:\Users\UserName\Documents\ProjectName\Code\ProjectName-Ver-0\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\drawable-ldrtl-hdpi\abc_ic_ab_back_mtrl_am_alpha.png ERROR: Unable to open PNG file
Error: Failed to run command:
C:\Users\UserName\Desktop\UserName\Java\AndroidStudioSDK\build-tools\21.1.2\aapt.exe s -i C:\Users\UserName\Documents\ProjectName\Code\ProjectName-Ver-0\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\drawable-ldrtl-hdpi\abc_ic_ab_back_mtrl_am_alpha.png -o C:\Users\UserName\Documents\ProjectName\Code\ProjectName-Ver-0\app\build\intermediates\res\debug\drawable-ldrtl-hdpi-v17\abc_ic_ab_back_mtrl_am_alpha.png
Error Code:
42
Output:
C:\Users\UserName\Documents\ProjectName\Code\ProjectName-Ver-0\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\drawable-ldrtl-hdpi\abc_ic_ab_back_mtrl_am_alpha.png ERROR: Unable to open PNG file
:app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: Failed to run command:
C:\Users\UserName\Desktop\UserName\Java\AndroidStudioSDK\build-tools\21.1.2\aapt.exe s -i C:\Users\UserName\Documents\ProjectName\Code\ProjectName-Ver-0\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\drawable-ldrtl-hdpi\abc_ic_ab_back_mtrl_am_alpha.png -o C:\Users\UserName\Documents\ProjectName\Code\ProjectName-Ver-0\app\build\intermediates\res\debug\drawable-ldrtl-hdpi-v17\abc_ic_ab_back_mtrl_am_alpha.png
Error Code:
42
Output:
C:\Users\UserName\Documents\ProjectName\Code\ProjectName-Ver-0\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\drawable-ldrtl-hdpi\abc_ic_ab_back_mtrl_am_alpha.png ERROR: Unable to open PNG file
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 11.013 secs
Not only that.
I also get an error that says Cannot resolve symbol 'R'
I think it has to do with the fact that the project code is inside a sub folder of Github. But I need to have it there.
I created another project to test and I don't get any of this error since is not connected to Github.
Extra:
So I confirmed that if I take the project folder out of the Github root folder, the project does not show me these errors when I open it on Android Studio.
If anyone knows why does this happen and there is a way to fix it, I would really appreciate it.
Create a git repository with the same name of the project
clone it to the folder where the Android project lies. ( copy cut paste the project to another folder (CopyFolder) before cloning .
so, after cloning you will get a folder with the same project name as before. with no contents there will be only a .git file . let it be there .
copy and paste the contents of your actual Android project in (CopyFolder) to the cloned folder. Make sure you only contents inside the folder is needed not he entire folder.
(if you are using git bash to update git use these commands )
git add .
git commit -m " updated "
git push
and there you go ... run the project. It wont show any error.

Gradle Build Error on Android Studio in Ubuntu 12.04 LTS

Well, after too much googling for about two days and trying most of the recommended work arounds suggested on this platform, my problem is not solved yet!!
It goes like this...
I have started android app development recently with Android Studio on Ubuntu 12.04 LTS.
Whenever I open my project, gradle build always finishes with following two errors;-
Executing tasks: [clean, :app:compileDebugJava]
Configuration on demand is an incubating feature.
:app:clean
:app:preBuild
:app:preDebugBuild
:app:checkDebugManifest
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
/home/vivek/AndroidStudioProjects/MyApplication3/app/src/main/res/drawable-mdpi/ic_launcher.png: Error: Cannot run program "/home/vivek/Documents/android-studio/sdk/build-tools/21.0.1/aapt": error=2, No such file or directory
:app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> /home/vivek/AndroidStudioProjects/MyApplication3/app/src/main/res/drawable-mdpi/ic_launcher.png: Error: Cannot run program "/home/vivek/Documents/android-studio/sdk/build-tools/21.0.1/aapt": error=2, No such file or directory
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 6.776 secs

Categories

Resources