In Android Studio, why is the output of Gradle console always empty? - android

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.

Related

The AbstractArchiveTask.destinationDir property has been deprecated. Gradle in Flutter

I was creating APK for my flutter project so I followed the below steps to generate a signed APK
Tools -> Flutter -> Open for editing in android studio
Then opened the model in a new window
I got the Gradle sync failed error, After my further investigation I run the command gradlew --warning-mode all in the terminal & I got the below message from gradle
The AbstractArchiveTask.destinationDir property has been deprecated. This is scheduled to be removed in Gradle 7.0. Please use the destinationDirectory property instead.
Since I am new to flutter & always scared of Gradle failing, I am not sure how to fix this issue & set the destination directory
Or if you know how to create APK from the flutter project do let me know if I am doing anything wrong to generate APK
Gradle sync failed error is not any error in flutter.
to build apk in flutter first of all you run flutter clean command
then run flutter pub get command
after then you run flutter build apk command to build apk
also if you use Android Studio then you can build apk without command using
in Android Studio in top menu Build => Flutter => Build APK and click on Build APK
it will make apk for you

How can I see what gradle task Android Studio is using to install an apk?

When I run a configuration, I can the gradle commands android studio is running to build the apk in the build tab (assembleDebug). But it is not showing me what command is run after that to actually install the apk on a device. Is there a way I can see this?

Generate signed apk fails with build\app\intermediates\flutter\profile\libs.jar (The system cannot find the path specified)

I am on android studio 4. Gradle is 6.1.1. And I created a new flutter project from android studio. Then I opened the project as an android project. There is such an option in Tools->Flutter. Which resulted in gradle sync. That was successful. But when I try to generate signed apk with my keys. I get this. error
\path\to\my\project\build\app\intermediates\flutter\profile\libs.jar (The system cannot find the path specified)
There is no profile directory at the given location. But there are Debug and Release directories both of which contains libs.jar. I searched all other the net for this issue. Found Nothing.
Additional: I can build debug apk with no issues.
I found a fix for this issue as I was searching through various issues people had reported on github regarding this.
This is just a workaround.
You can get two kinds of error. For me the system could not find profile/libs.jar, for some people the error was for debug/libs.jar. If the issue is profile, you should first run your app in profile mode and then Generate signed apk (or build and run in release mode). To run in profile mode use flutter run --profile. There is also a profile option under Run menu in Android Studio.
If the error is about debug/libs.jar, first build the debug version (and also the profile mode) and then try to Generate signed apk. By default, flutter run compiles to debug mode.
This issue evidently arises from the updated Gradle and android studio gradle plugin.
Here is the workaround by Jwiggiff on the github page.
This problem is with latest gradle 4.0.0
Switch from classpath 'com.android.tools.build:gradle:4.0.0'
to classpath 'com.android.tools.build:gradle:3.6.3'
or classpath 'com.android.tools.build:gradle:3.5.0' (Worked for me)
If you don't care about lintOptions you can add this code in app's build.gradle file:
android {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
This should also work fine
flutter build apk --profile
this will work.
flutter build apk --debug &&
flutter build apk --profile &&
flutter build apk --release
but test the apk before sharing it.
even it doesn't work the change the gradle from 4.x to 3.6.x this will work.
This is a trick
Run terminal for current flutter project, then type
flutter run
to get this success result :
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 22.7s
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
then, type
flutter build apk
to get
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 41.8s
✓ Built build/app/outputs/flutter-apk/app-release.apk (23.6MB).
then, install this Release APK to device.
flutter install build/app/outputs/flutter-apk/app-release.apk
Now, you got Release App on your device.
p/s : This case skip error
Execution failed for task ':app:lintVitalRelease'.
Failed to transform libs.jar to match attributes
Execution failed for JetifyTransform
Transform's input file does not exist
you already got.
In my case, I forgot that I'm using flavors. Maybe this caused the issue.
Now I let flutter build the app with the following command:
flutter build apk --flavor <flavorname> -t <path/to/main.dart>
Permanent fix
To fix this issue permanently, type in terminal
flutter doctor
This will give you summary like this
You need to fix all those red marks!!
Fixing android licenses
type flutter doctor --android-licenses
if you encounter this error
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
Try to install Android SDK command-line tools from Android Studio (Tools > SDK Manager)
Unfold Appearance & Behavior
Unfold System Settings
Click Android SDK
Click tab of SDK Tools
Check Android SDK Command-line Tools (latest)
Click Apply button
Then run once again
flutter doctor --android-licenses
Fixing Flutter plugin not installed
Check your Android Studio Version (For Mac go to ~/Library/Application Support/Google/AndroidStudio{Version}. In my case, the {Version} is 2020.3)
Then type
ln -s ~/Library/Application\ Support/Google/AndroidStudio2020.3/plugins ~/Library/Application\ Support/AndroidStudio2020.3
This command just redirects flutter doctor to the different folder to find plugins (where they are now). This is called symbolic link
Fixing unable to find bundled Java version
This solution is for Mac User
Find your local Java version by typing /usr/libexec/java_home -V
Set Java_Home path by typing /usr/libexec/java_home /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
Type all of these in terminal
cd /Applications/Android\ Studio.app/Contents/jre
ln -s ../jre jdk
ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk
Finally run flutter doctor -v to see all the details changes
Happy Ending
After fixing all those issues, run
flutter clean
flutter run
to build release apk
flutter build apk --split-per-abi

How to run 'rebuild project' from the command line

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.

Jenkins job using Gradle can't find executable

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

Categories

Resources