1.android开发可实现功能的原生代码(能执行不会程序崩溃,不然后期在wex5中的h5页面中js调用原生代码的时候会一直在jni_onload程序无反应)
2.配置插件文件建立如下图的目录
libs文件中放插件需要的依赖包等,res里面存放的是android的原生代码中需要的资源文件,www文件下的js文件是cordova插件中需要通过js调用的CordovaPlugin(具体开发步骤可参考wex5的官方文档cordova android插件开发),plugin-ex.xml和plugin.js.xdoc是wex5中cordova插件的说明文档(所有xml文件必须以<?xml version="1.0" encoding="UTF-8"?>开通并且不能在前面加入空格或者换行),plugin.xml是插件中最为重要的配置文档具体代码如下
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.justep.cordova.plugin.pusher"
version="5.3.6">
//id为js中调用的id名字 version是xml的编译版本
<engines> <engine name="cordova" version=">=3.3.0" /> </engines> <name>pusher</name> <description>pusher_plugin</description> <js-module src="www/pusher.js" name="pusher"><!--pusher.js的地址路径--> <clobbers target="navigator.pusher" /> </js-module> <platform name="android"><!--android配置--> <config-file target="res/xml/config.xml" parent="/*"><!--config.xml中添加插件名字及包路径对应到具体的cordovaplugin类--> <feature name="pusher"> <param name="android-package" value="com.justep.cordova.plugin.pusher.pusher" /> </feature> </config-file> <config-file target="AndroidManifest.xml" parent="/manifest"> <uses-permission android:name="android.permission.CAMERA"> </uses-permission> <uses-permission android:name="android.permission.RECORD_AUDIO"> </uses-permission> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"> </uses-permission> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> </config-file> <!--在wex5的项目AndroidManifest.xml添加配置请求-->
<config-file target="AndroidManifest.xml" parent="/manifest/application"> <activity android:name="com.justep.cordova.plugin.pusher.DemoActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation|screenSize" android:allowBackup="true" android:supportsRtl="true" android:windowSoftInputMode="stateHidden|adjustPan" android:theme="@style/Theme.AppCompat.Light.NoActionBar"> </activity> <activity android:name="com.justep.cordova.plugin.pusher.LiveCameraActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTask" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/> </config-file>
<!--在wex5的项目AndroidManifest.xml注册插件需要的activity-->
<!--string配置--> <config-file target="res/values/strings.xml" parent="/resources"><string name="max_bitrate">Max Bitrate</string><string name="best_bitrate">Best Bitrate</string><string name="quit_live">Long time reconnect failed, please exit</string><string name="network_message">The current network status is very poor, continue the live broadcast?</string><string name="camera_success">Camera open successfully</string><string name="camera_fail">Camera open failed</string><string name="error_message">-22 error</string><string name="mute_off">Mute close</string><string name="mute_on">Mute on</string><string name="mirror_off">Mirror off</string><string name="mirror_on">Mirror on</string><string name="advance_setting">美颜等级</string><string name="watermark_position">position (topright 1, topleft 2, bottomright 3, bottomleft 4):</string><string name="fps_hint">The fps must be between 0~30</string><string name="watermard_url">水印路径:</string><string name="fps">Fps</string><string name="front_camera_mirror">前置摄像</string><string name="landscape">水平</string><string name="portrait_normal">垂直</string><string name="ready_push">开始直撿</string><string name="rtmp_url">请输兿url</string><string name="beauty_level">Beauty Level</string><string name="toggle_switch_flash_on">Flash on</string><string name="toggle_switch_flash_off">Flash off</string><string name="app_camera">Camera switch</string><string name="live_push">Start pushing</string><string name="live_stop">Stop pushing</string><string name="toggle_switch_beauty_on">Beauty on</string><string name="toggle_switch_beauty_off">Beauty off</string><string name="min_bitrate">Min bitrate</string><string name="min_rate_value">300</string><string name="initial_bitrate">Initial bitrate</string><string name="VIDEO_CAPTURE_FPS">Video capture fps:</string><string name="AUDIO_ENCODER_FPS">Audio encoder fps:</string><string name="VIDEO_ENCODER_FPS">Video encoder fps:</string><string name="OUTPUT_BITRATE">Output bitrate:</string><string name="AV_OUTPUT_DIFF">The difference between audio pts and video pts:</string><string name="AUDIO_OUTPUT_FPS">Output fps of audio:</string><string name="VIDEO_OUTPUT_FPS">Output fps of video:</string><string name="STREAM_PUBLISH_TIME">Time costs of stream published:</string><string name="STREAM_SERVER_IP">Stream server IP:</string><string name="VIDEO_DELAY_DURATION">Video delay duration:</string><string name="AUDIO_DELAY_DURATION">Audio delay duration:</string><string name="VIDEO_CACHE_FRAME_CNT">Number of video cache frame:</string><string name="AUDIO_CACHE_FRAME_CNT">Number of audio cache frame:</string><string name="VIDEO_CACHE_BYTE_SIZE">Size of video cache:</string><string name="AUDIO_CACHE_BYTE_SIZE">Size of audio cache:</string><string name="VIDEO_FRAME_DISCARD_CNT">Number of video frame dropped:</string><string name="AUDIO_FRAME_DISCARD_CNT">Number of audio frame dropped:</string><string name="CUR_VIDEO_BUEATY_DURATION">Time costs of beauty:</string><string name="CUR_VIDEO_ENCODER_DURATION">Time costs of video encoding:</string><string name="cur_video_encode_bitrate">Current video encoding bitrate:</string><string name="illegal_output_resolution">The output resolution is illegal</string><string name="VIDEO_OUTPUT_FRAME_COUNT">Number of video output frame:</string><string name="VIDEO_DATA">Size of video output frame:</string><string name="VIDEO_BUFFER_COUNT">Number of video buffer frame:</string><string name="VIDEO_DROPPED_FRAMECOUNT">Number of video dropped frame:</string><string name="AUDIO_DATA">Size of audio output:</string><string name="reconnect_fail">Reconnection failed</string><string name="dialog_title">Error tips</string><string name="ok">OK</string><string name="no_camera_permission">Camera usage is not permitted, please open first</string><string name="no_record_audio_permission">Audio is not permitted to record, please open first</string></config-file>
<!--因为wex5生成的项目已经包含string.xml文件,直接复制会导致不能成功生成apk,只能将字符串全面写入项目中存在的strings文件中。注:
如果是写入的时候目标文件必须存在,如果是复制文件的话不能在目标文件夹中存在同名文件-->
<framework src="src/android/build.gradle" custom="true" type="gradleReference"/><source-file src="src/android/libs/AlivcPlayer-3.2.0.aar" target-dir="libs/"/> <source-file src="src/android/libs/live-pusher-3.2.0.aar" target-dir="libs/"/> <!--添加项目依赖 同时还需要配置一个gradle文件 gradle文件源码后面贴出--> <source-file src="src/android/pusher.java" target-dir="src/com/justep/cordova/plugin/pusher" /><source-file src="src/android/AdvancedSettingDialog.java" target-dir="src/com/justep/cordova/plugin/pusher" /><source-file src="src/android/DataStatistics.java" target-dir="src/com/justep/cordova/plugin/pusher" /><source-file src="src/android/DemoActivity.java" target-dir="src/com/justep/cordova/plugin/pusher" /><source-file src="src/android/LiveCameraActivity.java" target-dir="src/com/justep/cordova/plugin/pusher" /><source-file src="src/android/ToastUtils.java" target-dir="src/com/justep/cordova/plugin/pusher" /><source-file src="src/android/res/drawable/ic_launcher_background.xml" target-dir="res/drawable"/><source-file src="src/android/res/drawable/ic_launcher_foreground.xml" target-dir="res/drawable"/><source-file src="src/android/res/mipmap/ic_launcher.xml" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/ic_launcher_round.xml" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/beauty.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/beauty1.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/bubble.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/fash_open.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/finish.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/flash_off.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/microphone_open.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/microphone_off.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/off.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/pause.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/satrt.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/set_up.png" target-dir="res/mipmap"/><source-file src="src/android/res/mipmap/xuanzhuan.png" target-dir="res/mipmap"/><source-file src="src/android/res/layout/activity_live_camera.xml" target-dir="res/layout"/><source-file src="src/android/res/layout/demo_activity.xml" target-dir="res/layout"/><source-file src="src/android/res/layout/layout_advance_setting.xml" target-dir="res/layout"/><source-file src="src/android/res/layout/performance_log.xml" target-dir="res/layout"/><source-file src="src/android/res/values/arrays.xml" target-dir="res/values"/><source-file src="src/android/res/values/colors.xml" target-dir="res/values"/><source-file src="src/android/res/values/styles.xml" target-dir="res/values"/> <!--将需要的资源文件复制到相应的路径文件夹下--> </platform> </plugin>
gradle文件源码:
/*
* Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
*
* @APPPLANT_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPPLANT_LICENSE_HEADER_END@
*/
//两种文件依赖库方式都加上
repositories { jcenter() flatDir { dirs 'libs' }}repositories { mavenCentral() flatDir { dirs 'libs' }}dependencies { compile(name: 'AlivcPlayer-3.2.0', ext: 'aar') compile(name: 'live-pusher-3.2.0', ext: 'aar')}