how to setup environmental variable for android in mac - android

My .bash_profile looks like this
export PATH=$PATH:/Users/subbarao/Library/Android/sdk/platform-tools/
export ANDROID_HOME=/Users/subbarao/Library/Android/sdk/
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
even $(user/libexec/path_helper -s)
When I give ionic platform add android I am getting like this
When I give ionic run android I am running into this error
Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: /Users/subbarao/Library/Android/sdk/tools/templates/gradle/wrapper

You have cordova-android v 6.1.2. There was an issue with cordova-android. Check this answer.
Try
ionic platform add android#6.2.1
Or
ionic platform add android#latest
Update:
if you are using ionic cli v3, the command is
ionic cordova platform add android#latest

Update SDK and gradle version and then try following commands in the terminal
export ANDROID_HOME=/Applications/ADT/sdk
PATH environment variable
export PATH=$PATH:$ANDROID_HOME/bin

Related

“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.

fs-extra: source and destination must not be the same. (cordova)

I get an error while building with cordova.
Error: Source and destination must not be the same.
Build-System:
Ionic:
ionic (cli): 4.10.1
ionic framework: ionic-angular 3.9.2
#ionic/app-scripts: 3.1.11
Cordova:
cordova (cli): 8.1.2 (cordova-lib#8.1.1)
platforms: "cordova-android": "8.0.0"
System:
Android SDK Tools: 26.1.1
NodeJS: 10.15.3
npm: 6.4.1
OS: Windows 10
Command:
ionic cordova build android
or
cordova build --release
Error-Details:
Error: Source and destination must not be the same.
at checkPaths (C:\Jenkins\workspace\%PROJECTNAME%\node_modules\fs-extra\lib\copy-sync\copy-sync.js:185:11)
at Object.copySync (C:\Jenkins\workspace\%PROJECTNAME%\node_modules\fs-extra\lib\copy-sync\copy-sync.js:25:20)
at updatePathWithStats (C:\Jenkins\workspace\%PROJECTNAME%\node_modules\cordova-common\src\FileUpdater.js:103:24)
at C:\Jenkins\workspace\%PROJECTNAME%\node_modules\cordova-common\src\FileUpdater.js:298:19
at Array.forEach (<anonymous>)
at Object.mergeAndUpdateDir (C:\Jenkins\workspace\%PROJECTNAME%\node_modules\cordova-common\src\FileUpdater.js:296:33)
at updateWww (C:\Jenkins\workspace\%PROJECTNAME%\platforms\android\cordova\lib\prepare.js:157:17)
at Api.module.exports.prepare (C:\Jenkins\workspace\%PROJECTNAME%\platforms\android\cordova\lib\prepare.js:56:19)
at Api.prepare (C:\Jenkins\workspace\%PROJECTNAME%\platforms\android\cordova\Api.js:177:45)
at C:\Jenkins\workspace\%PROJECTNAME%\node_modules\cordova\node_modules\cordova-lib\src\cordova\prepare.js:105:36
Does anyone facing the same error or has an idea what's wrong?
Additional infos:
I always check out the git repository to a empty folder. This means: It's a hard-clean every build. No node_modules and no platform, etc. (rm platform etc. is useless)
I don't know if this is the correct answer, but it could be a wrong setting in the cordova build.json (if you have one).
Since you are using Jenkins, maybe you have some wrong settings there like missing dependencies or something like that.
You can also try to remove the platform and add it again to get the latest version and compatibility.
cordova platform remove android
cordova platform add android#8.0.0
You can check if you have an outdated fs-extra (although I don't think that is the problem) and update Ionic.
You can try to restore your node_modules.
I hope one of these steps help.
At first, manually remove this:
node_modules folder
package-lock.json file
platform > android folder
then use this commend:
1 => npm rm -rf node_modules package-lock.json
2 => npm cache clear --force
3 => ionic cordova platform add android#8.0.0
4 => ionic cordova prepare android
5 => ionic cordova run android
The problem is fs-extra checkPaths method of copy operation. There is a check of state.ino (inode) of node fs which is evaluated as number. Bigint is also supported but not enabled. This is the reason that the comparsion can fail. Because max-safe-integer in JavaScript is 53-bit. Maybe also a symlink issue.
See / Join:
https://github.com/jprichardson/node-fs-extra/issues/657
Why Cordova-Android 8.0.0?
Because https://github.com/apache/cordova-common/blob/master/RELEASENOTES.md . fs-extra is new in this version.
In my case it happened while removing/adding android again to make sure that some plugins are updated.
This solution fixed my issue as referenced here
cordova clean android

cordova requirements are not satisfied. "Android SDK Not Found"

i am using cordova version 6.5.0.
after following the instructions on cordova site , i have wrote those commands in the CLI
cordova create myApp com.myCompany.myApp myApp
cd myApp
cordova plugin add cordova-plugin-camera --save
cordova platform add android --save
cordova requirements android
i get this error:
i have installed android studio on its default location.
C:\Users\Liran\AppData\Local\Android\sdk
i have the sdk tools installed as it is shows in sdk manager.
what else can i check to solve it?
Setup the Environment Variables at control Panel, selecting Advanced system settings, and clicking Environment Variables.
Then add the ANDROID_HOME variable with the value:
C:\Users\Liran\AppData\Local\Android\sdk
Then setup in the variable path in your Environment variables in the end something like the next line, add first semicolon
[[text in path];%ANDROID_HOME%;
Check this link: https://spring.io/guides/gs/android/#android-dev-env

Ionic 2 platform add android error

Im trying to build an android app with ionic 2. When I try to run ionic platform add android I get this error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually. Failed to find 'android' command in your 'PATH'.
Im using linux mint and already set the environment variables like this:
export ANDROID_HOME=/home/mauro/Android/Sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
When I type android in the console, the sdk manager gets started.
My ionic version is: 2.1.7
and cordova: 6.4.0
Hope anybody can help me with this issue.
Instruction 1:
After adding your ANDROID_HOME, make sure you do the below:
Restart your System or run source ~/.bash_profile
Remove Android platform from your project ionic cordova platform rm android or ionic platform rm android
Add Android platform ionic cordova platform add android
Then ionic cordova run android or ionic run android
Instruction 2:
To set your ANDROID_HOME and JAVA_HOME, follow the below steps:
Run command open ~/.bash_profile
Paste the below in the file that opens on your Text editor
export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.4.1_1
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Save - "Command S" or "Ctrl S"
Then Follow the "Instruction 1:" above
Hope this helps.....
I have the same issue. It seems to be an issue of the combination of cordova, the installed Android SDK version and the profile settings.
This is what worked for me on ubuntu 16.10:
get an older cordova that is known to work:
npm install -g cordova#4.2
(I was on 6.4.0 and 5.0.0)
in .profile:
PATH="~/Android/Sdk/platform-tools:~/Android/Sdk/tools:$PATH"
export ANDROID_HOME=~/Android/Sdk
(Seems you are good there)
I needed the latter to stop the complaining about it even while android was in my path and it also gave me meaningfull errors, which was that API 22 was missing.
Load the profile in current bash:
source ~/.profile
Type android and install SDK 22.
Exit when done and type
ionic build android
and it should work.

Phonegap/cordova add Android Platform on Mac not recognized as core cordova platform

I have an issue with setting up an Android Project on Mac OS.
with the command:
$cordova platform add /path/to/androidSDK/android
I've got the error message:
[Error: Platform "/path/to/androidSDK/android" not recognized as core cordova platform.]
Does anyone have the same Issue ? How can I fix that ?
latest Android SDK version (downloaded today).
Phonegap version: 3.1.0-0.15.0
OSX 10.9 Mavericks
To install the cordova command-line tool, follow these steps:
First of all go through the Cordova Document
For Cordova command-line tools to work, you need to include the SDK's tools and platform-tools directories in your PATH environment. On Mac, you can use a text editor to create or modify the ~/.bash_profile file, adding a line such as the following, depending on where the SDK installs:
export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools
Next Steps:
Download and install Node.js from Here. Following installation, you should be able to invoke node or npm on your command line.
Install the cordova utility. In Unix(Mac), prefixing the additional sudo command may be necessary to install development utilities in otherwise restricted directories:
For Mac $ sudo npm install -g cordova
once successful installation of cordova is done ,now you can create your application
across all the platforms.
Create the Cordova Application
Go to the directory where you maintain your source code, and run a command such as the following:
$cordova create hello com.example.hello CordovaDemo
hello is the directory where you want to create your application
com.example.hello is the package name
CordovaDemo is the name of the Application
Once Successful creation of your project, some file will be created inside the directory i.e hello
Add Platforms
All subsequent commands need to be run within the project's directory, or any subdirectories within its scope:
$ cd hello
Now you need to specify a set of target platforms, Supported OS for Mac
$ cordova platform add android
plz tell me if you are still having problem.
Hope this will help you.
this is documentation Phonegab docs
and my .bash_profile:
export PATH=${PATH}:$HOME/Development/adt-bundle-mac-x86_64-20140321/sdk/platform-tools:$HOME/Development/adt-bundle-mac-x86_64-20140321/sdk/tools
visit the solution here
I hope this helps you

Categories

Resources