com.android.tools.idea.run.ApkProvisionException: Couldn't get post build model - android

After downgrading from Gradle 6.1.1 to 7.2 and Android Gradle Build tools 7.1.0 to 4.0.1 (by switching branches in Git) I got the following exception in the Run console (tool window) of Android Studio Bumblebee 2021.1.1 (when trying to run the app on a device):
Unable to determine application id: com.android.tools.idea.run.ApkProvisionException: Couldn't get post build model. Module: My_App.app Variant: debug
The Grade build runs successfully but the app won't be installed in the device.

In Android Studio run File > Invalidate Caches ... and restart (you don't need to select the optional "Clear file system cache and Local History"). Just to be sure, also run Build > Clean Project.

I have faced this issue when i upgrade to android studio Dolphin. So for me this workaround was to delete the existing app configuration from Run/Debug Configurations.
After that add new configuration by clicking the left top + icon and then add Android App.

Related

Android Studio - Gradle sync failed: Already disposed

After updating to Android Studio 3.2 Beta 1, I started getting the following error for two different projects:
Gradle sync failed: Already disposed!
There is no error with Android Studio 3.1.3, and there was no error with various canary versions of Android Studio 3.2 before updating to beta 1.
I already tried everything I can think of (e.g. complete cleaning of project, including all generated .gradle/.iml/.idea files/folders, as well as a complete invalidate cache and restart of Android Studio) without success. The build works as expected from command line using Gradle.
This is not a duplicate of Android Studio Gradle Already disposed Module
EDIT
The event log is showing
Unable to save plugin settings: The plugin org.jetbrains.android failed to save settings and has been disabled. Please restart Android Studio
In the "IDE Fatal Errors" window, I am seeing the following exception:
'Gradle: backport-util-concurrent:backport-util-concurrent:3.1#jar' already disposed: --------------Creation trace:
java.lang.Throwable
at com.intellij.openapi.util.TraceableDisposable.<init>(TraceableDisposable.java:45)
at com.intellij.openapi.roots.impl.libraries.LibraryImpl.<init>(LibraryImpl.java:103)
at com.intellij.openapi.roots.impl.libraries.LibraryImpl.<init>(LibraryImpl.java:69)
at com.intellij.openapi.roots.impl.libraries.LibraryTableBase$LibraryModel.readExternal(LibraryTableBase.java:327)
at com.intellij.openapi.roots.impl.libraries.LibraryTableBase.loadState(LibraryTableBase.java:64)
at com.intellij.openapi.roots.impl.libraries.LibraryTableBase.loadState(LibraryTableBase.java:30)
at com.intellij.configurationStore.ComponentStoreImpl.doInitComponent(ComponentStoreImpl.kt:375)
at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:331)
at com.intellij.configurationStore.ComponentStoreImpl.initPersistenceStateComponent(ComponentStoreImpl.kt:121)
at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:96)
at com.intellij.openapi.components.impl.PlatformComponentManagerImpl.initializeComponent(PlatformComponentManagerImpl.java:54)
EDIT2:
More recent version of Android Studio 3.2 are having the same issue.
As it turned out, the problem was that I was trying to open a project directory that was a symlink to the actual location (on the same partition). Gradle (on command line) had no issues building the project from the symlinked location, however, opening it in Android Studio resulted in the obscure and non helpful error described above.
Simple solution
1.Delete module folder and modules.xml file under .idea folder.
2.Close Android Studio
3.Reopen and sync
Possible duplicate problem:
Android Studio 3.0 - Unable to save settings: Failed to save settings. Please restart Android Studio Android Studio 3.0 - Unable to save settings: Failed to save settings. Please restart Android Studio
This worked for me: Delete the .idea folder.
1) Go to File--> Settings -->Plugins Disable any plugins not loaded (i.e. red in color) #friederbluemle This may not apply to you.
2) Enable the one plugin, Android Support
3) Right-click on your 'app' directory (contains your module gradle.build file) in Android Studio and select 'Show in Explorer' --- this opens that directory.
4) Quit Android Studio. Get out of any and all instances of Android Studio to allow you to then delete the fold, .idea, in that directory.
5) Restart AS, you'll notice the project will not come up -- you'll have to pick in the dialog window that appears. That's ok. Pick it, and it will 'rebuild' the folder, .idea.
6) Go to File--> Settings -->Plugins Enable any and all plugins if any.
What worked for me was going to Android Studio File and Invalidate/Restart options.
What worked for me is as follows
Delete the .idea folder
Close Android Studio
Reopen Android Studio and allow it sync your project all over.

Android Studio 3.1 Gradle Plugin 4.4 KotlinNullPointerException

Surprisingly, my project is completely written and developed in Java only, it's also not containing any dependencies declared for Kotlin. Yet I'm receiving this weird error:
A problem occurred configuring project ':app'.
Configuration:
When I use the below configuration, it works perfectly fine, builds the project and the app gets installed on my device/emulator:
Android Studio Version: 3.1 Stable release
Gradle Plugin Version: 3.0.1
Gradle Distribution URL:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
BUT When I use the latest configuration declared below, the error occurs while running the app as shown in the images:
Android Studio Version: 3.1 Stable release
Gradle Plugin Version: 3.1.0
Gradle Distribution URL:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Steps I've followed/things I've tried:
Clean Project
Rebuild Project
Sync Project
Deleting build folder from project tree
Checked that project doesn't contain any names, references or declarations missing
Invalidate Caches/Restart
Check the whole dependency tree to make sure any Kotlin dependency is not imported or used as my project doesn't make use of Kotlin language
None of the above have worked!
I think instant run might be creating issue .
Do one thing disable instant run in android studio and try again .I think it might will resolve issue .
Try to update Android Studio. Turn off Instant Run from Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run.

Run button isn't compiling project in Android Studio 3.1 [duplicate]

When I try to install an app, there are two possibilities:
Install existing APK from build folder when I run the app
Install APK after performing clean build
For existing APK in the build folder, the app just works fine. But when I clean the project using Build -> Clean Project, and then try to run the app (i.e. install the app to my emulator or physical device), it shows me error:
The APK file /Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not exist on disk.
NOTE: This behaviour happens only when I clean the project and not when I have already have a pre-built app APK in my build folder
I've referred to: The APK file does not exist on disk but my point is, when we usually run the app after cleaning the project, we never need to make a build of it, if the APK is not existing in the build folder, it automatically generates and installs the latest one.
Things I've tried:
Running the app when APK file exists in the build folder (works perfectly fine)
Running the Clean Project -> Running the app (expected is the project would be built and the app would get installed but it shows the above mentioned error!)
Same process of cleaning and running the app after doing Invalidate Caches/Restart
I have solution for your issue.
Also confirmed by Android Studio on Twitter : https://twitter.com/androidstudio/status/981914632892960768
Edit your app configuration as below.
Here you can see your app configuration as below.
Here is missing Gradle-aware make attribute in before launch configuration. You can see here.
Please add this Gradle-aware Make attribute through this way. Click on + icon and select Gradle-aware Make as seen in this screen.
You can add this without writing any task just press OK button and task will be added and now it should look like this. Now apply changes and run your application.
It will solve this old apk installing issue on clean build in new Android Studio 3.1 issue.
Note : This issue is resolved in new Android Studio 3.1.1 Stable release.
The APK file
/Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not
exist on disk.
May be bug. You should change Settings.
You should open the Run/Debug Configurations dialog & select Run > Edit Configurations
Make sure, Gradle-aware Make is Added in TaskList or not. If not then click + & select from the options.
Note
If you receive
Shutdown finished in 0ms Error while generating dependencies split APK
com.android.ide.common.process.ProcessException: Failed to execute
aapt at
com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:809)
at
com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:797)
at
com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApkResourcesAp(InstantRunSplitApkBuilder.java:373)
You should Un-Check INSTANT RUN.
File-- Settings-- Build, Execution, Deployment -- Instant Run and
uncheck Enable Instant Run.
clean your project and run again
If it's not work then
Step 1 Close your project.
Step 2 Go to your project folder and delete all build folder.
Step 3 run your project.
This issue has been fixed with Android studio 3.1.1 (April 2018) release.
Update your android studio to 3.1.1.
Here is there explanation regrading the issue details, cause and solution:
In some cases, when a project created in Android Studio 3.0 was opened for the first time in Android Studio 3.1, the Gradle-aware Make task was removed from the Before launch area in Run/Debug Configurations. The result was that projects did not build when the Run or Debug button was clicked, which in turn caused failures such as deployment of incorrect APKs and crashes when using Instant Run.
To solve this problem, Android Studio 3.1.1 adds the Gradle-aware Make task to the run configuration for projects that are missing this entry. This modification occurs after the first Gradle sync when the project is loaded.
Official release notes: https://developer.android.com/studio/releases/index.html#3-1-0
For all people seing this and having the issue on Android Studio +4.0.0:
Run -> Edit configurations... -> disable check box (Allow parallel run)
It may slow your build a little but it better than running the app more than one time.

Android Studio 2.0 fails to build sample android project out of the box

I just download loaded the a brand new stable version of Android Studio.
It installs OK and ask what sort of project you'd like to open. I figured I'd open a sample project. I selected the first one,"ActionBarCompat-ShareActionProvider".
Android Studio fails and tells me to look in the log file. I see that this is the error
.project.GradleProjectResolver - Gradle project resolve error
org.gradle.tooling.BuildException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.8-all.zip
I am able to download https://services.gradle.org/distributions/gradle-2.8-all.zip with my browser. What gives?
Try updating your gradle distribution URL to point to version 2.10. There are a couple ways to do this.
a) In your gradle-wrapper.properties file, change the following line
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
b) Go to Android Studio > Preferences > Build, Execution, Deployment > Build Tools > Gradle and change your "Gradle home" directory to /Applications/Android Studio.app/Contents/gradle/gradle-2.10 or just select "Use default gradle wrapper".
when i click help> check for update> it will redirect
http://tools.android.com/download/studio/canary/latest/ << this web url. but my friends able to update without redirecting any web url. why?

Can't get Terminal Emulator for Android to build in Android Studio

I'm trying to build Terminal Emulator for Android. I'm running Android Studio 1.4 in Kubuntu 15.04. I also tried building it in Ubuntu 14.04 LTS with the same results. The project requires the latest Android NDK, SDK 22, and SDK 11 which I've downloaded and configured in Android Studio. My system gradle version is 2.8, and Android Studio has downloaded some other versions internally. I'm using jdk1.8.0_65, which is set to JAVA_HOME and configured in Android Studio. I've built several other projects with my configured Android Studio and only seem to have a problem with this project. I need to use this project as a base for an app I'm developing.
I end up with same error, posted below, no matter what route I take to fix it in Android Studio. This is generally what I've done to try and get the project to work. I open up the project unmodified in Android Studio. I click Build >> Rebuild Project. I get an error telling me ndk implementation is deprecated. I add a file gradle.properties to the root directory of the project with the line android.useDeprecatedNdk=true and rebuild. It gives me an error: Task 'generateDebugTestSources' not found in project. I execute Sync Project With Gradle Files to resolve it. Then I end up with the following error and can't get past it.
Gradle 'Android-Terminal-Emulator-master' project refresh failed
Error:exception during working with external system:
or
Gradle sync failed: exception during working with external system:
Consult IDE log for more details (Help | Show Log)
idea.log
Things I've done to try and get the project to build:
Modify all of the project's build.gradle files to use the experimental plugin
Use different versions of Android Studio
Switch from openjdk to Oracle's jdk
Upgrade gradle to the latest version
Set gradle to default wrapper (default) and also set gradle to different versions
invalidate cache, remove ~/.gradle, and rebuild project
Make sure PATH includes the gradle and jdk bin directories and is in ~/.bashrc, ~/.profile, and ~/.zshrc
remove proguard from libtermexec library
reboot computer
I should note that the project builds without issue on the command line. I'd really like to get the project to build in Android Studio for development.
Install Arch and run Android Studio there.
I decided to try building Terminal Emulator on my Arch server, so I installed a xfce (Desktop Environment) and Android-Studio through pacman. I followed the same general path to get things setup, and the app built without issue.
The idea log Android Studio generated for the failed build on Windows and Ubuntu didn't point to any clear problem, even with --stacktrace enabled with gradle. I'm not going to waste my time figuring out why gradle doesn't want to build apps in Ubuntu or Windows.

Categories

Resources