android - react-native-video Undefined is not an object (evaluating '_reactNative ...) -
hi trying use module react-native-video (or video player) video play on app, running error:
undefined not object (evaluating '_reactnative.nativemodules.uimanager.rctvideo.constants') ![1]: https://image.ibb.co/nft2cq/screen_shot_2017_08_23_at_3_47_18_am.png "full error image"
in index.android.js:
import react, { component } 'react'; import { appregistry, stylesheet, text, view } 'react-native'; import video 'react-native-video'; export default class demodigpocv3 extends component { constructor(props){ super(props); } render() { return ( <view style={styles.container}> <text>hello world</text> <video source={require('./videotrack.mp4')} repeat={false} /> </view> ); } } appregistry.registercomponent('demodigpocv3', () => demodigpocv3);
i have ran:
react-native link react-native-video
if rerun it:
rnpm-install info android module react-native-video linked rnpm-install info ios module react-native-video linked
as docs (https://github.com/react-native-community/react-native-video) suggested, in android/settings.gradle:
>
*** edit, have replaced following:
rootproject.name = 'demodigpocv3' include ':react-native-video' project(':react-native-video-exoplayer').projectdir = new >file(rootproject.projectdir, '../node_modules/react-native-video/android->exoplayer') include ':app'
**** this:
project(':react-native-video').projectdir = new >file(rootproject.projectdir, '../node_modules/react-native-video/android')
for file android/app/build.gradle :
apply plugin: "com.android.application" import com.android.build.outputfile /** * react.gradle file registers task each build variant (e.g. bundledebugjsandassets * , bundlereleasejsandassets). * these call `react-native bundle` correct arguments during android build * cycle. default, bundledebugjsandassets skipped, in debug/dev mode prefer load * bundle directly development server. below can see possible configurations * , defaults. if decide add configuration block, make sure add before * `apply from: "../../node_modules/react-native/react.gradle"` line. * * project.ext.react = [ * // name of generated asset file containing js bundle * bundleassetname: "index.android.bundle", * * // entry file bundle generation * entryfile: "index.android.js", * * // whether bundle js , assets in debug mode * bundleindebug: false, * * // whether bundle js , assets in release mode * bundleinrelease: true, * * // whether bundle js , assets in build variant (if configured). * // see http://tools.android.com/tech-docs/new-build-system/user-guide#toc-build-variants * // configuration property can in following formats * // 'bundlein${productflavor}${buildtype}' * // 'bundlein${buildtype}' * // bundleinfreedebug: true, * // bundleinpaidrelease: true, * // bundleinbeta: true, * * // whether disable dev mode in custom build variants (by default disabled in release) * // example: disable dev mode in staging build type (if configured) * devdisabledinstaging: true, * // configuration property can in following formats * // 'devdisabledin${productflavor}${buildtype}' * // 'devdisabledin${buildtype}' * * // root of project, i.e. "package.json" lives * root: "../../", * * // put js bundle asset in debug mode * jsbundledirdebug: "$builddir/intermediates/assets/debug", * * // put js bundle asset in release mode * jsbundledirrelease: "$builddir/intermediates/assets/release", * * // put drawable resources / react native assets, e.g. ones use via * // require('./image.png')), in debug mode * resourcesdirdebug: "$builddir/intermediates/res/merged/debug", * * // put drawable resources / react native assets, e.g. ones use via * // require('./image.png')), in release mode * resourcesdirrelease: "$builddir/intermediates/res/merged/release", * * // default gradle tasks skipped if none of js files or assets change; means * // don't @ files in android/ or ios/ determine whether tasks * // date; if have other folders want ignore performance reasons (gradle * // indexes entire tree), add them here. alternatively, if have js files in android/ * // example, might want remove here. * inputexcludes: ["android/**", "ios/**"], * * // override node gets called , additional arguments * nodeexecutableandargs: ["node"], * * // supply additional arguments packager * extrapackagerargs: [] * ] */ apply from: "../../node_modules/react-native/react.gradle" /** * set true create 2 separate apks instead of one: * - apk works on arm devices * - apk works on x86 devices * advantage size of apk reduced 4mb. * upload apks play store , people download * correct 1 based on cpu architecture of device. */ def enableseparatebuildpercpuarchitecture = false /** * run proguard shrink java bytecode in release builds. */ def enableproguardinreleasebuilds = false android { compilesdkversion 23 buildtoolsversion "23.0.1" defaultconfig { applicationid "com.demodigpocv3" minsdkversion 16 targetsdkversion 22 versioncode 1 versionname "1.0" ndk { abifilters "armeabi-v7a", "x86" } } signingconfigs { release { storefile file(myapp_release_store_file) storepassword myapp_release_store_password keyalias myapp_release_key_alias keypassword myapp_release_key_password } } splits { abi { reset() enable enableseparatebuildpercpuarchitecture universalapk false // if true, generate universal apk include "armeabi-v7a", "x86" } } buildtypes { release { minifyenabled enableproguardinreleasebuilds proguardfiles getdefaultproguardfile("proguard-android.txt"), "proguard-rules.pro" signingconfig signingconfigs.release } } // applicationvariants e.g. debug, release applicationvariants.all { variant -> variant.outputs.each { output -> // each separate apk per architecture, set unique version code described here: // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits def versioncodes = ["armeabi-v7a":1, "x86":2] def abi = output.getfilter(outputfile.abi) if (abi != null) { // null universal-debug, universal-release variants output.versioncodeoverride = versioncodes.get(abi) * 1048576 + defaultconfig.versioncode } } } } dependencies { compile project(':react-native-video') compile filetree(dir: "libs", include: ["*.jar"]) compile "com.android.support:appcompat-v7:23.0.1" compile "com.facebook.react:react-native:+" // node_modules compile project(':react-native-video') } // run once able run application buck // puts compile dependencies folder libs buck use task copydownloadabledepstolibs(type: copy) { configurations.compile 'libs' }
in mainapplication.java :
package com.demodigpocv3; import com.brentvatne.react.reactvideopackage; import android.app.application; import com.facebook.react.reactapplication; import com.brentvatne.react.reactvideopackage; import com.facebook.react.reactnativehost; import com.facebook.react.reactpackage; import com.facebook.react.shell.mainreactpackage; import com.facebook.soloader.soloader; import java.util.arrays; import java.util.list; public class mainapplication extends application implements reactapplication { private final reactnativehost mreactnativehost = new reactnativehost(this) { @override public boolean getusedevelopersupport() { return buildconfig.debug; } }; @override public reactnativehost getreactnativehost() { return mreactnativehost; } @override public void oncreate() { super.oncreate(); soloader.init(this, /* native exopackage */ false); } @override protected list<reactpackage> getpackages() { return arrays.aslist( new mainreactpackage(), new reactvideopackage() ); } } have been looking solution couple days, , appreciate get. have ran steps in docs , still getting error. here similar stack overflow have found (https://stackoverflow.com/questions/43130134/react-native-video-android-undefined-is-not-an-object-evaluating-nativemoduel), accepted answer is: "fixed adding reactvideopackage when creating reactinstancemanager mreactinstancemanager = reactinstancemanager.builder() .setapplication(getapplication()) .setbundleassetname("index.android.bundle") .setjsmainmodulename("index.android") .addpackage(new mainreactpackage()) .addpackage(new reactvideopackage())//<-- line fixed .setusedevelopersupport(buildconfig.debug) .setinitiallifecyclestate(lifecyclestate.resumed) .build(); "
where add this? tried adding mainactivity.java file (like below) same error still there:
package com.demodigpocv3; import com.facebook.react.reactactivity; public class mainactivity extends reactactivity { /** * returns name of main component registered javascript. * used schedule rendering of component. */ mreactinstancemanager = reactinstancemanager.builder() .setapplication(getapplication()) .setbundleassetname("index.android.bundle") .setjsmainmodulename("index.android") .addpackage(new mainreactpackage()) .addpackage(new reactvideopackage())//<-- line fixed .setusedevelopersupport(buildconfig.debug) .setinitiallifecyclestate(lifecyclestate.resumed) .build(); @override protected string getmaincomponentname() { return "demodigpocv3"; } }
i love solutions, ideally non java solutions (as don't know java) , beginner friendly answers/terminology preferred.
in "setting.gradle" change
project(':react-native-video-exoplayer').projectdir = new file(rootproject.projectdir, '../node_modules/react-native-video/android-exoplayer')
to
project(':react-native-video').projectdir = new file(rootproject.projectdir, '../node_modules/react-native-video/android')
wiki
Comments
Post a Comment