Error related to resources_ap after upgrading to Android Studio 3.4 - android-studio

I upgraded Android Studio 3.4 today. I am no longer able to run the the app. I have cleaned the project, restarted Android studio many times. I have also invalidated cache to no avail.
I am getting the following error when installing the app:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexWithInstantRunSlicesApkForDebug'.
> java.lang.RuntimeException: java.io.FileNotFoundException: E:\...\app\build\intermediates\instant_run_split_apk_resources\debug\instantRunSplitApkResourcesDebug\out\slice_1\resources_ap
Could anyone offer a tip on how to remedy this?
Edit:
I have two projects with different behaviors related to this issue:
Project A initially had this issue. I disabled Instant Run per the answer, the problem was solved. I enabled Instant Run later, and Project A is still working fine.
Project B also had this problem that has been remedied by turning of Instant Run. However, its problem will occur as soon as Instant Run is turned on. I do not what difference between these two projects results in this. One suspect is library C project. Library C is a part of Project A (i.e. its source code, resources are in Project A). However, Project B uses the aar of Library C as a module.

Issue should be fixed in Android Studio 3.4.2.
EDIT: Here is my old answer on how to fix it in Android Studio 3.4.0 and 3.4.1:
Using Gradle 5.4 instead of 5.1.1 helped me with this error.
Update gradle-wrapper.properties file with:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-all.zip
Please note I haven't tested older Gradle versions, so it's possible even (for example) 5.2 version will work. You can see all Gradle releases here - https://gradle.org/releases/

Switching off Instant Run as a workaround (File/Settings/Instant Run) seems to eliminate the problem.
According to OP it is possible to turn Instant Run back on without the problem recurring for some projects.

There is no need to turn off Instant Run.
Just delete the '.gradle' directory in the project and build directory inside the 'app' module.
Perform Clean Project and Rebuild Project.
This will solve the issue.

This is caused by "instant run" feature in android studio 3.4 , you can disable it by:
Open the Settings or Preferences dialog. Navigate to Build, Execution, Deployment > Instant Run. Uncheck the box next to Enable Instant Run
Enjoy...!

Go to your project folder and move everything from ...\app\build\ to some other folder outside project. (to clear build folder with back up)
In my case clearing the build folder solved the probem, till then i was disableing the instant Run option for every new install.

I tried both "Gradle 5.4" and "Switching off Instant Run" solutions but they didnt work until I turned on "Wait for Debugger" option until "Developer Options" in my phone (Huawei Mate 10). I have confirmed that this is only working with "Instant Run" off as well.

This problem happened to me on Windows. I solved it by disabling instant run.
I also have the same Android Studio version on Linux and it works fine with instant run enabled.

This is fixed in 3.4.2. Just update to the latest version of Studio. https://androidstudio.googleblog.com/2019/07/android-studio-342-available.html

This same error happened when I updated to Android Studio 3.4.2, I updated the tools-build-gradle to 3.4.2 and the problem disappear.

Switching off Instant Run as a workaround (File/Settings/Instant Run) seems to eliminate the problem.

Related

Android Studio stuck at "Analyzing..."

In my Android project (Android 4.2 Canary 15), completion does not work anymore, and neither does syntax highlighting. This is happening in one Android project only (the others work well).
I have tried to clean, rebuild the project, create a new project and import files, but no changes... I have tried to delete .idea directory and all .iml files, but not better...
In the "File" menu, I've just tried the option "Invalidate caches / restart" and now all classes in my project are blocked at the state "Analyzing..." and completion still does not work...
Build and run project work, and my application starts well on my phone, but all intellij features
are inactive.
It appears that the Kotlin plugin was, indeed, the culprit.
Today (24 May 2021), a new version was released 1.5.10, and as soon as I installed it, everything went back to normal.
Synopsis: After upgrading from version 1.4.32 of Kotlin plugin to 1.5.0, code inspection, completion, linking to sources, javadocs, etc. all stop working (stuck at "Analyzing..." as the images here and here show), and only return for a few seconds/minutes when sth triggers a new analysis (eg. a gradle build, commit, loading new files, etc).
History of the plugin updates for reference can be found here
you can just change the Kotlin version to something else and then gradle sync again
This will solve the issue
you will find it in build.gradle file(project)
ext.kotlin_version = "1.5.10" //I used this
you can also roll back to your previous version. If you want this should not recreate the issue.
Android Studio -> File -> Invalidate Caches and Restart
Nothing else helped me.
Try it:
File --> settings --> Plugins --> Android ButterKnife Zelezny --> disenable
From my project I deleted the files
.idea/gradle.xml
.idea/workspace.xml
and it solved it for me.
Seems to be that I had previously configured the project's gradle incorrectly and even after several reinstalls I wasn't getting any luck.
I just update the Koltin version to 1.5.20 and it works!!
Kotlin version 1.4.10 magically stopped working in the IDE.
The problems are not related to the IDE version but rather to the integration of the kotlin plugin and the IDE.
kotlinVersion = '1.5.10'
classpath 'com.android.tools.build:gradle:4.2.2'
Then Sync Project and Compile.
Finally you can see that the problem of Analyzing disappears and the IDE becomes intelligent again.
It is possible that after updating kotlin you have minimal errors in other libraries so you also have to update or fix them (I happened with Room)
GL
This is a looming AS IDE issue correlated with the Kotlin plugin, Have tried literally every answer here with tooth and nail, but nothing worked. There were chains of errors. Finally, removing the AS cache folder manually worked for me -
%USERPROFILE%\AppData\Local\Google\AndroidStudio2020.3\caches
Artic fox sucks!
You may also try to update the Kotlin plugin to the latest if possible and see if it makes any difference.
The one solution that worked for me (working in Canary 2021.1.1) was to completely uninstall the Kotlin plugin from Android Studio, restart, let Android Studio install it automatically, and then everything worked again.
The root cause of this issue was that Android Studio "accidentally?" updated Kotlin plugin to an M1 version (I'm on x64), namely 211-1.5.30-M1-release-141-AS7442.40, when updating the plugin. I'm not sure why, but from now a check of what is going to be updated in Canary seems mandatory to avoid these kind of stuff to happen.
this issue comes from plugins
1- update plugins
2- step by step disable plugins to find incorrect plugin
3- as advance people please report issue to providers for solve the problem
in Arctic Fox version (2020.3.1) I fixed it by updating Gradle Plugin version 7.0.0.
This solution is 100% working for the above issue
ext.kotlin_version = "1.5.21"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
In my case, I just update the dependency "androidx.core:core-ktx:1.3.2" to "androidx.core:core-ktx:1.6.0". And it's gone, working normally
After many hours, I finally uninstalled Android Studio, delete all Android directory, clean registry and reinstall Android Studio stable version.
disable Compose plugin. the only way work for me.
If you are using
Jetpack Compose 1.0.5 (haven't tested with 1.0.0-1.0.4 but they should work too)
Java 11
Kotlin 1.5.31 (tested 1.5.10 working too)
the other answers don't work
What works is the following in your project build.gradle:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "11"
useIR = true
freeCompilerArgs += [
"-Xallow-jvm-ir-dependencies",
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
]
}
}
(compose compiler was blocking Kotlin compiler from completing jobs)
and Invalidate Caches & Restart
for me file analysis is only getting stuck in kotlin files with co-routines. upgrading co-routines version to the latest helped me.
Sometimes some files are stucking to me at analazying, I resolve that issue by:
Just copy / paste that file with the different name
Then remove the original file and rename the copied file with the original name.

could not find extension implementation class org.jetbrains.kotlin.idea.scripting.gradle.roots.GradleBuildRootsManager

My project works and builds successfully on my Mac but I cloned from github and although Android Studio appears to work normally, the project wouldn't build. I setup this project using Kotlin DSL.
Gradle sync failed: could not find extension implementation class org.jetbrains.kotlin.idea.scripting.gradle.roots.GradleBuildRoot
Tried invalidate cache, removed all .gitignore rules but it's still the same.
Any ideas?
I had the same issue (Note : Running Linux/Ubuntu 20.04 LTS and Android Studio 4.1.1).
Things I tried that did NOT work and error persisted :
Invalidate Caches / Restart
Reboot
Nuking the .gradle and .m2 folders
Android Studio re-install
Downgrade kotlin gradle plugin from 1.4.21 to 1.4.10
What did work :
Moving the project to a different folder/location on disk and open Android Studio
As soon as I moved the project back to the original location I would start getting the same error. This lead me to believe it was some sort of caching issue, separate from the caches "invalidated".
Solution :
Android Studio / Intellij creates a hidden folder called :
On Linux :
AS : ~/.cache/Google/AndroidStudioX.X
IJ : ~/.cache/Jetbrains/IntelliJIdea2020.X
On Mac :
AS : ~/Library/Caches/Google/AndroidStudioX.X
IJ : ~/Library/Caches/Jetbrains/IntelliJIdea2020.X
On Windows:
AS : %HOME%\AppData\Local\Google\AndroidStudioX.X
IJ : %HOME%\AppData\Local\Jetbrains\IntelliJIdea2020.X
Inside this folder are other various folders, however I removed the relevant workspace file (workspace/[project name].[hashed value].xml) after which problem went away when opening the project again, from its original location.
So it appears that "Invalidate Caches / Restart" does not "Invalidate" all caches!
I hope this resolves you problem!
Update
As this answer has had quite a few upvotes it would appear that this might be a ongoing bug with Intellij. If anyone has this problem, before resolving with the suggested solution consider checking there isn't an open issue on the bug tracker and submitting a new issue : https://youtrack.jetbrains.com/issues
Feel free to edit this update with issue if one is opened.
Update 2
Issue opened by #GeniusRUS :
https://youtrack.jetbrains.com/issue/KT-44937
For Mac users delete the following file:
~/Library/Caches/Google/AndroidStudio4.1/workspace/<your_project_name>.58dfbe93.xml
PS: Thanls #Mark Keen for solution.
basically i deleted .idea folder and then invalidate and restart ... error goes away and built successfull.
This probably isn't the "correct" solution, however, it worked for me. I had to download a newer (Canary) Version of Android Studio to get this error message to go away and to finally build my Android project once again. I found this YouTrack JetBrains issue where people also suggested reverting to previous, known working, versions of Android Studio to get their projects to build again.
This is a SUPER frustrating issue and I hope that one of the approaches resolves your build issues for you!
Here are the Android Studio Versions Download page for convenience.
After moving projects and files around I had also the honor to enjoy this error in Android Studio 4.1.1 (under Windows 10). Unfortunately, none of the above solutions worked for me but they helped me to narrow down the issue.
So, I found that there is a folder with workspaces under:
%HOME%\AppData\Local\Google\AndroidStudio4.1\workspace\
There are a couple of *.xml files named like the android projects. I deleted the one that didn't work.
Then switched back to Android Studio and used the Files > Invalidate Caches / Restart... feature. Android Studio restarted and the problem was fixed.
Bonus: How I found the workspace folder?
I used the Procmon.exe from Sysinternals where I filtered by the Process Name = studio64.exe. I then used the elephant-with-the-arrow button (Sync Project with Gradle Files) in Android Studio. At the end of the recording there was the workspace folder that Android Studio used just before Gradle failed.
I added a "problem" ticket to YouTrack, where I described my case in detail.
The support agent said the issue has already been fixed in the IDEA 2021.1 platform.
And also gave recommendations for this case
Link to issue
https://youtrack.jetbrains.com/issue/KT-44937
I fixed the issue by changing the root project directory name. You can try that.

Could not find a JavaToKotlinConversionProvider

I'm not able to create a new project in the android studio. I am getting a warning message
java.lang.RuntimeException: Could not find a
JavaToKotlinConversionProvider, even though one should be bundled with
Studio at
com.android.tools.idea.npw.model.JavaToKotlinHandler.getJavaToKotlinConversionProvider(JavaToKotlinHandler.java:56)
at
com.android.tools.idea.npw.template.TemplateValueInjector.addKotlinVersion(TemplateValueInjector.java:410)
Go to Preferences -> Plugins -> Kotlin and update the Kotlin plugin to the last version even though you don't write your code in Kotlin.
I have the same error, I've juste disabled the kotlin plugin and after restarting the IDE, just re-enable it. After that final restart, every thing works fine.
Go to file and the plugin in android studio and update your Kotlin plugin...
I opened an old project (by old I mean another project) and did everything Android Studio said to give me a successful build (I faced some errors when I tried to build the project that I could build couple weeks ago and actually I fixed them, updating gradle and stuff like that, not code issues of course).
After that I could create new project same as before.
Update seems like in order to keep Android Studio happy we have to keep Kotlin plugin enabled, interesting.
I solved this problem by doing this:
File->Settings->Plugins
Click the Installed tab at the top.
Search "kotlin" and click the result that shows up.
Click Enable at the top right
settings>plugins>check Kotlin >Apply then Ok solved it for me.
It occurred due to migration from Android Studio 3.2 to 3.3
Goto File-->Invalidate Caches/Restart
This will solve the problem.

Auto complete not working in android studio

I am a starter in android development and I started off with eclipse.. But it started giving lot of problems. So I switched to android studio. Got it set up successfully and for couple of weeks it was ok. Now, for some reason, the auto complete feature is not working. It is not giving any choices while typing, so I tried ctrl-enter. It says no suggestions. I browsed through similar queries and tried the following.
Disabling Power Save in File menu.
Checking basic complete and smart type completion in IDE settings (editor)
Invalidate caches and restart.
But non of these seems to work.
Try with CTRL + space and you will get the drop down .
I had the same issue and solved it.
Go File> Invalidate Caches / Restart... > Click at Invalidate and Restart
Then you can also check if Power Save Mode on File menu is disabled.
Source: Android Studio - Auto complete and other features not working
These following steps are working for me:
Close android studio
Go to path/.AndroidStudio3.5/system/ delete caches folder
Start Android Studio
You should Try this way File->Invalidate Caches/Restart or you can find solution by using below link
https://stackoverflow.com/a/58214439/11404883
In my case on Android Studio Artic Fox edition there were strange problems with autocompletion and suggestions because of old version of Gradle plugin. I have updated to
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21'
and it worked as expected. Hope it will be helpful for new visitors like in my case it would.
In Ubuntu 21 I had tried
$ rm -rf ~/.cache/Google/AndroidStudio2020.3/caches/
I followed all the steps from various answers and sources, still didn't get it to work. Code completion and Syntax Highlighting was not working.
I restarted using Invalidate Caches and did Gradle Sync atleast 10 times.
It was working in main flavor, but not in other flavors! In this project we have multiple flavors.
So finally the solution was found using
Android Studio product flavors only recognized one out of two flavours
Just selecting the correct Build Variant solved my issue.
Delete everything inside caches folder
C:\Users\<user_name>\AppData\Local\Google\AndroidStudio<version_x>\caches
and restart android studio

Android Studio is installing old apk on device

I am developing an Android app using Android Studio (0.89 Build #AI-135.1404660, Built on Sept 3,2014) using both emulator and Nexus 4 device.
I had the same issue with a version prior to that.
The problem is that after I changed my code and resource files, I still get the old apk installed on the device or emulator.
What do I need to do to get it to run current code? Is it a building config?
Is it a known issue with Android Studio?
Or with a Nexus 4 device?
This is the second time it has happened, and I resolved it(then) after trying one of the steps below. They have not worked for me again.
Here is what I've tried
Build > Clean Project > Restart Android Studio > Run
Build > Rebuild Project > Run
Step 1 plus Uninstalling of apk on device
Step 2 plus Unistalling of apk on device
Adding erroneous resource entry then running.
I have read the following:
Android apk install: How to clear files from old version?
adb - How to reinstall an app, without retaining the data?
Device still has the old apk
Android build doesn't update code base or resources for target .apk on device
None has worked so far.
I had the same problem. After trying numerous methods that didn't work, I realized that I had accidentally changed an option in my "Run Configuration". Here's exactly what I did to fix the issue.
Run --> Edit Configurations
With your configuration selected on the left panel (mine says "app"), in the General tab on the right panel, there is a section called "Before launch". This section should have an option added called "Gradle-aware Make", but I had accidentally removed it.
I re-added it by pressing the "+", then clicking OK in the popup (leave the input box in the popup blank).
Click apply.
This fixed the problem immediately. Hope this helps someone!
Run / Debug Configurations / Miscellaneous TAB
[] Uncheck: Skip installation if APK has not changed
Android Studio doesn't always detect small changes in code.
The behaviour is erratic. I solved it by reviewing my code.It turned out that there was a resource file that was invalid. Try reverting back to the last working version of your code before the current changes... Probably a known issue that will be/was resolved out of Beta
Google thinks it is a feature, not a bug
https://code.google.com/p/android/issues/detail?id=156263
Their proposed solution is to copy the apk(s) instead of manipulating the filename, as in e.g.
Copying APK file in Android Gradle project
I've spent way too many hours to keep this to myself. The way I fixed it was that I noticed some hours later that I was using different layout version in res/ .... I have actually two versions of layout (layout-v26) and (layout). All this time I was modifying the other one and uploading different one. Maybe its just a newbie mistake but I hope somebody will find it useful.
The reason why there are 2 version was because of " autofillHints="" -> quickfix -> create new version of layout "
image of my tree
I am using android studio for building flutter app, I was facing the same issue untill I did the following:
From Android Studio, go to Tools-Flutter-FlutterClean
It resolved my problem as of now.
Check Your Layout Files.
I ran into the same problem and I realized, it gives some problem if you have same layout in multiple orientations(portrait and landscape). If one is changed other remains unchanged and then it creates a conflict. So android studio installs the one with the previous layout
PS: This was happening in my case.
The problem occurred on my Android 11 devices. I guess ART ran old code dex2oated.
Solution:
Run / Debug Configurations - General - Always install with package manager (disable deploy optimization on Android 11 and later), and check the option.
I was also facing this issue and get solution by deleting build folder manually because some time ide cannot be able to delete this. So go to the app folder and find build folder delete this and after clean and build project and run again.
projectname->app->build
You should select "Deploy default APK" option in Run/Debug Configurations. After that Android Studio will upload and install new apk to your emulator/device when you run application.
In android studio. at right side. see gradle option. click it. and then press circular arrows button shown in red square.
Same problem, none of the solutions mentioned here had any effect. I had to disable the "Allow parallel run" in "Menu > Run > Edit configurations...".
You can read more about this option here: How to run the same project multiple times in IntelliJ IDEA?
The solution to this issue is actually very simple.
Android studio is actually not detecting some small changes that you have made to the application. That is why it is installing the previous builds.
The solution is easy -> Remove the previous builds.
In the right side, go to gradle tab.
Expand Tasks. Find "clean" or "cleanCache" task or any task that starts with "clean". Double click to run that task.
Expand "app". and do the same.
Then File> Invalidate cache and restart.
Enjoy!! Your problem is solved...
My devices also ran old states - dont know from where in my git it has taken these.
I created a new configuration (default is "app") and it worked.

Resources