cordova-android icon indicating copy to clipboard operation
cordova-android copied to clipboard

Removing/re-adding Android platform results in "exec() call to unknown plugin" error at runtime

Open dpa99c opened this issue 5 years ago • 3 comments

Bug Report

Problem

I had an issue reported against a plugin of mine (https://github.com/dpa99c/cordova-plugin-hello-c/issues/10) and from the description it seemed like cordova-plugin-ionic-webview was the cause, but after some testing I found this is a red herring and the issue can be recreated without that plugin in a simple test case, so it seems that it's directly related to cordova-android.

What is expected to happen?

Removing/re-adding the Android platform does not cause an issue on subsequently building and running the app project.

What does actually happen?

Removing/re-adding the Android platform causes an issue on subsequently building and running the app project.

Information

cordova-plugin-hello-c is a tutorial plugin that illustrates how to wrap a C/C++ library in a cross-platform Cordova plugin.

cordova-plugin-hello-c-test is a simple test harness Cordova project to validate/demonstrate the above plugin. It includes 2 plugins in its config.xml: cordova-plugin-hello-c and cordova-plugin-whitelist.

Command or Code

To reproduce the issue:

git clone https://github.com/dpa99c/cordova-plugin-hello-c-test && cd cordova-plugin-hello-c-test
cordova platform add [email protected]
cordova run android

=> Observe plugin output appears

=> In platforms/android/app/src/main/res/xml/config.xml there is 1 <feature> element for cordova-plugin-hello-c:

<feature name="HelloCPlugin">
    <param name="android-package" value="com.example.HelloCPlugin" />
</feature>

Then remove/re-add Android platform:

cordova platform rm android --nosave && cordova platform add android --nosave
cordova run android

=> Observe plugin output does not appear

=> In platforms/android/app/src/main/res/xml/config.xml there is now 1 <feature> element for cordova-plugin-whitelist, i.e. none for cordova-plugin-hello-c:

<feature name="Whitelist">
    <param name="android-package" value="org.apache.cordova.whitelist.WhitelistPlugin" />
    <param name="onload" value="true" />
</feature>

=> The Android logcat indicates that on each call to the plugin, the plugin class could not be found by Cordova:

2019-02-26 17:47:49.429 11562-11648/io.cordova.hellocordova D/PluginManager: exec() call to unknown plugin: HelloCPlugin

Remove and re-add the plugin:

cordova plugin rm cordova-plugin-hello-c --nosave && cordova plugin add cordova-plugin-hello-c --nosave
cordova run android

=> Observe plugin is still not found:

2019-02-26 20:15:39.300 11093-11173/io.cordova.hellocordova D/PluginManager: exec() call to unknown plugin: HelloCPlugin

I can also produce the same result with [email protected] so it's not something that has been introduced in [email protected]

I'm not sure if this is related to https://github.com/apache/cordova-android/issues/636.

Environment, Platform, Device

cordova-android@7, cordova-android@8

Version information

[email protected], [email protected], [email protected] Windows 10 64-bit 1809 Android Studio 3.2.1

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

dpa99c avatar Feb 26 '19 20:02 dpa99c

@dpa99c First of all I would like to thank your plugin example, it is being the basis for my plugin. PS: There's a bug in the iOS 64bits compiler, when I can, I'll post an ISSUE for you.

I managed to get around this reported problem by making some modifications: (I believe the main one is the lack of a release of the cordova-android)

config.xml

<platform name="android">
        <allow-intent href="market:*" />
        <preference name="loadUrlTimeoutValue" value="700000" />
        <preference name="android-minSdkVersion" value="21" />
        <preference name="android-targetSdkVersion" value="26" />
</platform>

package.json (Note git master repository for Cordova-android)

"dependencies": {
    "cordova-android": "git+https://github.com/apache/cordova-android.git",
    "cordova-plugin-hello-c": "file:../cordova-plugin-hello-c-master"
  }

After prepare and building Android build, I manually added it to the AndroidManifest.xml file:

<manifest>
    ...
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
</manifest>

Result: Screen Shot 2019-06-21 at 20 25 51

luisdemarchi avatar Jun 21 '19 23:06 luisdemarchi

@dpa99c I had similar problem with my plugin, fixed by changing

<config-file target="app/src/main/res/xml/config.xml" parent="/*">

to <config-file target="res/xml/config.xml" parent="/*">

Similarly if you need to modify AndroidManifest, or other platform resource

ebhsgit avatar Jul 01 '19 13:07 ebhsgit

@dpa99c was this fixed and related to the plugin's config-file target? If this was resolved, can we close this ticket?

erisu avatar Jul 21 '21 09:07 erisu