25

For some reason, after going through Phonegap's non-inclusive instructions (it doesn't even mention setting up ANT, or the headaches with Ant and JDK), this doesn't work at all:

package com.HealthTrustSoftware.AndroidTemplate3;

import android.app.Activity;
import android.os.Bundle;
import org.apache.cordova.*;

public class AndroidTemplate3 extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");
    }
}

It gives 5 errors referencing the fact that org.apache.cordova can't be resolved. I'm entirely sure what to do at this point. Please help. This is after 3 hours of trying to get the sdk working and finally being able to open a project within eclipse. After following the steps on their documentation, I am left with a wasted 3 hours unless I can figure this out.

4
  • 4
    Make sure org.apache.cordova is on your classpath. Nov 28, 2012 at 23:01
  • 3
    sorry if this is a stupid question, but HOW? Nov 28, 2012 at 23:18
  • Are you in a Java Project (as Eclipse considers it)? Open its Properties and add the necessary libraries to the Build Path.
    – nitind
    Nov 28, 2012 at 23:44
  • Do you see a cordova-2.2.0.jar in your project libs directory? Nov 29, 2012 at 1:57

8 Answers 8

23

I just ran into the same problem. Following what was written in here, I finally made it work.

After you download cordova from phonegap github page, you will find cordova-2.2.0.jar and cordova-2.2.0.js in lib/android folder. After running "./create ...", copy cordova-2.2.0.jar into your projects libs folder and cordova-2.2.0.js into your www folder. Then import the project into eclipse and it should work.

I had to go to "Project -> Properties -> Android" and select a newer SDK (I selected the latest one available on the list) and than run the "Project -> Clean" as well.

4
  • 1
    The "from phonegap github page" is key here. Jan 9, 2013 at 13:19
  • 1
    Having a very similar problem with cordova-2.7 and the importing jar fix isn't solving it.
    – obimod
    May 15, 2013 at 22:21
  • 1
    Same issue here with cordova-2.7
    – funkyeah
    May 31, 2013 at 18:56
  • 1
    Same issue in phonegap 3.4.0 android
    – gnganapath
    Apr 8, 2014 at 13:12
7

In addition to copying cordova-2.2.0.jar from the phonegapp download to the libs folder of the project I had to manually add it to the projects libraries.

Procedure: Project -> properties -> Java Build Path -> Libraries -> Add JARs... Then select the libs from the project itself

3

Android studio: File -> Invalidate cache / Restart. Worked for me...

2

I initially got around this using one of the solutions posted above: about downloading the phonegap from github and pasting in the cordova-2.2.0.jar and cordova-2.2.0.js files into the generated directories.

After fiddling around with the path and environment variables these files are already in place (project/libs/cordova-2.2.0.jar and project/assets/www/cordova-2.2.0.js) now for me after running the "create" command on command line.

I am using the ANT that came bundled with Eclipse so my PATH variable includes:

C:\Program Files\Eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\bin;

and I added an environment variable for ANT_HOME of: C:\Program Files\Eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730

I tested adding \bin or removing it to both the PATH and environment variable for ANT_HOME and this was the winning combination.

2

Run cordova -d build. If it says anything about "Unable to locate tools.jar", fix that. Then completely rebuild the application by running cordova platform rm android. Also remove the project from eclispe. Then recreate the app by running cordova platform add android + cordova build. Finally add the project in eclipse again.

org.apache.cordova should now be included and everything should be working.

1

Replace your header with some miner changes like bellow

 import com.google.android.gcm.GCMRegistrar;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaInterface;
import org.apache.cordova.api.CordovaPlugin;
0

Step 4 in the getting started guide is the only part specific to phonegap. The rest is setting up a general android development environment. Instead of eclipse classic, get the ADT bundle from http://developer.android.com/sdk/index.html - that includes a custom version of eclipse with most of the android stuff ready to go.

The default link to cordova-2.2.0.jar worked fine for me, though it did take a bit of effort to work out that if you want to use a custom build of cordova it needs to be set up as an android library dependency in project properties.

1
  • I also need to port to ISO. The libs folder is co. Nov 29, 2012 at 5:27
-1

Download apache cordova jar and add it to lib folder and classpath.

4
  • your link just points to the same repo that I already downloaded! Nov 28, 2012 at 23:04
  • @AndrewRhyne:If you already downloaded, then have you added it to classpath?
    – kosa
    Nov 28, 2012 at 23:04
  • 1
    There are absolutely no instructions on their documentation regarding this. Can you please point me in the right direction? I don't see a cordova.jar in the project folder at all Nov 28, 2012 at 23:06
  • I need to step out. See this link, it may help. docs.phonegap.com/en/2.2.0/…
    – kosa
    Nov 28, 2012 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.