杭州陈奕迅 發表於 2019-5-14 14:38:00

关于react-native引入第三方库,运行react-native link xxxxx后项目无法运行

<p>最新版本的react-native中,官方表示将要移除</p>
<div>AsyncStorage,推荐使用@react-native-community/async-storage,好吧官方经常这么干</div>
<div>&nbsp;</div>
<div>按照官方提示</div>
<div>yarn add&nbsp;@react-native-community/async-storage</div>
<div>react-native link&nbsp;@react-native-community/async-storage</div>
<div>好吧,果然不负众望的报错了</div>
<div>错误信息如下</div>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">info Starting JS server...
info Building and installing the app on the device (cd android </span>&amp;&amp;<span style="color: rgba(0, 0, 0, 1)"> gradlew.bat app:installDebug)...
</span>&gt;<span style="color: rgba(0, 0, 0, 1)"> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED

FAILURE: Build failed </span><span style="color: rgba(0, 0, 255, 1)">with</span><span style="color: rgba(0, 0, 0, 1)"> an exception.

</span>*<span style="color: rgba(0, 0, 0, 1)"> What went wrong:
Execution failed </span><span style="color: rgba(0, 0, 255, 1)">for</span> task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'<span style="color: rgba(0, 0, 0, 1)">.
</span>&gt; com.google.gson.stream.MalformedJsonException: Invalid escape sequence at line 1 column 32 path $.name

</span>*<span style="color: rgba(0, 0, 0, 1)"> Try:
Run </span><span style="color: rgba(0, 0, 255, 1)">with</span> --stacktrace option to get the stack trace. Run <span style="color: rgba(0, 0, 255, 1)">with</span> --info or --debug option to get more log output. Run <span style="color: rgba(0, 0, 255, 1)">with</span> --<span style="color: rgba(0, 0, 0, 1)">scan to get full insights.

</span>* Get more help at https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">help.gradle.org</span>
<span style="color: rgba(0, 0, 0, 1)">
BUILD FAILED </span><span style="color: rgba(0, 0, 255, 1)">in</span><span style="color: rgba(0, 0, 0, 1)"> 3s
</span>76 actionable tasks: 1 executed, 75 up-to-<span style="color: rgba(0, 0, 0, 1)">date
error Could not install the app on the device, read the error above </span><span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">facebook.github.io/react-native/docs/getting-started.html</span>
error Command failed: gradlew.bat app:installDebug. Run CLI <span style="color: rgba(0, 0, 255, 1)">with</span> --verbose flag <span style="color: rgba(0, 0, 255, 1)">for</span> more details.</pre>
</div>
<p>有关环境信息</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">info
React Native Environment Info:
    System:
      OS: Windows </span>10<span style="color: rgba(0, 0, 0, 1)">
      CPU: (</span>8) x64 Intel(R) Core(TM) i7-4790 CPU @ 3<span style="color: rgba(0, 0, 0, 1)">.60GHz
      Memory: </span>4.55 GB / 15.95<span style="color: rgba(0, 0, 0, 1)"> GB
    Binaries:
      Node: </span>10.15.3 -<span style="color: rgba(0, 0, 0, 1)"> D:\node\node.EXE
      Yarn: </span>1.16.0 -<span style="color: rgba(0, 0, 0, 1)"> D:\yarn\bin\yarn.CMD
      npm: </span>6.4.1 - D:\node\npm.CMD</pre>
</div>
<p>解决方案</p>
<div class="cnblogs_code">
<pre>1<span style="color: rgba(0, 0, 0, 1)">.清除yarn缓存 yarn cache clean
</span>2.清除npm缓存 npm cache clean -<span style="color: rgba(0, 0, 0, 1)">f
</span>3<span style="color: rgba(0, 0, 0, 1)">.在项目文件夹中有一个package.json 文件,里面记录了该项目所有安装的依赖环境,若项目文件出现依赖环境报错的情况,则可以删除依赖node_module文件夹,在重新yarn install 一次 , 重新安装依赖。
</span>4.对于项目出现出现.../.../debug/.../../文件夹报错,可能是缓存导致的问题,进入android文件夹下,输入命令 ./gradlew clean 命令清除缓存,也可使用android studio 中的菜单按钮的build下的clean project清除环境,在使用rebuild project 重新跑一次项目。</pre>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div><br><br>
来源:https://www.cnblogs.com/songdongdong/p/10862065.html
頁: [1]
查看完整版本: 关于react-native引入第三方库,运行react-native link xxxxx后项目无法运行