How to use gradle installed with android studio out of android studio - android

Please how can I use the Gradle shipped with android studio out of android studio? I tried running gradle -v on my ubuntu command line but it says the command is not recognized.

For running gradle:
Download gradle
Unzip the zip file
add GRADLE_HOME/bin to your PATH environment variable
Somenthing like:
wget https://services.gradle.org/distributions/gradle-2.5-bin.zip
unzip gradle-2.5-bin.zip
export GRADLE_HOME="$HOME/yourGradleFolder"
PATH="$PATH:$GRADLE_HOME/bin"
More info here.
AndroidStudio donwloads the gradle distributions in this folder:
/home/xxxx/.gradle/wrapper/dists
If you would like to use the gradle wrapper inside the projects, it is enough to run
./gradlew xxxxxx

May you can install grade from
Gradel download link
Building and Running from the Command Line
then Follow this link Building and Running from the Command Line
please let me know if any issue.Thanks for asking.

Related

Could not compile settings gradle React Native

The app worked for me from another machine, now that downloading the files from the repository on another computer gives me this problem
FAILURE: Build failed with an exception.
Where:
Settings file 'C:\Users\samue\Desktop\MCGPS\TeachAll\android\settings.gradle'
What went wrong:
Could not compile settings file 'C:\Users\samue\Desktop\MCGPS\TeachAll\android\settings.gradle'.
startup failed:
General error during semantic analysis: Unsupported class file major version 57
This is an issue with how Gradle is automating the build and the current version of the JDK installed on your machine, follow these steps to fix it, the react native documentation states you need adoptopenjdk8, however you may have other conflicting JDK versions in the same directory.
Blog post: https://ashirazee.medium.com/react-native-android-failure-build-failed-with-an-exception-908934c3a32b
Step one:
open up your terminal and navigate to /Library/Java/JavaVirtualMachines by typing the following command:
cd /Library/Java/JavaVirtualMachines
after you have done that type ls to see what files are included and take note of the versions.
incase you have one or multiple JDK files present like such:
adoptopenjdk-8.jdk jdk-16.jdk jdk-8.jdk
then go head and delete them with the following command line :
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-16.jdk
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-8.jdk
the only dependency you need is adoptopenjdk-8.jdk as mentioned in the react native docs
however delete that aswell and reinstall it after you have completed these steps:
sudo rm -rf /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk
after you have done so you can check if the files still exist by typing ls
if the files are deleted.
Step 2:
then run the following commands to insure all other links, plugins and files are deleted as-well from your Library:
run the following :
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf ~/Library/Application\ Support/Oracle/Java
Step 3:
once you have done the following, reinstall the correct jdk as mentioned in the react native docs like so:
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
https://reactnative.dev/docs/_getting-started-macos-android
this may say adoptopenjdk-8.jdk is already installed, but go ahead and reinstall install it with:
brew reinstall adoptopenjdk8
At this point the error should be resolved and your build should work.
It is important to note that this is a build error, since react native uses Gradle to build automations, the conflicting of multiple jdk versions can cause your build to fail.
please refer to the following documentation:
https://docs.gradle.org/current/userguide/userguide.html
This is due to the jdk version intalled on your system.
If you're using the latest version of Java Development Kit, you'll need to change the Gradle version of your project so it can recognize the JDK. You can do that by going to {project root folder}\android\gradle\wrapper\gradle-wrapper.properties and changing the distributionUrl value to upgrade the Gradle version. You can check out latest releases of gradle and note the latest version of gradle and edit in gradle-wrapper.properties and change the distributionUrl
I have solved issue by just opening project in Android studio
react native version 0.60.5
Open the android folder using Android Studio. Then all dependencies will start downloading(as shown in the picture). Let them complete. After completely downloaded and loaded you can run the project.
this issue seems to be with the java version, pls check for correct version. also even if two or more jdk are installed we can specify during runtime which jdk has to be used by specifying this gradlew.bat build -Dorg.gradle.java.home=---path-to-jdk---
Solved it by downgrading Java and upgrading Gradle version.
I had the same problem, I came here looking for a solution. I selected JDK 11 instead of 16, but it didn't work, I remembered that I didn't point the way for the new JDK version in ~/.bashrc, now it finally worked.

“Could not find an installed version of Gradle” in ionic 3 [duplicate]

I create ionic 2 project and add diagnostic cordova plugin like this :
ionic plugin add cordova.plugins.diagnostic
npm install --save #ionic-native/diagnostic
and add android platform like this :
ionic platform add android#latest
but when build with ionic build android console give me this error :
Error: Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
and I try to download manualy gradle.3.3-all.zip and change this distributionUrl var in platform/android/cordova/lib/builders/GradleBuilder.js
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-3.3-all.zip'
to:
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'file:///E:/gradles/gradle-3.3-all.zip';
but not working and console give me last error.
I dont know how to add gradle for android#latest version
Life is too short to spend it on messing with paths, etc.
Since I had Homebrew installed on the iMac, I just ran this command:
brew install gradle
The Ionic3 project started to build successfully.
Try installing gradle and include it into your path. Click the link below to get manual.
https://gradle.org/install
Just install gradle on linux, Even if Android Studio is installed,
sudo apt install gradle
For windows users:
Download gradle binary from the link in the answer Gradle Download
Extract the zip file to 'C:\Gradle' or somewhere else
open Edit Environment variable dialog from start menu > Search
Click 'New' under system variables and add as below
Variable Name GRADLE_HOME Variable Value C:\Gradle\gradle-4.0.1
Then choose PATH variable from system variable list
append the gradle path to variable value like this C:\Gradle\gradle-4.0.1\bin
then press win Key+R type cmd then enter > in command terminal type gradle -v
if the setup is correct you will see the gradle installation details
I was already installed Android Studio and it's just need to add gradle PATH to ~/.bash_profile on my MacOSX Mojave.
Also if gradle is upgraded then path might need to update again.
Example .bash_profile :
export ANDROID_SDK_ROOT="~/Library/Android/sdk"
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export JAVA_HOME=$(/usr/libexec/java_home)
export GRADLE_PATH="~/.gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/gradle-4.10.1/bin"
export ANDROID_STUDIO="/Applications/Android Studio.app/Contents/MacOS"
export PATH="$PATH:$GRADLE_PATH:$ANDROID_STUDIO"
When edited your .bash_profile then run a command below to read it again.
source ~/.bash_profile
For Windows you can try below solution
Copy your gradle-->bin path and add it to system environment variable path.
In my case gradle path is
C:\Users\username\.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9\gradle-3.3\bin
This solution worked for me.
In Ubuntu, Installing latest version of gradle solved the issue for me.
Try these steps to install the latest version,
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle
then build using,
cordova build android or ionic cordova build android
Note: If you install gradle from ubuntu repo, it will install the old version 1.4 and will not help, so sudo apt-get install gradle alone will not help most times, if you did not add the repo ppa:cwchien/gradle earlier
There is a problem with cordova version 6.4.0 and android 6.2.1 .so,please try with below compatible versions
cordova version must be 6.4.0
sudo npm install -g cordova#6.4.0
Install android in your project
sudo cordova platform add android#6.1.2
or
sudo ionic platform add android#6.1.2
brew install gradle
In short that will save time :) Ionic team please fix this
On Ubuntu 18.04, I intalled gradle with:
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle
And Ready.
If you dont want to install gradle explicitly just to address this issue, you can overcome this by following the workaround as mentioned below:
Look for check_reqs.js file under platforms\android\cordova\lib folder
Edit the else part of androidStudioPath variable null check in get_gradle_wrapper function as below:
Existing code:
else {
//OK, let's try to check for Gradle!
return forgivingWhichSync('gradle');
}
Modified code:
else {
//OK, let's try to check for Gradle!
var sdkDir = process.env['ANDROID_HOME'];
return path.join(sdkDir, 'tools', 'templates', 'gradle', 'wrapper', 'gradlew');
}
NOTE: This change needs to be done everytime when the android platform is removed and re-added
UPDATE: The above workaround will work fine till Cordova Android version 6.3.0. For Cordova Android 6.4.0 and above, Gradle needs to be installed as a standalone dependency. Please find Cordova Android 6.4.0 release notes for more info on this.
For Windows users:
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
scoop install gradle
Just install the Gradle through the command line
If you are using Mac try
brew install gradle
I am on Microsoft Windows:
I encountered this error after upgrading Android Studio from 2.3.3 to 3.0. I solved it by changing the path to gradle in the PATH environment variable, which is now "gradle-4.1" for Android Studio 3.0 (previously it was "gradle-3.2" for Android Studio 2.3.3)
I moved Android folder path to another path and taked this error.
I resolved to this problem in below.
I was changed to Gradle path in system variables. But not path in user variables. You must change to path in system variables
Screenshot this
Alternative Screenshot this
I would like to add my two cents to this conversation. If you are a Windows user, you would like to take advantage of Chocolatey
Per https://community.chocolatey.org/packages/gradle, you need to run
in your console (it assumes you already have Chocolatey installed).
choco install gradle
If you haven't installed Chocolatey, follow the instructions at https://chocolatey.org/install
I solve this problem
Download gradle.zip from this site https://gradle.org/install. And follow the instructions indicated in the site.
Then open another terminal cmd and execute the command:
Cordova build android --prod --release
End
First of all uninstall ionic and cordova, later set your variables envarionment JAVA_HOME, ANDROID_HOME and PATH then reinstall ionic cordova and add platform like follow:
$ sudo npm install -g ionic cordova
$ ionic platform add android
The ionic will setup gradle packages properly.
In Arch Linux/Manjaro:
sudo pacman -S gradle
just install android studio and select your sdk folder as a android studio's sdk default folder and then android studio repair all the damage area and download needed files.
Download the latest gradle from https://gradle.org/install and set the gradle path upto bin in your PATH variable and export path in the directory you are working in
example : export PATH=/home/abc/android-sdk-linux/tools:/home/abc/android-sdk-linux/platform-tools:/home/abc/android-sdk-linux/tools:/home/abc/android-sdk-linux/platform-tools:/home/abc/Downloads/gradle-4.4.1/bin
I spent my whole day resolve this and ultimately this solution worked for me,
If your gradle was working normally before and this came up (probably after you upgraded or reinstalled ionic or cordova - as was my case), you might want to leave the environment variable as is, and check if the folder listed there actually exists.
If it doesn't, rather than reinstalling gradle as mentioned above and changing the value of the environment variable, I had to recreate the old missing folder and copy the gradle files into them.
It seems the value of the gradle location is saved somewhere in Android Studio, and updating the PATH in system variables doesn't affect Android Studio checking for that same location after something triggers a change.

Can't find cordova.jar file in phonegap?

I am new to phonegap the tutorials I have referred to says that there should be a cordova.jar file inside the phonegap-2.9.1\lib\android path. But I don't have it in this phonegap 2.9.1 version.
Can I download the cordova.jar from anywhere or is there any alternative?
Someone please help me.
Thanks.
First, you need the following requisites, for sure are covered if you have been playing with phonegap/cordova for a while ;)
Java JDK 1.5 or greater
Apache ANT 1.8.0 or greater
Android SDK http://developer.android.com
And then, to generate the cordova-2.9.1.jar file, follow the next steps:
Download and extract the phonegap-2.9.1.zip file.
In a terminal/cmd window go inside the recently extracted directory:
$ cd phonegap-2.9.1\lib\android\framework\
Execute the following commands (you need android sdk and ant already configured in your system path):
$ android update project -p . -t android-17
If required add the --subprojects parameter:
$ android update project -p . -t android-17 --subprojects
You get a message like this:
Updated project.properties
Updated local.properties
build.xml: Found version-tag: custom. File will not be updated.
Updated file D:\work_NEW\phonegap-2.9.1\lib\android\framework\proguard-project.txt
Updated and renamed default.properties to project.properties
Updated local.properties
No project name specified, using Activity name 'DroidGap'.
If you wish to change it, edit the first line of build.xml.
Added file D:\work_NEW\phonegap-2.9.1\lib\android\framework\bin\build.xml
Added file D:\work_NEW\phonegap-2.9.1\lib\android\framework\bin\proguard-project.txt
Finally run:
$ ant jar
Blablabla....
jar:
[jar] Building jar: xxx\phonegap-2.9.1\lib\android\framework\ cordova-2.9.1.jar
BUILD SUCCESSFUL
Total time: 4 seconds
Done!!!!! The file is ready! And you can find this and other information reading a file inside the phonegap-2.9.1.zip:
phonegap-2.9.1\lib\android\README.md
Since 3.x version phonegap has changed a lot. I suggest you to install 3.3 version and create a proyect following the steps described in the offical page.
Also, you can download cordova from cordova web page, add to path, and create a proyect using terminal:
cordova create app_name
cordova platform add android || cordova build android
In 3.3.0 version, You can get cordova-3.3.0.jar file by following these steps:
Go to Command Prompt:
$ cd %HOMEPATH%/.cordova/lib/android/cordova/3.3.0/framework
$ android update project -p
$ ant jar
After executing these commands you will get cordova-3.3.0.jar in framework folder i.e.
=> %HOMEPATH%/.cordova/lib/android/cordova/3.3.0/framework/cordova-3.3.0.jar

PhoneGap 3.0 Android build Command failed to execute : ant jar

I installed PhoneGap 3.0 with Node.js and configured all the environment variables so that javac, java, and ant all work but when I do a basic app create and try to build it for Android, I get the following error:
An error occurred during creation of android sub-project. Creating Cordova project for the Android platform: Command failed to execute : ant jar
Any ideas?
Make sure you have the Android Build Tools installed for your Android SDK version. In the Android SDK manager under Tools>Android SDK Build-tools you should see that the Build tools for your SDK version are not installed.
Detail on how I uncovered this:
To identify this as the root cause I ran the Cordova command with -d for verbosity:
cordova -d platform add android
The output of this command shows the error:
Running bin/create for platform "android" with command: ""C:\Users\---\.cordova\lib\android\cordova\3.1.0\bin\create" "C:\Users\---\workspace_android\FleetView\platforms\android" "com.---.fleetview" "Fleet View"" (output to follow)
Running the offending command directly:
"C:\Users\---\.cordova\lib\android\cordova\3.1.0\bin\create" "C:\Users\---\workspace_android\FleetView\platforms\android" "com.---.fleetview" "Fleet View"
produces this output:
BUILD FAILED
C:\tools\adt-bundle-windows-x86_64-20130219\sdk\tools\ant\build.xml:479: SDK does not have any Build Tools installed.
Total time: 1 second
Command failed to execute : ant jar
I am on Windows 7.
This is due to ANT tools could not find tools.jar in JRE lib directory. When I copied tools.jar from JDK lib directory to JRE lib directory, the problem was absolutely solved and the build was successful when I ran the command "cordova -d platform add android". Hope this helps you.
Posted the answer to similar question: Android Platform Guide trouble with adding a platform through the command line
A combination of 2 things worked for me:
include the JDK in your path (path\to\jdk\bin of course)
exclude the JRE from your path (or at least have it come after the JDK)
I faced the same issue,
I was having jdk-6 and I updated to jdk-7,
that fixed the issue,
Also I didn't installed ant in the first place,
in your case ant PATH might be missing.
See if that helps.

Android build from command line in Windows

I would like to build an Android project from command line instead of using Eclipse. I have installed ant on my Windows Vista, and I would like to run ant release but I can't find the file build.xml in the root directory of my Android project.
The project has been created using Eclipse. Is there a particular reason why the file build.xml doesn't exist ? How to find/generate it please ?
Thanks.
Take a look at this doc wrt how to update an Android project:
https://developer.android.com/studio/tools/help/android.html

Categories

Resources