【问题标题】:Run the project on Android @ react-native 0.60.2, build success but nothing happens在Android@react-native 0.60.2 上运行项目,构建成功但没有任何反应
【发布时间】:2019-11-28 00:52:36
【问题描述】:

有一天我将我的 react-native 项目从 0.59.3 升级到 0.60.2 设置 AndroidX 迁移并运行 react-native run-android。 它显示构建成功,并且应用程序安装在模拟器上,但 Metro bundler 没有运行

这是我的设置:

react-native-cli: 2.0.1 反应原生:0.60.2

这里是终端登录

warn The following packages use deprecated "rnpm" config that will stop working from next release:
  - react-native-code-push: https://microsoft.github.io/code-push
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
error React Native CLI uses autolinking for native dependencies, but the following modules are linked manually: 
  - @react-native-community/async-storage (to unlink run: "react-native unlink @react-native-community/async-storage")
  - react-native-amplitude-analytics (to unlink run: "react-native unlink react-native-amplitude-analytics")
  - react-native-camera (to unlink run: "react-native unlink react-native-camera")
  - react-native-code-push (to unlink run: "react-native unlink react-native-code-push")
  - react-native-config (to unlink run: "react-native unlink react-native-config")
  - react-native-firebase (to unlink run: "react-native unlink react-native-firebase")
  - react-native-languages (to unlink run: "react-native unlink react-native-languages")
  - react-native-os (to unlink run: "react-native unlink react-native-os")
  - react-native-randombytes (to unlink run: "react-native unlink react-native-randombytes")
  - react-native-splash-screen (to unlink run: "react-native unlink react-native-splash-screen")
  - react-native-svg (to unlink run: "react-native unlink react-native-svg")
  - react-native-tcp (to unlink run: "react-native unlink react-native-tcp")
  - react-native-touch-id (to unlink run: "react-native unlink react-native-touch-id")
  - react-native-udp (to unlink run: "react-native unlink react-native-udp")
  - react-native-vector-icons (to unlink run: "react-native unlink react-native-vector-icons")
  - react-native-version-number (to unlink run: "react-native unlink react-native-version-number")
  - react-native-webview (to unlink run: "react-native unlink react-native-webview")
This is likely happening when upgrading React Native from below 0.60 to 0.60 or above. Going forward, you can unlink this dependency via "react-native unlink <dependency>" and it will be included in your app automatically. If a library isn't compatible with autolinking, disregard this message and notify the library maintainers.
Read more about autolinking: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1351 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
info Installing the app...

> Configure project :@react-native-community_async-storage
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :app
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.

Reading env from: .env
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

> Configure project :react-native-amplitude-analytics
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-camera
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-code-push
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-config
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-firebase
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.

react-native-firebase: using React Native prebuilt binary from /Users/mac/Documents/GitHub/myrn/node_modules/react-native/android

> Configure project :react-native-keychain
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-languages
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-os
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.

WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

> Configure project :react-native-randombytes
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-splash-screen
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-svg
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.

WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

> Configure project :react-native-tcp
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.

WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

> Configure project :react-native-touch-id
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-udp
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.

WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

> Configure project :react-native-vector-icons
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-version-number
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.


> Configure project :react-native-webview
WARNING: The following project options are deprecated and have been removed: 
android.enableAapt2
This property has no effect, AAPT2 is now always used.


WARNING: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported.
The current default is 'true'.

:react-native-webview:reactNativeAndroidRoot /Users/mac/Documents/GitHub/myrn/node_modules/react-native/android

> Task :app:processDebugGoogleServices
Parsing json file: /Users/mac/Documents/GitHub/myrn/android/app/google-services.json

> Task :app:installDebug
12:04:15 V/ddms: execute: running am get-config
12:04:15 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1
12:04:15 V/ddms: execute: returning
Installing APK 'app-debug.apk' on 'Nexus_5X_API_28(AVD) - 9' for app:debug
12:04:15 D/app-debug.apk: Uploading app-debug.apk onto device 'emulator-5554'
12:04:16 D/Device: Uploading file onto device 'emulator-5554'
12:04:16 D/ddms: Reading file permision of /Users/mac/Documents/GitHub/myrn/android/app/build/outputs/apk/debug/app-debug.apk as: rw-r--r--
12:04:16 V/ddms: execute: running pm install -r -t "/data/local/tmp/app-debug.apk"
12:04:16 V/ddms: execute 'pm install -r -t "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1
12:04:16 V/ddms: execute: returning
12:04:16 V/ddms: execute: running rm "/data/local/tmp/app-debug.apk"
12:04:16 V/ddms: execute 'rm "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1
12:04:16 V/ddms: execute: returning
Installed on 1 device.

BUILD SUCCESSFUL in 5s
338 actionable tasks: 7 executed, 331 up-to-date
info Connecting to the development server...
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.dapppocket/.MainActivity }

【问题讨论】:

  • 你可以试试这个react-native link

标签: react-native react-native-android


【解决方案1】:

检查当前进程是否已经启动并在任何端口上运行

第 1 步

以管理员身份运行命令行。然后运行下面提到的命令。在 yourPortNumber 中输入您的端口号

netstat -ano | findstr :yourPortNumber

它将列出进程及其PID(进程标识符)

然后你在识别PID后执行这个命令。

taskkill /PID typeyourPIDhere /F

注意: 由于 taskkill 在某些 git bash 命令中不起作用,请尝试:

tskill typeyourPIDhere 

再次运行第一个命令以检查该进程是否仍然可用。如果该过程成功结束,您将得到一个空行。

第 2 步

在升级 RN 版本时有时会出现类似问题。我还没有找到解决方案,但意识到在成功构建之前必须进行清理。

到目前为止,对我来说最好的解决方案是一个批处理脚本来启动项目,其中包括 gradlew clean

cd (path to project/android folder)

gradlew clean

cd (path to project root folder) 

react-native run-android

注意:所有4个命令都可以通过以下方式组合在一起

cd (path to project/android folder) && gradlew clean && cd (path to project root folder) && react-native run-android

你可以走了

希望这有助于解决您的问题。

【讨论】:

  • 感谢您的建议,但还是不行,也许我应该尝试在 0.60 以上启动一个新项目
  • 您可以删除node modules文件夹并再次执行npm install。然后做react-native link
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-14
  • 1970-01-01
  • 2010-11-09
相关资源
最近更新 更多