Gradle build never stops in Android Studio - android

I have an Android Studio project. When i compile it using Build -> make project menu the build take around 30 seconds. But when I launch my project using the "run app" or the "debug app" button the gradle build never stops. The process is stucked on "Gradle build running".

This had nothing to do with Gradle. It was because of some files I had in the assets folder, I removed these files and it works now. Gradle was looping trying to build again and again.
These files were created when I opened a Realm database I had in the assets folder using Realm Studio :
default.realm.lock
default.realm.note
default.realm.management
I guess it's kind of metadata files used by Realm Studio. They are always created in the same directory of the opened database.

Related

Android Studio 3.1.2 can't delete file opened by itself

I just installed brandnew Android Studio and haven't to mess with the configuation. It happened when I try to clean Kotlin project, I didn't even touch the code or the config manually.
Kotlin is configed by running Configure Kotlin in project and I press clean project. It fail to delete a file and it has to be deleted manually after closing Android Studio.
Later it failed to create debug directory 'C:\Users\myname\AndroidStudioProjects\thesimpleplainbasic\app\build\intermediates\res\debug'

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 3.1 is not compiling/building the app, runs instantly [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.

Importing src folder into Android Studio

My Android Studio project was doing some funny business with the preview mode. I was getting lots of errors in regards to rendering the views. In just one Activity I would get about 50 errors. Long Story Short: I spent all day searching for a solution to no avail, but noticed that these errors only happen to that particular project. I thought - you know what, I'm just going to delete all the Android generated stuff and re-import my src files into a new project.
So I deleted them, but now I don't know how to import the src folder back into Android Studio! When I tried to import, Android does not create a gradle build for me. This is what I've tried:
Closed AS
Open AS
Click Import project (Eclipse ADT, Gradle, etc.)
Import project from external model -> Gradle -> Next
Use Local Gradle Build -> C:/Program Files/Android/Android Studio/gradle/gradle-2.10
Finish
I get a notice "Frameworks detected: Android framework is detected in the project. Click Configure -> select AndroidManifest.xml -> OK
In Project Explorer -> Android window - no files are present.
In Project Explorer -> Project window - files are present but has a red marking on them, I have no idea what they mean.
Example:
The run, build, debug buttons etc are all greyed out. This tells me that the Gradle build wasn't successful.
Anyway, after I restarted AS, I now get this event log:
Migrate Project to Gradle? This project does not use the Gradle build system. We recommend that you migrate to using the Gradle build system.
Why do I need to migrate? I told Android Studio to build gradle by pointing to the local gradle build?
What is the correct way to create a Android Studio project if you have source codes but not as an existing project in eclipse or android studio?
Maybe you should create a new project, then paste source files.

Android studio 2.0 unable to load project correctly - wearable.iml is not well formed

Everytime i try and load my project using android studio 2.0 Beta 6 i get the following error:
After that i sync gradle and im able to work with the project. I tried going to file-->Invalidate Caches /Restart and i invalidated the cache which clears history. Obviously the error is saying a xml file is not correctly formed but how can i correct this ?
The other thing i notice is that everytime i load the project it starts the wearable app has the default project like this:
My project structure is simple. Here is the settings.gradle file:
include ':app', ':wearable',':SliderPreference'
project(':SliderPreference').projectDir = new File('libs/AndroidSliderPreference')
After i do a gradle sync the project seems fine but when i load the app module as a signed release, the wearable app never loads automatically anymore so i know something wrong. I can load the wearable by itself through a install but a signed app module should automatically install a wearable project but now its no longer working.
When I got a problem with the .iml files, I do this:
I open Android Studio to run the project
I delete the .iml which got a problem.
I Rebuild the project Build > Rebuild Project.
After that I have no problem.

Categories

Resources