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.
Related
I want to try to run this airbnb clone app in my android studio
but the problem is it's not working in my android studio
https://github.com/mdy0501/Airbnb
It just show in my console
!-- console --!
7:01:05: Executing task...
> Task :help
Welcome to Gradle 5.1.1.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
To see more detail about a task, run gradle help --task <task>
For troubleshooting, visit https://help.gradle.org
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
7:01:05: Task execution finished.
I want to know how to run that app in my android AVD
Is that possbile..? running in my android studio that app ?
i can't find how to run...
Make sure the repository you have cloned is Android project
Before Run the demo you should sync your project
You will see a lot output in the Build window at the Android Studio bottom.
Project sync successfully the Run button will look like this.
If sync operation failed it means project did not configure correctly just try to fix the error according to the sync output.
Lately I came to know the power of Gradle as a build system and as an Android developer I wanna understand it deeply.
One article said the following:
You can execute all the build tasks available to your Android project using the Gradle wrapper command line tool. It's available as a batch file for Windows (gradlew.bat) and a shell script for Linux and Mac (gradlew.sh), and it's accessible from the root of each project you create with Android Studio.
To run a task with the wrapper, use one of the following commands:
On Windows:
gradlew task-name
Now I have some doubts which goes as follow:
What is Gradle Wrapper and gradlew.bat?
If I've got Android studio installed and it is using gradle to build my apps (so gradle is already installed on my system), do I still need to install gradle for build purpose from command line? As when i write any commend like gradle, gradlew on my command line I get error saying gradlew is not recognized as internal or external command (the same error for other commands). I may be using it on wrong path, help me on what path do I need to use Gradle related command?
If I need to download and install it, how and where can I find the file? And the other processes?
I am using a Windows machine for this.
The Gradle Wrapper is an optional part of the Gradle build system. It consists of four files that you check into version control system. The Unix start script <your root project>/gradlew, the <your root project>/gradlew.bat Windows start script, <your root project>/gradle/wrapper/gradle-wrapper.jar which contains the class files for the wrapper and is started by the start scripts and <your root project>/gradle/wrapper/gradle-wrapper.properties which contains some configuration for the wrapper, for example which Gradle version to use to build the project.
In my opinion, each and every Gradle project, even the tiniest, should make use of the Gradle wrapper.
The Gradle wrapper makes sure your build is always run with the same Gradle version, no matter who executes the build and where or that Gradle is installed or not, as long as the one uses the Gradle wrapper to build the project. This means you can design your build for that Gradle version and be sure that the build will not fail, just because someone is using a different version of Gradle and thus is also an important step in build reproducibility.
Also, someone wishing to build your project only needs to have Java installed and that's it. He does not need to have any Gradle version installed. Actually any already installed Gradle version is ignored. The Gradle wrapper checks whether in ~/.gradle/ the version that is necessary for the build is already present, because some Gradle wrapper of any project put it there already. If it is present already, it is used, otherwise it is automatically downloaded.
If you type gradlew on the commandline and the command is not found, that means you didn't put your root projects path to the PATH environment variable (I wouldn't recommend doing that either), nor are you currently in your root project's directory. To run a Gradle build, you have to be anywhere inside your project and call Gradle or the Gradle wrapper. But like with any executable file that is not on the path, you have to provide its path of course. So if you are in your root project directory, you can simply do gradlew. if you are in <root project dir>/foo/bar/, you would need to call ../../gradlew.
The Gradle Wrapper files are generated by the implicitly available Gradle task wrapper and then get checked into the VCS of the project in question. If those four files are not present for a project, it does not use the Gradle wrapper and you should post an improvement request to the project to add it.
If some project does not use the Gradle wrapper, but builds with Gradle, you can either install Gradle and use gradle instead of gradlew, or you can even call the Gradle wrapper of any other project that you have available on disk. The build will then be run with the Gradle version that wrapper or Gradle installation is using and thus might not behave as expected, which is why really each and every project should use the wrapper if it uses Gradle.
Edited after comments
Gradle is a build system.
This gradle-wrapper is kind of the primary interface to to build Android projects. It the part of Gradle-build-system and does some primary check if gradle in installed or not.
gradlew.bat - its a batch file used on Windows. You can even open it with a notepad to view the instructions in it. Batch files are like 'commands' written in a file to be executed. You use it (in case of Windows) to execute build commands. It also checks if gradle is installed or not. And in case it is not, it downloads and installs it.
Example : to build android app on Windows:
Open command prompt
Navigate to your project's root directory
execute gradlew.bat assembleDebug
It starts the wrapper, checks if Gradle is installed there and
executes all the 'gradle specific' commands to build your project.
Do you need to install Gradle ?
Actually, no. Its the job of this gradlew script to check for that. If gradle its not already there, it would automatically download it and use it for all later builds.
gradlew.bat IS the Gradle Wrapper (for Windows in this case). Gradle Wrapper is just a small utility that will ensure that Gradle is installed (or install it if necessary) so you can always build the project. Gradle itself allows you to manage dependencies and build configurations for your project.
If you have installed Android Studio, you have Gradle installed and are good to go. (Technically, each project will have it's own wrapper to handle installing/using Gradle)
As I mentioned above, you are good to go.
In the end Gradle is a command line tool that you use to build your project and you could very well use that directly (though you don't have to) since it is exactly what Android Studio uses to build your project.
In Android Studio 2.2.3, the output of Gradle console is always empty no matter what task I triggered. Is it deprecated?
Build Your App from the Command Line In this document About build
types Build a debug APK Build a release APK Run your app on the
emulator Run your app on a device You can execute all the build tasks
available to your Android project using the Gradle wrapper command
line tool. It's available as a batch file for Windows (gradlew.bat)
and a shell script for Linux and Mac (gradlew.sh), and it's accessible
from the root of each project you create with Android Studio.
To run a task with the wrapper, use one of the following commands:
On Windows: gradlew task-name
On Mac or Linux: ./gradlew task-name To
see a list of all available build tasks for your project, execute
tasks:
gradlew tasks
Read More at https://developer.android.com/studio/build/building-cmdline.html
And
https://developer.android.com/studio/run/index.html
I found out that Gradle console is used for build action like "Make Project" in menu bar:
If you run the task from Gradle panel, the output will not be shown on Gradle console.
I noticed that the Gradle uses a separate daemon than the terminal does, and it uses the gradlew (wrapper) to run its own instance of Gradle daemon.
I noticed this when i tried to stop Gradle task in Android Studio by the command gradle --stop. it says there is no daemon running. but when I use ./gradlew --stop it stops the Gradle task. It's like I'm having two daemons running one for Android Studio and one for the terminal.
How can I make the Android Studio to use the same daemon that the terminal is using (when I start a Gradle task by gradle build command, the terminal starts a daemon and uses it).
How can I do this?
I found the answer myself by testing many ways.
the point is when u use Gradle wrapper it will start a new daemon for every project even if they are with the same version you can stop using Gradle wrapper by one change in Android Studio so it uses system Gradle daemon (not using wrapper and running a new daemon for each project)
you need to go to "Settings ->Build, Execution, Deployment -> Build tools -> Gradle" then check the radio button "Use local Gradle distribution" and address the "Gradle Home" field to the system Gradle_Home installation.
though you need to have already Gradle installed on your system.
for me its directory is: "/home/[my_user]/.gradle/wrapper/dists/gradle-3.1-all/ejgglywf033yp6s4x8ahmgm74/gradle-3.1"
the good point about this is you will have just one instance of Gradle Daemon (starting daemons takes time - especially if you are working on multiple project at the same time like me), and the negative point is you will have to change the directory manually when you want to migrate to new Gradle version distributes.
I dont know why but with this method the Gradle syncs faster on my pc. let me know if its also faster in your computer.
It was a lot of work but I was able to find a better solution than using the local gradle distribution
Please have a look at my bug report where everything is explained and hopefully this will be solved by Google or Gradle in a future release
https://issuetracker.google.com/issues/68374709
I am trying to set up a Jenkins job to build the next big Android app! I've got the Android SDK installed and that part seems to be working fine. I've got Gradle Plugin v1.24 installed on Jenkins and now I think I'm trying to figure out how to get Gradle actually working.
First attempt was to have Jenkins download a specific version automatically from gradle.org. I'm trying to pull v2.2.1 because that seems to be the version my Android app builds with locally. When I do that I get this error in my Jenkins job:
[Gradle] - Launching build.
Invalid tool ID 2.2.1
[Gradle] - [ERROR] Can't retrieve the Gradle executable.
Build step 'Invoke Gradle script' marked build as failure
I tried many different versions but could not get that working. So, next was to tell Jenkins where to download Gradle from. I gave it this location:
https://services.gradle.org/distributions/gradle-2.2.1-bin.zip
I get a different error when building but still not too sure what to do.
[Gradle] - Launching build.
[Journeyman-Android] $ gradle clean build
FATAL: command execution failed
java.io.IOException: Cannot run program "gradle" (in directory "/var/lib/jenkins/workspace/Journeyman-Android"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:816)
at hudson.Launcher$ProcStarter.start(Launcher.java:382)
at hudson.Launcher$ProcStarter.join(Launcher.java:389)
at hudson.plugins.gradle.Gradle.performTask(Gradle.java:262)
at hudson.plugins.gradle.Gradle.perform(Gradle.java:116)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1744)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:374)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:186)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 16 more
Build step 'Invoke Gradle script' changed build result to FAILURE
I tried to see what I can do with the Jenkins CLI but that fails for me too. We use Jenkins to build/deploy several other projects successfully so this is a working Jenkins installation.
Does anyone have any pointers or suggestions for what I may need to do?
Update (still failing)
I am able to build my app manually but navigating to the root of my project in the jenkins workspace and executing
./gradlew assemble
Finally figured it out. I needed to update my jenkins job to use the Gradle wrapper instead of a specific Gradle version. Once I did that I had a few more errors to sift through but they were all very informative and gave me the information I needed to resolve them.
I downloaded the Gradle.
Extracted to some place.
In Jenins > Manage Jenkins > Gradle
Unchecked the install automatic.
Set the path to gradle home, (Ex: C:\Graddle\gradle-2.1).
Probelm resolved.
For Jenkins running on linux:
download gradle zip file
cd /opt/
wget https://services.gradle.org/distributions/gradle-2.10-all.zip
unzip
unzip gradle-2.10-all.zip
visit jenkins website
Jenkins > Manage Jenkins > Configure System > Gradle > Gradle installations
uncheck Install automatically, set 2.10 to name, set /opt/gradle-2.10 to GRADLE_HOME.
click your job
Configure > Build > Invoke Gradle script
select Invoke Gradle, select 2.10 in Gradle Version dropdown list.
If one previously configured the build with Invoke Gradle script option and selected a specific Gradle Version (say 2.4 for example), he initiated the build but later switched to Use Gradle Wrapper option without resetting the Gradle Version value back to Default. Jenkins would issue the
[Gradle] - [ERROR] Can't retrieve the Gradle executable.
It is a jenkins' bug as documented by this post.
The workaround is to reset Gradle Version to Default before swithcing to Use Gradle Wrapper.
This will help you remove invalid tool issue:
Manage Jenkins -> Manage Plugins -> Advanced: Click "Check Now" button at the bottom/right of the page.
On an old version of Jenkins (v1.609), I had to delete the "Gradle build script" step, and recreate it :-O