Error initializing Cordova: Class not found

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

I followed the tutorial of Phonegap from the official Phonegap.com site (getting started with Android).

I have created project with following all the steps.

  1. created activity and extended from "DroidGap" and added loadURL method from onCreate().
  2. Added cordova-2.0.0.js and cordova-2.0.0.jar on the respective folder.
  3. Added the jar file to the build path
  4. Loaded the js file from the html tag
  5. Added permissions from AndroidMainfeast.xml
  6. copied the xml folder containing "configs.xml"

Now I don't understand where's the problem. It is showing the below error as shown in the screenshot

Here is my HTML file

         Notification Example

Show Alert

Play Beep

Vibrate

Any advice? Thanks!

回答1:

It is config.xml not configs.xml.

Based on the logs I'm seeing you are missing this file in your apps res/xml directory. It is included as part of the distribution at lib/android/res/xml/config.xml so copy that file into your res/xml directory and you should be all set.



回答2:

Just as aharris88 in his answer to this question, I had the [CORDOVA] Error initilizing Cordova: Class not found error message when using Cordova 3.1.0 on my Android dev phone after migrating from Phonegap 3.0.

All fiddling with the config.xml file in the /platforms/android/res/xml directory did not help. Based on the Stackoverflow answer mentioned above, I tried to "start over" by reinstalling Android platform support:

cordova platform rm android cordova platform add android 

After this step it worked again, and I was able to cordova build android && cordova run android without any further problems.



回答3:

I have had this error because of a plugin that I deleted. I Added

to the config.xml file again and it fixed it.



回答4:

My you not have following plugin:

You have to put that in between . like



回答5:

Well,the error I found is:

05-28 08:19:53.139: E/PluginManager(1478): ===================================================================================== 05-28 08:19:53.139: E/PluginManager(1478): ERROR: config.xml is missing. Add res/xml/config.xml to your project. 05-28 08:19:53.139: E/PluginManager(1478): https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml

but I found /res/xml/config.xml in my project

finally,I found error in org.apache.cordova.api.PluginManager:

public void loadPlugins() { int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml",    this.ctx.getActivity().getClass().getPackage().getName()); ... 

should change to:

public void loadPlugins() { int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml",    this.ctx.getActivity().getPackageName()); ... 

you could read more about the method "getIdentifier(String name, String defType, String defPackage)" in offical doc



回答6:

I had this problem using phonegap 3.x and the problem turned out to be that phonegap hadn't properly installed the plugins, or they just messed up along the way. Basically when you install the plugins and build for a platform it takes the javascript files from plugins/org.apache.cordova.core.specific-plugin/www and puts them in platforms/android/assets/www/plugins/org.apache.cordova.core.specific-plugin/www and then it takes the Java files (or objective C for iOS) and puts them in platforms/android/src/org/apache/cordova/specificplugin

And all of this is specified by plugins/org.apache.cordova.core.specific-plugin/plugin.xml. If you look in a plugins.xml you should see something like:

So this tells you that in platforms/android/src/org/apache/cordova/networkinformation, there should be NetworkManager.java. And that file can be copied from plugins/org.apache.cordova.core.network-information/src/android/NetworkManager.java

Now all of this is supposed to happen automatically without having to touch the platforms folder. But if it messes up you can fix it by manually copying the correct files into the correct folders.



回答7:

You can resolve this when using phonegap command line by doing the following:

  1. Delete merges/android, platforms/android, plugins/android.json

  2. run phonegap local build android



回答8:

Had same problem with Class not found. One problem to look at is to ensure that the android.json (or ios.json) file is being updated on a build. Mine was effectively empty. Also, remove and add back the plugins as mentioned in some other posts. Finally, the thing that worked for me was to ensure that the plugins were corrected referenced in the config.xml:

Note the double naming of 'device.Device' and also the sub-classing of the 'camera' and 'dialogs' plugins. This just isn't properly referenced by the Phonegap documentation.



回答9:

I ran into the same error: "Error initializing Cordova: Class not found", using cordova with visual studio 2015. But this wasn't the only error, none of my plugins seem to get trough. I've tried about EVERYTHING. From cordova platform rm/add android x1000 times, to deleting and re-adding the plugins manually, nothing seem to do the trick.

Then i changed my cordova-cli in the taco.json file from 5.3.3 to 5.4.0 and ran it on my device. Finally this fixed the whole issue for me. I then downgraded the cordova version back to 5.3.3 ( the 5.4.0 version is not supported by the adb bridge as of yet ). Try it out!



回答10:

I'm getting the same error, I checked my Cordova plugin list

by running the command "cordova plugin list" in my Android project directory and found "org.apache.cordova.device" plugin missing.

I updated it using "Cordova plugin add cordova-plugin-device" and Error was gone.



回答11:

So After near to kill myself , i found that i was using cordova version 5.3.3 and cordova-android version 5.0.0, somehow i don't know may be there are not compatible or there can be a bug ,so i fall back to cordova android 4.1.1

  cordova platform rm android   cordova platform add android@4.1.1  

and this saved me up



回答12:

[Solved in my case]

First, step six is wrong: it is config.xml and not configs.xml

I have the same error despite I have my config.xml in res/xml folder. It is because you have to install manually plugins for basic API functions.

Through console navigate to your project folder and type:

phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git 

You can read more here in phonegap Doc (last section called add features) : Phonegap Doc

I leave you also my config.xml file

Menu Digital         Description      Name 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!