0

I'm new to both tools. I'm trying to get a sample application working, a flashlight app that I saw on github. I'm using OSX. I've created a project and added the platform too, android. However, I'm not sure how to start the application.

I was reading this stackoverflow post and the guy mentions that android sdk and platform tools are needed, Phonegap/cordova add Android Platform on Mac not recognized as core cordova platform Where can I find those?

Since I was curious, I ran phonegap run android and below is what I got then it went back to the prompt. Nothing happened.

[phonegap] executing 'cordova run android'...
[phonegap] completed 'cordova run android'

Fyi, this is what is in my directory right now

drwxr-xr-x  3 user01  207825898  102 Dec 23 12:15 hooks/
drwxr-xr-x  6 user01  207825898  204 Dec 23 12:19 www/
-rw-r--r--  1 user01  207825898  992 Dec 23 12:32 config.xml
drwxr-xr-x  6 user01  207825898  204 Dec 23 12:32 plugins/
drwxr-xr-x  4 user01  207825898  136 Dec 23 12:32 platforms/

And this is my unix history output

$ cordova create .
$ ls -lrt
$ cordova plugin add https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin
$ cordova platform add android

Then I ran this

$ cordova build

However, I got an error

Running command: /Users/user01/repos/Flash/platforms/android/cordova/build
[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 building one of the platforms: Error: /Users/user01/repos/Flash/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /Users/user01/repos/Flash/platforms/android/cordova/build: Command failed with exit code 2

What am I missing? I watched a tutorial in youtube and the person used Eclipse. Do I really need an Eclipse editor to be able to start a phonegap application? I was hoping I can just copy the build directory into an Apache server then visit the webserver from a phone. However, I'm not sure if I do it this way, I'm missing the purpose of phonegap.

Community
  • 1
  • 1
devwannabe
  • 3,160
  • 8
  • 42
  • 79

1 Answers1

1

Set ANDROID_HOME system variable to the location of your Android sdk. Also add the bin folder of your Android sdk to the system variable path.

Cordova looks for the Android sdk and binaries by evaluating those two variables.

sschrass
  • 7,014
  • 6
  • 43
  • 62
  • Ok, looks like i need to install android sdk? I'll google it. Is there such thing as sdk platform? That's what the person mentioned on the so I included in my post – devwannabe Dec 23 '15 at 19:11
  • If you want to build apps for Android you ll need the sdk. Çordova just lure you into thinking HTML and JavaScript is everything you need. – sschrass Dec 23 '15 at 19:14
  • Yes you will find the sdk as standalone to download. – sschrass Dec 23 '15 at 19:15
  • In the the bin folder should be a executable called sdkmanager. Run it to install platforms and build tools. – sschrass Dec 23 '15 at 19:24
  • ok, trying it now. I had a question above. Am I right that I really don't need Eclipse to start the app? – devwannabe Dec 23 '15 at 19:25
  • No eclipse needed (opt for Android Studio if you want native development). – sschrass Dec 23 '15 at 19:26
  • Ok. I finished downloading the standalone sdk. I moved it to /usr/local/bin so now I have /usr/local/bin/android-sdk-macosx. I've also assigned this to ANDROID_HOME. I searched for the bin directory and I found it in tools/apps/SdkController/bin. Is this the one I need to add to PATH? – devwannabe Dec 23 '15 at 19:31
  • Could be. I cannot say because I have no Mac. You should find the sdkmanager or similar tooling in this folder. – sschrass Dec 23 '15 at 19:35
  • No, should be .sh not .apk. – sschrass Dec 23 '15 at 19:55
  • I downloaded this specifically the one for mac osx - http://developer.android.com/sdk/index.html#Other This one -> android-sdk_r24.4.1-macosx.zip – devwannabe Dec 23 '15 at 20:00
  • Try looking here http://stackoverflow.com/q/8119282/1087479 without Mac I can't help you that much. You just need to setup the path variable and start the sdkmanager to download platforms and build tools. Good luck. – sschrass Dec 23 '15 at 20:04
  • 1
    I got it working. I found it from their docs. I had to run android sdk to download tools, platforms, etc :) This is the page that helped me - http://developer.android.com/sdk/installing/adding-packages.html – devwannabe Dec 23 '15 at 20:05
  • One more question. Is it possible to have 2 platforms on a single project such as android and wp8? Or should I duplicate the directory and use separate platform for each? – devwannabe Dec 23 '15 at 20:10
  • 1
    Should be possible. This is what Cordova claims to be capable of. But you should ask the "how" in a different question. – sschrass Dec 23 '15 at 20:12