Let me start with some context. I have a Java file and a .jar library which contains an Android project with an Activity, its layout, and another jar library. I also have the javascript interface for my plugin, of course. In other words, this is what I have:
plugins/com.phonegap.example.activity.plugin/www/myplugin.js
plugins/com.phonegap.example.activity.plugin/src/android/MyPlugin.java
plugins/com.phonegap.example.activity.plugin/src/android/libs/myJar.jar
plugins/plugin.xml
My plugin is supposed to execute a method within my MyPlugin.java file which is supposed to then launch the Activity that is within the myJar.jar file.
The plugin.xml for this plugin reads:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="com.phonegap.example.activity.plugin"
version="0.1.0">
<name>MyPlugin</name>
<description>Launch an Android Activity from PhoneGap 3</description>
<author>Author</author>
<license>MIT</license>
<keywords>phonegap,activity</keywords>
<js-module src="www/myplugin.js" name="MyPlugin">
<clobbers target="window.MyPlugin" />
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="MyPlugin">
<param name="android-package" value="com.phonegap.example.activity.plugin"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<activity
android:name="com.phonegap.example.activity.ExampleActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.phonegap.example.action.EXAMPLE" />
</intent-filter>
</activity>
</config-file>
<source-file src="src/android/MyPlugin.java" target-dir="src/com/phonegap/example/activity" />
<source-file src="src/android/libs/myJar.jar" target-dir="libs" />
</platform>
</plugin>
I have installed Phonegap 3.3 and Cordova 3.4 using npm install, and I have Ruby 2.0.0 installed as well. I'm running all this on a Mac OS X.
Onto the problem:
I create a phonegap app to test this plugin (phonegap create TestApp)
I add the Android platform (cordova platform add android)
I run phonegap local plugin add /path/to/plugin/folder from within my newly created app
I run phonegap build android and the compile fails with the following error:
[error] An error occurred while building the android project. Error executing "ant debug -f "/path/to/TestApp/platforms/android/build.xml"":
BUILD FAIL
/path/to/ant/build.xml:720: The following error occurred while executing this line:
/path/to/ant/build.xml:734: Compile failed; see the compiler error output for details.
Total time: 4 seconds
I don't understand why this is happening at all. When I install the plugin it seems like it's been added successfully and it appears within the plugins/android.json file.
At one point, the project automagically decided to compile properly (I don't know what made it work). I tried to access the plugin I had added by adding a line that reads var p = window.MyPlugin within the www/js/index.js, right after the app.receivedEvent('deviceready'); in the onDeviceReady function. I used console.log(p); and it turned out to be undefined, as if my plugin had never been loaded/initialized in the first place.
I suppose this is a problem within my plugin definition, since the Java part has been tested on an Android native app and it was working properly. Where did I go wrong with my plugin? What can I do to troubleshoot it? Why wasn't it initialized? Any help/guidance is very well-appreciated.
======UPDATE=====
I followed Dawson's suggestion to use cordova build android -d and here's the output I received:
[javac] /path/to/TestApp/platforms/android/src/com/phonegap/example/MyPlugin.java:10:
error: package com.phonegap.example.activity does not exist
[javac] import com.phonegap.example.activity.ExampleActivity;
This com.phonegap.example.activity package is defined within the myJar.jar file, so it seems that MyPlugin.java can't find the myJar.jar file.
I think the plugin.xml should be correctly taking care of the including the jar file during plugin installation. This is how it's being added in the plugin.xml:
<source-file src="src/android/libs/myJar.jar" target-dir="libs" />
Any ideas of what may be wrong here?
It's solved thanks to Dawson.
I ran cordova build android -d and viewed its output. Noticed misplaced libraries (myPlugin.java couldn't find myJar.jar) so I just moved them to the proper place as Dawson suggested.
Thanks a lot!
Related
I installed the FacebookConnect plugin into my cordova project with the code:
cordova -d plugin add /Users/your/path/here/phonegap-facebook-plugin --variable APP_ID="123456789" --variable APP_NAME="myApplication"
Then linked the Facebook API (3.8.0) in /platforms/android/project.properties with:
android.library.reference.2=../../facebook-android-sdk-3.8.0/facebook
Then copied the example 'Simple' into the /www folder, added my app id and changed phonegap.js to cordova.js.
When I compile and run the application on my android phone I receive the following errors:
Cordova Facebook Connect plugin fail on init
Cordova Facebook Connect plugin fail on auth.status
and on login:
Cordova Facebook Connect plugin fail on login!Class not found
LogCat gives the following error:
exec() call to unknown plugin: org.apache.cordova.facebook.Connect
I've scoured the internet but cannot find a solution to this problem.
I did notice that my /platforms/android/res/xml/config.xml file lists the plugin as:
<feature name="FacebookConnectPlugin">
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
</feature>
When the Documentation says that it should be:
<feature name="org.apache.cordova.facebook.Connect">
<param name="ios-package" value="FacebookConnectPlugin" />
</feature>
But I can't change this as it's automatically generated during the compiling process.
Did you remember to copy (from the download) www/cdv-plugin-fb-connect.js, www/facebook-js-sdk.js into your apps www folder?
I got the same error, managed to fix by updating my root config.xml (which isn't generated) to include:
<feature name="org.apache.cordova.facebook.Connect">
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
</feature>
(Note android-package as looks like you are using android.)
This is under the manual install section of the readme, but also seems to be necessary after following the automatic install process.
Now you can execute cordova build android from the root, bob's your uncle.
As of 6/13/14 this is what works for me, so I laid out my steps on PasteBin.
http://pastebin.com/WvQvqx6U
Basically just reverted back to 0.4.0 of Facebook Connect.
It's working perfectly for me, and I didn't have any issues setting it up.
I am using phonegap plugin and I could not get it to work. In the plugin, there is a plugin.xml and may I know how this file should be set up.
I have mine configured as below and it does not work.
<platform name="android">
<config-file target="res/xml/config.xml" parent="plugins">
<feature name="GAPlugin" >
<param name="android-package" value="com.adobe.plugins.GAPlugin"/>
</feature>
</config-file>
<source-file src="src/com/learnchn/pinyin/GAPlugin.java"
target-dir="src/com/learnchn/pinyin" />
<source-file src="libs/libGoogleAnalyticsV2.jar"
target-dir="libs" />
</platform>
plugin.xml is a file that is meant to be read and executed by tools such as the plugman to install a plugin to a platform. If you are not using such a tool then you may try to do the steps manually. Basically insert <feature> to res/xml/config.xml and copy src files on <source-file> to target-dir.
However I doubt that the plugin.xml you have posted is valid. The value for "android-package" parameter should point to the plugin implementation. The value "com.adobe.plugins.GAPlugin" would suggest that there would be a corresponding source file or a library with that class name added as part of the installation. However the only file that is added with a close name is "com/learnchn/pinyin/GAPlugin.java" which has a different package name.
At first you have to build your project with phonegap. Navigate to the location where you want to create your project and do the following:
phonegap create test com.example.test Test
cd test
phonegap local build android
Now you have a working android project in your "platforms/android/" directory which you can import in eclipse. Download the GAPlugin and unzip it. Then just use plugman to install the Google Analytics Plugin.
plugman install --platform android --project (Path to your phonegap android project) --plugin (path to the GAPlugin)
Now everything should be set and the plugin is installed. The next step would be initializing the plugin in your index.html to track every page visit. Add the GAPlugin.js
<script type="text/javascript" src="GAPlugin.js"></script>
You should add the following code after you received the "deviceready" event.
document.addEventListener("deviceready", onDeviceReady, false);
var gaPlugin;
function onDeviceReady() {
gaPlugin = window.plugins.gaPlugin;
gaPlugin.init(successHandler, errorHandler, "UA-********-*", 10);
// Put this function everywhere you want to track something
gaPlugin.trackPage( nativePluginResultHandler, nativePluginErrorHandler, "index.html");
function successHandler() {}
function errorHandler() {}
function nativePluginResultHandler() {}
function nativePluginErrorHandler() {}
}
This approach worked for me. I'm using Phonegap 3.0 with the CLI.
Hope this fixes your problems ;)
If u want to add simple google Analytics setup then its quite easy just follow the below steps
1:- Add libGoogleAnalyticsV2.jar in libs folder 2:- Add analytics.xml file inside res->values, it binds the trackingid with the app,u can google for this file 3:-Add import com.google.analytics.tracking.android.easyTracker; in the activity file and use EasyTracker.getInstance().activityStart(this); in onCreate function.
Thats it, you are done with Google Analytics basic setup
I've been trying to upgrade a plugin to v3, and I've managed to get past the plugin loading issues, and I've managed to expose the plugin to the client environment (making changes to the way exec works, etc).
But when I watch the adb logcat with
adb logcat | grep -v nativeGetEnabledTags | grep -i web
I get this error:
D/PluginManager(11189): exec() call to unknown plugin: WebSocket
I can't work out what's gone wrong, and I'm not sure why the Android build can't see the plugin.
I've pushed ALL the code to a github repo, so if someone is able to replicate and help I'd be very welcome! I'm also trying to write up my experience of the conversion and logging the gotchas as I hit them (there's some in the readme, though it's incomplete):
Here's the repo: https://github.com/remy/phonegap_test
– Remy
define your plugin in "res/xml/config.xml"
find these lines in the file
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
and append these right after:
<feature name="MyPluginName">
<param name="android-package" value="com.phonegap.plugins.plugin.class" />
</feature>
replace the dummy names (MyPluginName, plugins.plugin.class, etc) with the actual names. This works for me when I was getting this error:
exec() call to unknown plugin : MyPluginName
I am all of a sudden getting the same issue with my phone gap build (2.6). Same exact code worked prior so it must be a build issue.
Did you tried to open your apk and see if config.xml is included (there is where plugins are defined).
On Android Studio 1.0.1 (running on Mac OS 10.9.5) + Cordova 4.2.0, I fixed a similar problem ("exec() call to unknown plugin") as follow:
it happened that the content of the tag:
<feature name="MyPluginName">
<param name="android-package" value="com.phonegap.plugins.plugin.class" />
</feature>
Under YourCordovaProjectName/config.xml was not duplicated under YourCordovaProjectName/platforms/android/res/xml/config.xml
I had to alter the file config.xml under YourCordovaProjectName/platforms/android/res/xml/ and to add the tag:
<feature name="MyPluginName">
<param name="android-package" value="com.phonegap.plugins.plugin.class" />
</feature>
Then it worked.
I will also add that I've experienced the same problem with IOS, I had to enter manually:
<feature name="MyPluginName">
<param name="ios-package" value="com.phonegap.plugins.plugin.class" />
</feature>
In the file config.xml under the folder YourCordovaProjectName/platforms/ios/YourCordovaProjectName
Hopefully that will be fixed in the future and the content of YourCordovaProjectName/config.xml will correctly be reflected in the config.xml files that are under each specific platforms (it used to worked correctly for Android few months ago).
For adding plugin definition in android under ProjectFolder/platforms/android/res/xml/config.xml,update the ProjectFolder/plugins/android.json
"cordova build” command will read this android.json file and update the ProjectFolder/platforms/android/res/xml/config.xml automatically with all plugins mentioned here.
Are you getting a successful deviceready event? I have gotten that error in the past when my app was silently failing for other reasons in my code causing my deviceready event to never fire. In my case the silent error was due to some javascript syntax errors in my app.initialize() code blocks.
I recently upgraded my app from Phonegap 1.6 to 2.2.
I've refactored everything (ex Plugin --> CordovaPlugin) and I'm also using the new config.xml.
The app compiles and builds, however I constantly am getting an error in logcat and an error dialog box. The dialog says [ERROR] Error initializing Cordova: Class not found.
The logcat error is:
Line 6048 : Error initializing Network Connection: Class not found
What could I be missing?
The issue happens on multiple devices.
Update
I've already changed the config.xml for the network status plugin from Network Status to NetworkStatus. It reads: <plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager"/>
I had this problem and made it go away by adding the following to the config.xml:
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager"/>
And adding this to the Manifest file:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I originally took them out because I "knew" that my app wouldn't be using any communications. I had forgotten about the emulator "communicating" with the ADK.
I'll take these 2 lines out when I convert the project over to "production" so that the app is ready for Google Play.
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:
<source-file src="src/android/NetworkManager.java" target-dir="src/org/apache/cordova/networkinformation" />
So this tells you that in platforms/android/src/org/apache/cordova/networkinformation, there should be NetworkManager.java. And right 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 copying the correct java files into the correct folders.
The following line in config.xml works for cordova 6.2 with android
<plugin name="cordova-plugin-network-information" value="org.apache.cordova.networkinformation"/>
The name should be the same as in what your plugin contains. You can find it in the your project folder at the following path plugins/name-of-the-plugin/package.json.
The value should be the package name for the plugin which can be found in the native implementation file.
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.
created activity and extended from "DroidGap" and added loadURL method from onCreate().
Added cordova-2.0.0.js and cordova-2.0.0.jar on the respective folder.
Added the jar file to the build path
Loaded the js file from the html tag
Added permissions from AndroidMainfeast.xml
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
<!DOCTYPE html>
<html>
<head>
<title>Notification Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
// Empty
}
// Show a custom alert
//
function showAlert() {
navigator.notification.alert(
'You are the winner!', // message
'Game Over', // title
'Done' // buttonName
);
}
// Beep three times
//
function playBeep() {
navigator.notification.beep(3);
}
// Vibrate for 2 seconds
//
function vibrate() {
navigator.notification.vibrate(2000);
}
</script>
</head>
<body>
<p>Show Alert</p>
<p>Play Beep</p>
<p>Vibrate</p>
</body>
</html>
Any advice? Thanks!
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.
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.
I have had this error because of a plugin that I deleted. I Added
<plugin name="Device" value="org.apache.cordova.Device"/>
to the config.xml file again and it fixed it.
My you not have following plugin:
<plugin name="Device" value="org.apache.cordova.Device"/>
You have to put that in between <plugins></plugins>.
like
<plugins>
<plugin name="Device" value="org.apache.cordova.Device"/>
</plugins>
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
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:
<source-file src="src/android/NetworkManager.java" target-dir="src/org/apache/cordova/networkinformation" />
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.
You can resolve this when using phonegap command line by doing the following:
Delete merges/android, platforms/android, plugins/android.json
run phonegap local build android
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:
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device"/>
</feature>
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher"/>
</feature>
<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification"/>
</feature>
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.
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
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!
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.
[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
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.helloCordova" version="2.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name short="Menu">Menu Digital</name>
<description>
Description
</description>
<author email="asd#gmail.com" href="www.facebook.com/usr"> Name </author>
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="http://api.phonegap.com/1.0/device" />
<feature name="http://api.phonegap.com/1.0/media" />
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<content src="index.html" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<access origin="*" />
<preference name="useBrowserHistory" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
</widget>
This could happened 'cause your cordova plugin have a different path from what IONIC expect to found:
You should correct the file plugin.xml inside your plugin source folder:
<config-file target="app/src/main/res/xml/config.xml" parent="/*">
should be:
<config-file target="res/xml/config.xml" parent="/*">
If you try to searching that error inside the Android Studio Logcat usually you find something like:
io.ionic.starter E/chromium: [ERROR:service_manager.cc(156)] Connection InterfaceProviderSpec prevented service: content_renderer from binding interface: blink::mojom::BudgetService exposed by: content_browser
2019-02-22 13:40:06.144 30230-30258/com.android.webview:sandboxed_process0 E/chromium: [ERROR:BudgetService.cpp(167)] Unable to connect to the Mojo BudgetService.