@react-native-community/async-storage在Android上的手动link问题

PS C:\Users\linjin\Desktop\RN_APP> react-native link @react-native-community/async-storage
error Something went wrong while linking. Error: Expected "/* Begin ", "/* End ", "\"", or [A-Za-z0-9_.] but "<" found.
Please file an issue here: https://github.com/react-native-community/react-native-cli/issues
error Expected "/* Begin ", "/* End ", "\"", or [A-Za-z0-9_.] but "<" found.

 

解决方案

1.在项目结构android/settings.gradle中添加如下代码:
rootProject.name = 'MyApp'

include ':app'

+ include ':@react-native-community_async-storage'
+ project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android')

 

2.在项目结构android/app/build.gradle添加如下dependencies:
dependencies {
  ...
+ implementation project(':@react-native-community_async-storage')
}

 

3.在MainApplication.java添加如下代码:
package com.myapp;

+ import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;

...

@Override
protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
+       new AsyncStoragePackage()    
    );
}
posted @ 2019-04-01 15:11  林璡  阅读(4757)  评论(0编辑  收藏  举报