Here is my Gradle setting:
On my developing app, I usually click the button below and everything goes well.
I want to write a script to auto run my build every day.
I tried gradlew assembleRelease and /Applications/Android\ Studio.app/Contents/gradle/gradle-2.4/bin/gradle assembleRelease but it start downloading all dependencies, I have bad network so I can't run the build.
Obviously I have downloaded all the dependencies before because I could click that "run" button and launch my app. It seems Android Studio keep a gradle cache itself and provider another gradlew program.
How could I build my app from the command line with my bad network. Thanks!
Related
I had a project on Android Studio which was working. But after I ran
git pull and then git reset --hard and tried to run it again, build failed with the message:
File 'com.android.builder.files.ZipCentralDirectory#412e039a' was deleted, but previous version not found in cache
Build -> Clean Project fixed my problem.
Go to Task Manager
Search for any instances of OpenJDK or java in task manager click and End Task
Run flutter clean in IDE
The Reason was Flutter Clean cant delete the build while the Application is still running in the Background process, u have to close it and run.
I also faced the same issue. it occurs when you run> flutter clean command that actually did't clean all the files inside build directory of your project, and causes the issue.
So the simple solution is, delete your build directory manually. If it alerts "File in Use" dialogue then simple do the following steps
open the run command with shortcut Window+R
type resmon.exe it will open the resource monitor
click on "CPU" tab
click on "Associated handles" and type build in search bar
right click on java.exe and end process
restart your IDEA and run your project the problem is solved
An alternative way to fix this issue is to run flutter clean.
You mentioned you are using android studio, go to your terminal inside android studio and then run the above mentioned command.
After the above command was executed then run your app again.
This simple solution worked for me !
Using Android Studio 3.6.2 for a Flutter project there is no 'Build -> Clean' unless you 'Open Android module in Android studio'. Then there is a 'Build -> Clean Project'.
An alternative as mentioned above is to open the terminal in the project where you may Debug your application and run 'flutter clean'.
For me the latter is better since I typically only open the Flutter android module when I want to build a release of my app.
Open Android module in Android studio
run success
execute ‘Build -> Clean’
close Android module in Android studio
run flutter project again
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.
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.
As described here in the Android Studio docs, one can build an Android app from the command line with the gradle wrapper generated by Android Studio. The command line window in Android Studio shows exactly this, i.e. a call to gradlew assembleDebug (or a similar task). However starting a terminal on macOS and calling the gradle wrapper with that exact call sometimes yields other results, i.e. either one is able to build from Android Studio, or the command line, or both (which is ideal, but unfortunately not always true).
Who can explain what other settings the Android Studio IDE sets for their environment and where to find them, how to reproduce these settings easily in a CI environment (e.g. Jenkins, Bamboo, ...) and how one would consistently store these settings in a VCS along an Android project.
In the root of the project you have gradlew.bat, which is how you can run it in the first place. If you open this file, you see the code for building and everything else Gradle does.
Whether you build from the command line or ANdroid Studio, the gradlew.bat file is used. So building and other stuff you do with the gradlew command all use the same file whether it is from the command line or Android Studio's integrated tools.
You can open the file(s, there's gradlew and gradlew.bat in the project root) and see how it works if you wanted too, though these files are usually automatically generated by Android Studio (it is possible to make your own config as well, though there's rarely a need for that). And for including in vcs, make sure the files aren't listed in .gitnore (or whatever vcs ignore extension you have)
Some Context:
I am working on a Continuous Integration pipeline with MSBuild for a large project that includes an Android application. This application includes some automatically generated files that need to be integrated into the project regularly. This is usually accomplished by manually copying them over and selecting Build->rebuild project in android studio.
This step is necessary since the project also makes use of AndroidAnnotations, which generates classes at compile time.
The Problem:
I haven't found any documentation for what is run when you select 'rebuild project' in android studio.
What I Have Tried:
How to Rebuild and Run android project from command line
as well as:
What is happened after I run rebuild project in Android studio?
But the doccumentation here doesn't talk about the rebuild command, and a 6 week udacity course isn't a helpful resource either.
When I hit 'rebuild project' the Android Studio event log reads:
Executing tasks: [clean, :app:generateDevelopmentDebugSources, :app:generateDevelopmentDebugAndroidTestSources, :app:prepareDevelopmentDebugUnitTestDependencies, :app:mockableAndroidJar, :app:compileDevelopmentDebugSources, :app:compileDevelopmentDebugAndroidTestSources, :app:compileDevelopmentDebugUnitTestSources]
Which I have run in the command line as follows:
gradlew.bat clean :app:generateDevelopmentDebugSources :app:generateDevelopmentDebugAndroidTestSources :app:prepareDevelopmentDebugUnitTestDependencies :app:mockableAndroidJar :app:compileDevelopmentDebugSources :app:compileDevelopmentDebugAndroidTestSources :app:compileDevelopmentDebugUnitTestSources
The command executes, but the build finishes with several hundred errors, which also occur when you try to compile or clean without first running rebuild. Obviously this command is incomplete.
When I look at the Gradle Console in Android Studio I see a couple of dozen targets that are run, but I'm hesitant to copy-paste those, as I have no idea what small changes to the project will necessitate different targets to be run.
I've narrowed down my issue to the :app:compileDevelopmentDebugUnitTestJavaWithJavac target. This target requires one of the other targets listed in the Gradle Console, but I don't know which one.
Those targets have to be coming from somewhere, but where?
tl;dr:
How can I do all the things that Android Studio does when I run 'rebuild project' from the command line?
Please open build view in Android Studio, when you select from menu: Build -> Rebuild Project on the top in build view you will see which tasks were triggered by Android Studio: Executing tasks: [clean, :assembleDebug] in project ...
And now you can try to do this from command line:
./gradlew clean assembleRelease
Rebuild and build are the same thing. You can list all the gradle tasks by running a command gradle task --list or gradle -q :tasks --all . There you can see different types of gradle tasks. For example, install tasks, build tasks, assemble tasks, publishing tasks, verification tasks, build setup tasks, clean tasks, android task, or your own custom named tasks etc. Run on the build tasks from your module (e.g., MyModule:build) like this gradle MyModule:build (or ./gradlew MyModule:build if you wanna use inside gradle wrapper)
Note: you can see your runnable/buildable module from Run Configurations also.