简体   繁体   English

将库与其链接时未定义 React native nativemodules

[英]React native nativemodules not defined when linking a library with it

NPM version : 10 React-Native Library : react-native-get-music-files (Using android) Installation : npm i --save react-native-get-music-files rnpm link NPM 版本:10 React-Native 库:react-native-get-music-files(使用 android)安装:npm i --save react-native-get-music-files rnpm 链接

Things I Have Already Tried : rnpm link react-native-get-music-files react-native link npm install react-native run-android REINSTALLING MAKING A NEW PROJECT我已经尝试过的事情: rnpm link react-native-get-music-files react-native link npm install react-native run-android 重新安装制作新项目

Details : Its documentation says add import com.reactlibrary.RNReatNativeGetMusicFilesPackage;详细信息:它的文档说添加 import com.reactlibrary.RNReatNativeGetMusicFilesPackage; but when automatically linking , it adds com.cinder72.musicfiles.RNReactNativeGetMusicFilesPackage;但是当自动链接时,它会添加 com.cinder72.musicfiles.RNReactNativeGetMusicFilesPackage; Manually it is showing com.reactlibrary.RNReatN... is not found.手动显示 com.reactlibrary.RNReatN... 未找到。 Automatically everything is working fine.自动一切正常。

Error : In the react-native-get-music-files/index.js错误:在 react-native-get-music-files/index.js

import { NativeModules, Platform } from 'react-native';

const { RNReactNativeGetMusicFiles } = NativeModules;

const MusicFiles = {
    getAll(options){

        return new Promise((resolve, reject) => {

            if(Platform.OS === "android"){
                RNReactNativeGetMusicFiles.getAll(options,(tracks) => {
                    resolve(tracks);
                },(error) => {
                    resolve(error);
                });
            }else{
                RNReactNativeGetMusicFiles.getAll(options, (tracks) => {
                    if(tracks.length > 0){
                        resolve(tracks);
                    }else{
                        resolve("Error, you don't have any tracks");
                    }
                });   
            }

        });

    }
}
export default MusicFiles;

It says RNReactNativeGetMusic files is undefined.它说 RNReactNativeGetMusic 文件未定义。 I tried console log NATIVEMODULES and it shows nothing as RNReactNativeGetMusic or anything similar.我尝试了控制台日志 NATIVEMODULES 并且它没有显示任何 RNReactNativeGetMusic 或任何类似的东西。

maybe the docs hasn't been updated for V2.也许文档尚未针对 V2 更新。

import com.cinder92.musicfiles.RNReactNativeGetMusicFilesPackage;

the above should work fine.以上应该可以正常工作。

You're probably following the linking instructions on the package's npm page, which are outdated.您可能正在遵循包的 npm 页面上的链接说明,这些说明已过时。 Follow the instructions on this github repo instead.请按照此github repo上的说明进行操作。

Follow the steps for manual installation and don't forget to clean the code you previously added to link.按照手动安装的步骤操作,不要忘记清理您之前添加到链接的代码。

Then import it like this,然后像这样导入,

import MusicFiles from 'react-native-get-music-files';

Hope this helps you and feel free to ask any questions.希望这对您有所帮助,并随时提出任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM