Android Ionic Cordova - 错误:无法获得已安装模块的绝对路径

时间:2017-08-03 04:53:50

标签: android cordova ionic-framework ionic2 cordova-plugins

我创建了一个自定义插件,我尝试通过cmd添加它以获得以下错误

> cordova plugin add C:\r\work\custom_plugins\cordova-plugin-webrtc-video-call -
-save
x Running command - failed!

[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.

[ERROR] An error occurred while running cordova plugin add
        C:\r\work\custom_plugins\cordova-plugin-webrtc-video-call --s... (exit
        code 1):

        Error: Failed to get absolute path to installed module


C:\r\work>

config.xml中

<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-webrtc-video-call" version="1.0.1" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
    <name>WebrtcVideoCall</name>
    <js-module name="WebrtcVideoCall" src="www/WebrtcVideoCall.js">
        <clobbers target="cordova.plugins.WebrtcVideoCall" />
    </js-module>
    <platform name="android">
        <config-file parent="/*" target="res/xml/config.xml">
            <feature name="WebrtcVideoCall">
                <param name="android-package" value="com.hsc.plugin.webrtc.WebrtcVideoCall" />
            </feature>
        </config-file>
        <config-file parent="/manifest/application" target="AndroidManifest.xml">
            <activity
                android:name="com.hsc.plugin.webrtc.CallActivity"
                android:screenOrientation="fullUser"
                android:configChanges="orientation|screenSize"
                android:exported="true"
                android:theme="@style/CallActivityTheme">
                <intent-filter>
                    <action android:name="com.hsc.plugin.ACTION_CALL" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>

        </config-file>
        <config-file target="AndroidManifest.xml" parent="/manifest">
            <uses-feature android:name="android.hardware.camera" required="false" />
            <uses-feature android:name="android.hardware.camera.autofocus" required="false" />
            <uses-feature
                android:glEsVersion="0x00020000"
                android:required="false"
            />
            <uses-permission android:name="android.permission.CAMERA"/>
            <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
            <uses-permission android:name="android.permission.RECORD_AUDIO"/>
            <uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
        </config-file>
        <framework src="src/android/Webrtc.gradle" custom="true" type="gradleReference"/>

        <source-file src="src/android/AppRTCAudioManager.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/AppRTCClient.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/AppRTCProximitySensor.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/CallActivity.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/CallFragment.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/CaptureQualityController.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/CpuMonitor.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/DirectRTCClient.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/HudFragment.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/PeerConnectionClient.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/PercentFrameLayout.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/RoomParametersFetcher.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/TCPChannelClient.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/UnhandledExceptionHandler.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/WebrtcVideoCall.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/WebSocketChannelClient.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/WebSocketRTCClient.java" target-dir="src/com/hsc/plugin/webrtc" />
        <source-file src="src/android/util/AppRTCUtils.java" target-dir="src/com/hsc/plugin/webrtc/util" />
        <source-file src="src/android/util/AsyncHttpURLConnection.java" target-dir="src/com/hsc/plugin/webrtc/util" />

        <source-file src="src/android/libs/autobanh.jar" target-dir="libs" framework="true" />
        <source-file src="src/android/libs/libjingle-peerconnection-sources.jar" target-dir="libs" framework="true" />
        <source-file src="src/android/libs/libjingle-peerconnection.jar" target-dir="libs" framework="true" />
        <source-file src="src/android/libs/armeabi-v7a/libjingle_peerconnection_so.so" target-dir="libs/armeabi-v7a" 
                     framework="true" />

        <!--  drawable src/android/resources -->
        <resource-file src="src/android/res/drawable-hdpi/disconnect.png" target="res/drawable-hdpi/disconnect.png" />
        <resource-file src="src/android/res/drawable-mdpi/disconnect.png" target="res/drawable-mdpi/disconnect.png" />
        <resource-file src="src/android/res/drawable-xhdpi/disconnect.png" target="res/drawable-xhdpi/disconnect.png" />
        <resource-file src="src/android/res/drawable-ldpi/disconnect.png" target="res/drawable-ldpi/disconnect.png" />
        <resource-file src="src/android/res/layout/activity_call.xml" target="res/layout/activity_call.xml" />
        <resource-file src="src/android/res/layout/fragment_call.xml" target="res/layout/fragment_call.xml" />
        <resource-file src="src/android/res/layout/fragment_hud.xml" target="res/layout/fragment_hud.xml" />
        <resource-file src="src/android/res/values/WebrtcPluginStrings.xml" target="res/values/WebrtcPluginStrings.xml" />
        <resource-file src="src/android/res/values/WebrtcPluginStyles.xml" target="res/values/WebrtcPluginStyles.xml" />

        <resource-file src="src/android/res/drawable-hdpi/ic_action_full_screen.png" target="res/drawable-hdpi/iic_action_full_screen.png" />
        <resource-file src="src/android/res/drawable-mdpi/ic_action_full_screen.png" target="res/drawable-mdpi/ic_action_full_screen.png" />
        <resource-file src="src/android/res/drawable-xhdpi/ic_action_full_screen.png" target="res/drawable-xhdpi/ic_action_full_screen.png" />
        <resource-file src="src/android/res/drawable-ldpi/ic_action_full_screen.png" target="res/drawable-ldpi/ic_action_full_screen.png" />

        <resource-file src="src/android/res/drawable-hdpi/ic_action_return_from_full_screen.png" target="res/drawable-hdpi/ic_action_return_from_full_screen.png" />
        <resource-file src="src/android/res/drawable-mdpi/ic_action_return_from_full_screen.png" target="res/drawable-mdpi/ic_action_return_from_full_screen.png" />
        <resource-file src="src/android/res/drawable-xhdpi/ic_action_return_from_full_screen.png" target="res/drawable-xhdpi/ic_action_return_from_full_screen.png" />
        <resource-file src="src/android/res/drawable-ldpi/ic_action_return_from_full_screen.png" target="res/drawable-ldpi/ic_action_return_from_full_screen.png" />



    </platform>
</plugin>

我已尝试使用--nofetch选项,我使用的是cordova v7.0.1

3 个答案:

答案 0 :(得分:6)

确保插件中没有要安装的node_modules的文件/符号链接。如果存在,请将其删除并重新运行命令:

cordova plugin add C:\r\work\custom_plugins\cordova-plugin-webrtc-video-call --nofetch

希望有所帮助。 :)

答案 1 :(得分:1)

SO上有几个关于这个问题的帖子。

看来cordova在您用于安装插件的本地路径和config.xml中有关该插件的信息之间丢失。

有些人似乎通过首先使用--force标志删除插件然后重新安装它来修复它:

cordova plugin remove cordova-plugin-webrtc-video-call --force
cordova plugin add C:\r\work\custom_plugins\cordova-plugin-webrtc-video-call

( - 在cordova 7中保存似乎没用,因为插件没有添加到config.xml中)

当我遇到问题时,我通过清理项目中的所有插件并重新添加插件来修复它:

  1. 删除插件文件夹
  2. 删除平台/ android文件夹
  3. 删除config.xml中的所有插件引用
  4. 将所有插件重新添加到项目中
  5. ps:插件中的xml文件名为plugin.xml而不是config.xml,对吗?

答案 2 :(得分:0)

--nofetch选项是解决此问题的方法:https://stackoverflow.com/a/46010348/327862

但是,自Cordova 8.0.0起,--nofetch选项已被删除:https://issues.apache.org/jira/browse/CB-13055

如果您已经安装了Cordova 8.x.x并想使用--nofetch选项,那么您需要将cordova降级到7.1.0。

运行以下命令将Cordova降级为7.1.0:

npm install -g cordova@7.1.0

如果上述命令不起作用,请先尝试卸载cordova,然后再安装cordova版本7.1.0:

npm uninstall -g cordova
npm install -g cordova@7.1.0

然后,检查Cordova版本以确认它是否降级:

cordova --version