react-native報錯:Failed to apply plugin [id 'com.android.application']

背景:根據官網的環境配置方式配置了react-native環境,這裏提一下官網沒有配置java_home環境變量需要自己配置。https://reactnative.cn/docs/getting-started.html
然後使用android studio打開新建的rn項目,並運行npm run adnroid然後報了一堆的錯誤(我是個英語只過4級的辣雞所以谷歌翻譯,大概的意思就是項目路徑有非法字符)。
解決:
1.文件路徑上的把中文名字去掉
2.修改項目根目錄下的\android\gradle.properties文件如下:

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

android.useAndroidX=true
android.enableJetifier=true
android.overridePathCheck = true

主要是加上了這一段android.overridePathCheck = true(不檢查文件路徑)
打開android模擬器然後重新npm run android,項目就順利啓動了。

這是react-native的使用過程中的第一個bug加油!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章