The import org.apache.cordova cannot be resolved

2020-02-03 04:29发布

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.

7条回答
聊天终结者
2楼-- · 2020-02-03 04:55

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.

查看更多
混吃等死
3楼-- · 2020-02-03 04:56

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.

查看更多
爷的心禁止访问
4楼-- · 2020-02-03 05:00

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

查看更多
叼着烟拽天下
5楼-- · 2020-02-03 05:00

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.

查看更多
▲ chillily
6楼-- · 2020-02-03 05:08

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.

查看更多
等我变得足够好
7楼-- · 2020-02-03 05:08

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

查看更多
登录 后发表回答