Android Studio: Gradle project sync failed after update - android

I have been messing around with Android Studio after a long time without doing it. I tried to use Git (and after deleted the .git directory) and I also performed an Android Studio update some I am not sure where things went wrong.
I ended-up re-importing the project and now I get the following error:
app:sync failed -> Plugin with id 'com.android.application' not found.
android studio error screenshot

Thank you for the suggestions. In the end I decided to create a new empty project as to get a new clean gradle and structure and paste the rest of files in-there. It has worked so the problem is solved. Not sure yet what I had messed...
Thank you all.

Related

Clean project error with databinding: Unable to delete file androidx.databinding.library.baseAdapters--setter_store.json

I use Databinding. Sometimes while I make changes project may be broken. Then I go to Build -> Clean project & Re-Build project. And I get some strange error:
Unable to delete file: {path_to_project}\app\build\intermediates\data_binding_dependency_artifacts\debug\dataBindingMergeDependencyArtifactsDebug\out\androidx.databinding.library.baseAdapters--setter_store.json
Every time I don't know how to fix it, because I get this error on clean or rebuild. Even if I make Invalidate caches / Restart the problem isn't gone.
If I try to delete this file manually I get error that file is using by another process. Then I close project and successfully delete this file. But when I open the project and build it I get the same error described above.
As I can see the problem is about databinding, but I'm not sure because I saw the same problem with other files from other users on StackOverflow. Sometimes problem is gone by itself, but usually it isn't. Maybe the problem occurs because of errors in layout files, but how to find it out if there is no errors in build log.
Has anyone meet that error? Any ideas how to fix that situation without crush whole the project in undefined time range?
I close Android Studio, delete the app\build folder then reopen Android Studio. Note that all instances of AS must be closed for Windows to let you delete the build folder.
Put Below command in Android Studio terminal.
gradlew --stop
So, the problem is still here but all answers don't solve it. Project doesn't compile for a reason, usually it's some kind of mistake, and if you just delete build folder (which contains file Android Studio is unable to delete) it will not solve problem.
When you are trying to compile project you may get a dozens of errors in generated files (databinding, room, etc). Unfortunatelly, errors are not displaying in the usual window, but if you expand this generated files with errors, you probably will see the real problem, your mistakes you didn't fix when was changing your classes related to generated files. Just fix these mistakes and compile project again. Note: you probably should to look at warnings too.
But if you already got error Unable to delete file you won't see errors in generated files. You need to restart Android studio (if it won't help, you need to delete app\build) and try to compile your project. After that you will find generated files with errors in build tab.
Hope it helps!
First follow this 4 steps
Remove your file generated (build folder)
Clean your project ( simply run cmd command - > gradlew clean)
Invalidate cache and restart Android Studio
Restart computer
If not helpful please try following steps
Gradle sync;
Reinstall Java JRE & Java SDK;
Reinstall the latest version of Android Studio
Rolling back to the previous AS version
Invalidate cache and restart Android Studio
Delete the gradle and .gradle directories in the project directory;
Delete the .gradle directory in your directory;
Run gradlew clean ( simply run cmd command - > gradlew clean)
I have the same problem, and tried the method mentioned above. I could not find the related class in the error message when I searched in the project directory.
In the end, I suspected that it maybe ~/.gradle problem, and then recompile after deleting, and finally solved.
mv ~/.gradle ~/.gradle_bak
Try to disable the daemon and parallel build in gradle.properties
org.gradle.daemon=false
org.gradle.parallel=false
I tried most of the solutions above but seemed not to find them working.
But here is what I did to get my project up and running again.
I am assuming this is happening because you are using dataBinding.
browse to the dataBinding section in your app gradle file
now disable dataBinding by setting to false.
next, rebuild your project and you will notice an error about something to deal with missing a dataBinding in xml file.
Next enalble dataBinding by setting to true this time.
next, rebuild your project.
It should have cleared that strange error.
Forgive me for the strange explanation but am new to contributing to stackoverflow.
It is because of databinding cache issue. We need to delete that cache by disabling it first. I solved the issue after changing the properties of the gradle.properties file:
org.gradle.daemon=false
org.gradle.parallel=false
android.enableBuildCache=false
org.gradle.caching= false
android.databinding.enableV2=false
and
dataBinding {
enabled = false
}
Clean and rebuild the project. After rebuilding it will show errors. Then change all the configuration (make all properties true) and clean, rebuild. It will work absolutely fine.

Android studio: this project is not gradle based project

I have one project which was initially in eclipse, then i managed somehow to convert it to gradle and everything was working fine in Android Studio.
But then i didn't work some time with the project and after few months when i returned to project i am surprised that Android Studio has problems with this project.
When i selected "Android" from top left dropdown in AS, where you should see the project as Android, i saw no files, then i did something and now i see there one empty folder Java.
If i hit button "sync project with gradle files" AS says message as posted in name of question, but it is gradle based project.. there are gradle files etc.
Do you someone know why is this problem? Why it should stop work like this?
Thank you
Make sure you open the project from its root directory. i.e. the directory which contains the top level build.gradle file.
The missing top level gradle file is what causes this error.
For native Flutter Projects:
Note that this error will also appear if you "sync your project with Gradle files " in the root directory. Gradle works only in your android directory (flutter_name/android).
Configure Gradle version
I got this error because i wanted to change some build values like the Gradle version and the Gradle plugin version (and other build values ex. kotlin):
In your current project: File>Open
Select directory: user/StudioProjects/flutter_name/android
Open directory in a new window
After it is opened it will load some packages (see right bottom), which will take some time.
Under File>Project Structure Project you can set the gradle version and under Modules variables of your build
Now you can sync your project with Gradle files or at least read out the error messages, that come with your configuration
After configuration, you might need to restart your project with File>Invalid Caches/Restart....
That worked for me:
copy the file build.gradle
drop the copied file build.gradle in
your app/project folder .
My project stopped showing all of sudden and already had build.gradle file.
I just reopened it via File > Open.

How to fix com.android.builder.internal.aapt.AaptException: Failed to crunch file?

I have the latest version of Android Studio (as of Sep 21, 2016). When I create a brand new project in Android Studio and try to build it, I am getting this build error:
Error: com.android.builder.internal.aapt.AaptException: Failed to
crunch file
H:..pathTo..\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.2.1\res\drawable-xhdpi-v4\abc_list_selector_disabled_holo_light.9.png
into
H:..pathTo..\app\build\intermediates\res\merged\debug\drawable-xhdpi-v4\abc_list_selector_disabled_holo_light.9.png
What does this mean? And how do I fix it?
Build log:
https://jpst.it/NCnu
Amazing. It's 2016 and Google's tool chain still has these annoying file path limitations.
Error: File path too long on windows, keep below 240 characters
Move project further up your project file path and the problem goes away!
There is a workaround. If you add the following to the project build.gradle file, inside the allprojects section, it will move the Build output files to this folder. Meaning the app will now build.:
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
It does give you an additional app module at the root of the project but this is a much more convenient option than moving whole Project folder path.
I Found the same Error (Error: com.android.builder.internal.aapt.AaptException: Failed to crunch). I Copied the directory one level above. It Works!
The solution that help me was to delete node_modules folder,
remove android platform by running the command ionic platform remove android
and then go upper the project folder in system hirarchy
and then:
npm install
ionic platform add android
ionic run android
I faced this problem when trying to generate an unsigned apk using Gradle in Android Studio IDE 3.0
I solved it by creating a fresh new project and copied each file with the slightest amendment needed e.g. changing the package name, but I left the icons as they are thus I haven't added a new icon in several files like I did in the previous project.
And the problem was solved, it builds with no such error.
(However the generated apk file wasn't found in app\build\outputs\apk but inside app\build\outputs\apk\debug, but that's another problem which is not so important I hope).
I encountered a similar error. Just try to reduce the path length by moving the project folder up.
This will surely solve the problem.
Update you gradle to latest one, it solve the problem, i was also facing same problem, it work for me.
I was using classpath 'com.android.tools.build:gradle:2.0.0', then replace to
classpath 'com.android.tools.build:gradle:3.0.0' , it work for me.

android studio gradle refresh failed (The system cannot find the file specified)

Error:Could not open initscript class cache for initialization script
'C:\Users\Subash\AppData\Local\Temp\asLocalRepo2.gradle'
(C:\Users\Subash.gradle\caches\2.2.1\scripts\asLocalRepo2_cd0g6mnzdabuvxgeqlhhrxv0q\InitScript\initscript).
java.io.FileNotFoundException:
C:\Users\Subash.gradle\caches\2.2.1\scripts\asLocalRepo2_cd0g6mnzdabuvxgeqlhhrxv0q\InitScript\initscript\cache.properties
(The system cannot find the file specified)
UPDATE:
Check my answer here for full details
I have the latest version of Android Studio and I faced that problem, the only thing that worked for me is to:
1-Navigate to C:\Users\user.gradle\caches\2.4\
2-Copy the folder "scripts" and paste it somewhere safe just in case anything went wrong you will place it back
3-Delete this folder "scripts" from the directory C:\Users\user.gradle\caches\2.4\
4- Sync Project with Gradle Files and you are done.
When you sync your project Android Studio will generate new cash files.
It worked for me I hope it will work for you...
I don't know why a great developer as Google can't manage this issue by them selves it is very easy to delete the cached folder and regenerate it programmatically. Any way just navigate to C:\Users\user.gradle\caches\ and open the latest version folder, then delete the scripts folder. Go to android studio and sync project, that should do it.
Exit Android Studio, remove the Gradle cache folder which path is in the error message, and restart.
You could try to delete this : C:\Users_USER_.gradle\caches_GRADLE_\scripts_XXX_\InitScript\initscript\cache.properties.lock
I had the same problem and after deleting it all works fine.
Another common problem with Gradle is synchronization which is solved adding the correct path of JDK but this is another story.
I hope to help.

Error running MyActivity: Gradle project sync failed. Please fix your project and try again

I am new to Android Studio and I have just created a new project with only one Activity with fragments(Android studio created that), and when I ran the MyActivity.java , error occurs:
Error running MyActivity: Gradle project sync failed. Please fix your project and try again.
Nothing more in my event log.
I have no idea why it is, and This link did not helps.
One clue is that Gradle project sync in progress is flowing all the time , just after I restart the Studio.
Goto File -> Invalidate caches / Restart
Shutdown Android Studio
Rename/remove .gradle folder in the user home directory
Restart Android Studio (It will download gradle metadata and data)
Gradle build succeed
Rebuild project
Done
The exact same error message also pops up if there is a syntax-error inside your AndroidManifest.xml file. So if the above won't work - which it didn't for me - then check the AndroidManifest.xml syntax. That will save you thousands of frustrating hours.

Categories

Resources