Unable to build cordova project for android - android

I'm not cordova/android expert. I was provided with build steps to build some cordova project. However they stopped working after quite some time. I'm using old cordova 6.5.0 to build a cordova project for android. I don't believe i've changed any setup or libraries. I deleted my android studio and android sdk and installed them again. And Now i'm getting lots of weird errors like:
When i do cordova build android
Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
Error: Error
at /platforms/android/cordova/lib/check_reqs.js:313:19
at _fulfilled (XXX/platforms/android/cordova/node_modules/q/q.js:854:54)
at self.promiseDispatch.done (XXX/platforms/android/cordova/node_modules/q/q.js:883:30)
at Promise.promise.promiseDispatch (XXX/platforms/android/cordova/node_modules/q/q.js:816:13)
at XXX/platforms/android/cordova/node_modules/q/q.js:877:14
at runSingle (XXX/platforms/android/cordova/node_modules/q/q.js:137:13)
at flush (XXX/platforms/android/cordova/node_modules/q/q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:95:7)
at process._tickCallback (internal/process/next_tick.js:161:9)
I do have ANDROID_HOME:
/root/Android/Sdk
and $PATH:
echo $PATH
/home/XXX/.sdkman/candidates/gradle/current/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/usr/lib/jvm/java-8-oracle/bin:/home/XXX/dev/tools/idea-IU-145.258.11/bin:/root/Android/Sdk/tools:/root/Android/Sdk/platform-tools:/home/XXX/.sdkman/candidates/gradle/4.4.1/bin
I tried building it with android studio, supplying various version of gradle, but i always get stuck with some weird errors.
How can i understand what have happened? What versions of which libs i suould use?
Thanks

Related

Can't add android platforms in cordova 3.5.0

here is the information shown in my commandline:
$ cordova platforms add android
Creating android project...
Error: ENOENT, no such file or directory 'C:\Users\Administrator\.cordova\lib\android\cordova\3.5.0\VERSION'
at Object.fs.openSync (fs.js:427:18)
at Object.fs.readFileSync (fs.js:284:15)
at c:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\platform.js:351:42
at _fulfilled (c:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:798:54)
at self.promiseDispatch.done (c:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:827:30)
at Promise.promise.promiseDispatch (c:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:760:13)
at c:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:821:14
at flush (c:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
First go to that path and see if the file it's looking for is indeed missing.
C:\Users\Administrator\.cordova\lib\android\cordova\3.5.0\VERSION
If it is then reinstall cordova using the following commands:
npm uninstall cordova -g
npm cache clean
npm install cordova -g
Then try again and see if you get the same error.
SyntheCyphers answer worked for me after manually deleting the whole .cordova folder and then running cordova platform add android in project folder.
When u create a project in cordova 3.5.0, version file in .cordova is missing.
So unable to add android platform. I have copied version file from 3.4.0 and paste it to 3.5.0 with version change as 3.5.0. and with it, my issue is solved.

cordova platform add android - Not working on Mac Os

I'm new to cordova mobile app development. I have install Node and then install cordova. i have done those steps to create a cordova android app.
cordova create hello com.example.hellow HelloWorld This work fine
cd hello Navigation to directory_
cordova platform add android This is not working
This is the error showing my terminal
Jeys-MacBook-Pro:hello mactec$ cordova platform add android
Creating android project...
/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:126
throw e;
^
Error: The command "android" failed. Make sure you have the latest Android SDK installed, and the "android" command (inside the tools/ folder) is added to your path.
at /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/lib/check_reqs.js:85:29
at _rejected (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:808:24)
at /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:834:30
at Promise.when (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:752:41)
at /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:574:44
at flush (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
Error: /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/create: Command failed with exit code 8
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/src/superspawn.js:126:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
Jeys-MacBook-Pro:hello mactec$
Please help me to short-out this issue
Thanks in advance.
The problem is PATH wrongly defined on .bash_profile.
What i have done for this.
Change the path on bash profile open ~/.bash_profile. Then the bash profile open in a text editor.
Add the correct path to android SDK. If we have android studio then the path is /Application/Android Studio.app/sdk/ so we need to add this path to .bash_profile. export PATH=${PATH}:/Applications/Android\ Studio.app/sdk/tools
Then close all terminal and open again and code... :)
You can check that is working or not via typing android on terminal.
The error show in quite clear.You have to have the android sdk installed and proper path set in the system variable for the SDK, for cordova to work.See the prerequisites in cordova documentation http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html.For cordova 3.4 project android SDK must have target 19 installed.
Download SDK here http://developer.android.com/sdk/index.html
Here is the platform guide for more information http://cordova.apache.org/docs/en/3.0.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide
If you already have the SDK installed,check to see if the path is refered properly for cordova to find
There's also another potential cause for this error: an errant file in your project/www directory. I had inadvertently included a blank file called project/www/:q ("colon q") in www/ (note I use Vim)! Anyway, doing this yields the exact error as noted by JeyTheva. So, delete that file and do the following:
cordova platform remove android
rm -r ~/.cordova/lib/android
cordova platform add android
Now rebuild and run on your device. This should work if you did something similar to what I did.

cordova ubuntu: An error occurred while listing Android targets

I'm trying add the android platform to my cordova project, though I get the error:
$ cordova platform add android -d
cordova library for "android" already exists. No need to download. Continuing.
Checking if platform "android" passes minimum requirements...
Checking Android requirements...
cordova library for "android" already exists. No need to download. Continuing.
Error: An error occurred while listing Android targets
at /home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/lib/check_reqs.js:83:29
at _rejected (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:808:24)
at /home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:834:30
at Promise.when (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:752:41)
at /home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:574:44
at flush (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
Without the -d it will be:
Checking Android requirements...
[Error: An error occurred while listing Android targets]
I'm not sure what configuration I am missing. In my ~/.bashrc file I have:
### Java
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
export ANDROID_HOME=~/Code/adt-bundle-linux-x86-20131030/sdk/tools
export ANDROID_PLATFORM_TOOLS=~/Code/adt-bundle-linux-x86-20131030/sdk/platform-tools
export PATH=$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH
and I have ant installed:
$ ant -version
Apache Ant(TM) version 1.8.2 compiled on December 3 2011
What's missing? Why do i get the error An error occurred while listing Android targets when trying to add the android platform to the cordova project?
Cordova has a script to check if all dependencies are present. Is is called when you run cordova platform add android but unfortunatly it's output is not displayed when it fails.
You can try to run it manually, it should be $home/.cordova/lib/android/cordova/3.5.0/bin/check_reqs
The normal output when everything's fine is "Looks like your environment fully supports cordova-android development!", oterwise it should display a clear message about what's missing.
Maybe your issue is that you havent't installed SDK platform for API 19 in android sdk manager (cordova 3.3 or 3.5 uses target sdk 19).
Update: Cordova 3.3 or 3.5 works on SDK 19 only (Android 4.4.2). The error logs does not mention clearly what platform version it is looking for. Typically error messages are:
Unable to add platform android. Please see console for more info.
or
[Error: An error occurred while listing Android targets]
This can also happen when android (sdk/tools) is not in path. I would have loved if the check-script have printed correct error message. BTW, created a PR for them.
in .bashrc try adding
export ANT_HOME="/usr/bin/ant"
export PATH="$PATH:$ANT_HOME/bin"
export HOME="/home/username"
export ANDROID_HOME="$HOME/android-bundle/sdk/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/android-bundle/sdk/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"
or try explicitly define the paths globally.
from the terminal I type:
export PATH=${PATH}:~/dev/adt-bundle-linux-x86_64-20140321/sdk/tools
export PATH=${PATH}:~/dev/adt-bundle-linux-x86_64-20140321/sdk/platform-tools
(rememebr to replace with your own sdk path)
If this doesn't work, try updating the sdk
Please Refer the Question
An error occurred while listing Android targets
and the Link
developer.android.com/tools/devices/managing-avds-cmdline.html
Most probably the path variable pointing to this android was wrong. I had used %ANDROID_HOME% as variable and scaled the same to path variables %ANDROID_HOME%\SDK\TOOLS. This method doesn't work. Experimentally resolved by directly pointing to the Tools and Platform Tools.
Just based on what I did and it worked for me. Hope You get the Issue resolved
I had faced the Issue even after the Cordova check_reqs was working correctly without providing any error.But on adding a new platform this error was still being raised. The above method personaly resolved my issue.
I solved the problem giving full permission for my app folder
$ sudo chmod -R 777 myApp
After that, try again
$ cd myApp
$ ionic platform android

phonegap run android error

Whenever I try to build a project using phonegap run, I get the below error:
C:\Users\MS AwaN\my-app>phonegap run android
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
[error] An error occured during creation of android sub-project.
C:\Users\MS AwaN\.cordova\lib\android\cordova\3.3.0\bin\node_modules\q\q.js:126
throw e;
^
Error: An error occurred while listing Android targets
at C:\Users\MS AwaN\.cordova\lib\android\cordova\3.3.0\bin\lib\check_reqs.js:87:29
at _rejected (C:\Users\MS AwaN\.cordova\lib\android\cordova\3.3.0\bin\node_modules\q\q.js:808:24)
at C:\Users\MS AwaN\.cordova\lib\android\cordova\3.3.0\bin\node_modules\q\q.js:834:30
at Promise.when (C:\Users\MS AwaN\.cordova\lib\android\cordova\3.3.0\bin\node_modules\q\q.js:1079:31)
at Promise.promise.promiseDispatch (C:\Users\MS AwaN\.cordova\lib\android\cordova\3.3.0\bin\node_modules\q\q.js:752:41)
at C:\Users\MS AwaN\.cordova\lib\android\cordova\3.3.0\bin\node_modules\q\q.js:574:44
at flush (C:\Users\MS AwaN\.cordova\lib\android\cordova\3.3.0\bin\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:415:13)
Can anyone please suggest what I am doing wrong?
I had the same problem and this fixed it. Alternately look here (which is the same but has a link to the documentation which I also missed).
It seems that phonegap 3.3 requires android sdk 19.
If you have a older one, try the following steps :
delete the platforms/android folder (as the log say "Adding the android platform", I assume you didn't perform any customisations in that folder)
use android sdk manager to install the latest sdk
retry with phonegap build android and if it fails, run phonegap -V build android to get more details on the error

Cordova CLI on Windows8 can't find hooks

I'm trying to compile my phonegap project using the cordova cli on my Win8 machine. I've updated all my Android SDKs, updated cordova and phonegap but I cannot build my project. I get an error that the .cordova/hooks/any_hook is empty.
I looked in that directory and can't see any files in there. How do those files get there and is the latest version of cordova bad? Until now I've been compiling on my Mac because I couldn't get the PC setup correctly so today I decided to take a crack at it and have failed.
I even created a new hello world project using the CLI but still no luck in building the thing because of the supposed missing hook files. Anyone have any insight to this.?
Also, I've tried using the command prompt in both ADMIN and regular mode. Still no luck.
EDIT:
I'm using phonegap 3.3.0-4.18.0
Path to hooks:
Z:\projecttitleroot\projecttitle.cordova\hooks
OUTPUT OF PHONEGAP BUILD WITH DEBUG:
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] compiling Android...
[error] ENOENT, no such file or directory 'Z:\myprojectroot\myproject\.cordova\hooks\before_build'
I want to point out that I'm using phonegap command to compile and run, NOT cordova as per the documentation for the latest version.
If I run:
cordova -d build android
I get this:
Z:\myprojectroot\myproject>cordova -d build android
C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:126
throw e;
^
Error: ENOENT, no such file or directory 'Z:\myprojectroot\myproject\.cordova\hooks\before_build' at Object.fs.readdirSync (fs.js:654:18)
at C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\src\hooker.js:64:34
at _fulfilled (C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:798:54)
at self.promiseDispatch.done (C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:827:30)
at Promise.promise.promiseDispatch (C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:760:13)
at C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:821:14
at flush (C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
Z:\myprojectroot\myproject>
Make sure you put your hooks into subdirectories inside the hooks directory.
Path to hooks: Z:\projecttitleroot\projecttitle.cordova\hooks\before_build\

Categories

Resources