React-native 文件选择器react-native-file-selector的使用

最后是错误解决办法,本文只说明安装方法,具体使用查看https://github.com/prscX/react-native-file-selector

1、npm install react-native-file-selector --save

2、最好不要自动 link     --react-native link react-native-file-selector

手动link步骤

A、在android\settings.gradle添加

include ':react-native-file-selector'

project(':react-native-file-selector').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-file-selector/android')

B、在android\build.gradle添加

maven { url "http://dl.bintray.com/lukaville/maven" }

C、在android\app\build.gradle中添加

implementation project(':react-native-file-selector')

D、在MainApplication.java中引用jar包

import ui.fileselector.RNFileSelectorPackage;

在getPackages()中使用

new RNFileSelectorPackage(),

3、添加选择文件主题颜色,可以自定义

增加文件android/app/src/main/res/values/colors.xml

4、添加权限 android\app\src\main\AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

记一下的原因是安装依赖,自动link后出现各种报错,和之前引用的依赖冲突,或者打包报错

Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.

> java.io.IOException: Can't write [D:\Work\drp_admin_app\android\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\Admin\.gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.0.aar\b6c4178a4c08c4dfa3ddaf1b25f9d379\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/design/widget/CoordinatorLayout$Behavior.class]))

我的解决办法

在android/app/build.gradle中加入

还有一些其他的我尝试了没有用,也记一下

或者是implementation  'com.android.support:multidex:1.0.3'

这些都是老的sdk版本

发布了7 篇原创文章 · 获赞 2 · 访问量 1万+
展开阅读全文

react-native访问安卓原生VideoView组件报错,错误如下所示

08-01

react-native访问安卓原生VideoView组件报错,错误如下所示,请问什么原因?? ``` 08-01 12:54:24.034 4321-4321/com.react_native_video I/MediaPlayer: constructor 08-01 12:54:24.038 4321-4321/com.react_native_video I/MediaPlayer: setDataSource:http://ohe65w0xx.bkt.clouddn.com/test3.mp4 08-01 12:54:24.038 4321-4321/com.react_native_video W/MediaPlayer: Couldn't open http://ohe65w0xx.bkt.clouddn.com/test3.mp4: java.io.FileNotFoundException: No content provider: http://ohe65w0xx.bkt.clouddn.com/test3.mp4 08-01 12:54:24.038 4321-4321/com.react_native_video I/MediaPlayer: setDataSource:http://ohe65w0xx.bkt.clouddn.com/test3.mp4 08-01 12:54:24.039 4321-4321/com.react_native_video V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService@63789e0): Cookies: null 08-01 12:54:24.043 4321-4351/com.react_native_video V/MediaHTTPService: makeHTTPConnection: CookieManager created: java.net.CookieManager@4e82499 makeHTTP ``` 我的环境信息如下: ``` npmPackages: react: 16.4.1 => 16.4.1 react-native: 0.56.0 => 0.56.0 npmGlobalPackages: react-native-cli: 2.0.1 ``` 并且,我的视频地址 http://ohe65w0xx.bkt.clouddn.com/test3.mp4 也是可以访问到的, 下面是我的原生代码 ``` package com.react_native_video; import android.net.Uri; import javax.annotation.Nullable; import android.os.Build; import android.widget.VideoView; import com.facebook.common.logging.FLog; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMapKeySetIterator; import com.facebook.react.uimanager.SimpleViewManager; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.annotations.ReactProp; import java.io.File; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; public class VideoViewManager extends SimpleViewManager<VideoView> { @Override public String getName() {// 组件名称 return "VideoView"; } @Override protected VideoView createViewInstance(ThemedReactContext reactContext) { VideoView video = new VideoView(reactContext); return video; } @Override public void onDropViewInstance(VideoView view) {//对象销毁时 super.onDropViewInstance(view); view.stopPlayback();//停止播放 } // @ReactProp(name="source") // public void setSource(VideoView videoView, @Nullable String source) { // if (source!= null) { // videoView.setVideoURI(Uri.parse(source)); // videoView.start(); // } // } @ReactProp(name="source") public void setSource(VideoView videoView, @Nullable ReadableMap source) { if (source!= null) { if (source.hasKey("url")) { String url = source.getString("url"); System.out.println("========================" + url); FLog.e(VideoViewManager.class, "url=" + url); HashMap<String, String> headerMap = new HashMap<>(); if (source.hasKey("headers")) { ReadableMap headers =source.getMap("headers"); ReadableMapKeySetIterator iter = headers.keySetIterator(); while(iter.hasNextKey()) { String key = iter.nextKey(); String value = headers.getString(key); FLog.e(VideoViewManager.class, key+"=" + value); System.out.println("========================"); System.out.println(key+"=" + value); System.out.println("========================"); headerMap.put(key, value); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // videoView.setVideoURI(Uri.parse(url)); // Uri.fromFile(new File(url))) System.out.println("========+++++================"); System.out.println(Uri.fromFile(new File(url))); System.out.println(Uri.parse(url)); System.out.println("========+++==================="); videoView.setVideoURI(Uri.parse(url), headerMap); } else { try { // Uri.fromFile(new File(your image path)) Method setVideoURIMethod = videoView.getClass() .getMethod("setVideoURI", Uri.class, Map.class); setVideoURIMethod.invoke(videoView, Uri.parse(url), headerMap); } catch (Exception e) { e.printStackTrace(); } } System.out.println("=============videoView==========="); System.out.println(videoView); videoView.start(); //设置获取焦点 videoView.setFocusable(true); } } } } ``` 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览