react-native run-android Vs ./gradlew assembleDebug

。_饼干妹妹 提交于 2020-06-29 03:43:06

问题


I've noticed that react-native and gradle have two different outputs when building android builds.

  1. react-native build seems to incorporate some pre-build work from plugins such as react-native-config
  2. react-native will fail on build if there is no device present to install in (emulator in my case)
  3. different BUILD SUCCESSFUL output, particularly error type 3 in my case
  4. install - react-native only

Question

Aside from the install portion (4), why are the build portions of these two commands different?

Sample Outputs

react-native run-android

$ react-native run-android
Scanning folders for symlinks in /Users/Jackson/Sites/fnmultiapptest/node_modules (10ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...

> Configure project :app 
Reading env from: .env
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
Observed package id 'build-tools;20.0.0' in inconsistent location '/Users/Jackson/.android/build-tools/android-4.4W' (Expected '/Users/Jackson/.android/build-tools/20.0.0')

> Configure project :react-native-config 
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

> Task :react-native-config:installDebugAndroidTest 
11:40:14 V/ddms: execute: running am get-config
11:40:14 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1
11:40:14 V/ddms: execute: returning
Installing APK 'react-native-config-debug-androidTest.apk' on 'Nexus_5X_API_26(AVD) - 8.0.0' for react-native-config:debugAndroidTest
11:40:14 D/react-native-config-debug-androidTest.apk: Uploading react-native-config-debug-androidTest.apk onto device 'emulator-5554'
11:40:14 D/Device: Uploading file onto device 'emulator-5554'
11:40:14 D/ddms: Reading file permision of /Users/Jackson/Sites/fnmultiapptest/node_modules/react-native-config/android/build/outputs/apk/androidTest/debug/react-native-config-debug-androidTest.apk as: rw-r--r--
11:40:14 V/ddms: execute: running pm install -r -t "/data/local/tmp/react-native-config-debug-androidTest.apk"
11:40:15 V/ddms: execute 'pm install -r -t "/data/local/tmp/react-native-config-debug-androidTest.apk"' on 'emulator-5554' : EOF hit. Read: -1
11:40:15 V/ddms: execute: returning
11:40:15 V/ddms: execute: running rm "/data/local/tmp/react-native-config-debug-androidTest.apk"
11:40:15 V/ddms: execute 'rm "/data/local/tmp/react-native-config-debug-androidTest.apk"' on 'emulator-5554' : EOF hit. Read: -1
11:40:15 V/ddms: execute: returning
Installed on 1 device.


BUILD SUCCESSFUL in 2s
38 actionable tasks: 1 executed, 37 up-to-date
Running /Users/Jackson/.android/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081
Starting the app on emulator-5554 (/Users/Jackson/.android/platform-tools/adb -s emulator-5554 shell am start -n com.workingproject/com.workingproject.MainActivity)...
Starting: Intent { cmp=com.workingproject/.MainActivity }
Error type 3
Error: Activity class {com.workingproject/com.workingproject.MainActivity} does not exist.

./gradlew assembleDebug

$ ./gradlew assembleDebug

> Configure project :app 
Reading env from: .env
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-config 
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


BUILD SUCCESSFUL in 0s
50 actionable tasks: 50 up-to-date

回答1:


According to me, you are comparing two different things.

  1. react-native run-android :

    it executes cd android && ./gradlew installDebug(which can be seen in printed logs), which are exclusively used for installing already built and signed apk Or to build the apk and immediately install it on a running emulator or connected device.
    And it throws error as installation is not successful.

  2. ./gradlew assembleDebug :

    On the other hand ./gradlew assembleDebug this is only used for building the application.(which means you can build a debug APK with this command.) As debug apk is successfully created it shows message "BUILD SUCCESSFUL"


REF: Build a debug APK




回答2:


react-native run-android contains the command ./gradlew installDebug

./gradlew installDebug is used when you need to push an apk to a device whereas ./gradlew assembleDebug is just used to build an apk.

If you had to take a perspective, you can say ./gradlew assembleDebug being a subset of the processes executed by ./gradlew installDebug

So essentially if I had to list, the processes executed by react-native run-android include -

  1. Starts the metro package bundler which will listen for all your js changes
  2. Builds apk using ./gradlew installDebug
  3. Checks for available devices, if not it fails here.
  4. If successful, it installs the apk on the device, the same which you can read from the logs you showed us.
  5. As a last, it executes reverse tcp:8081 tcp:8081 which connects your metro bundler to the app emulator/device

And ./gradlew assembleDebug just builds the apk. Nothing more

Hope it helps :)

PS: If you check carefully, the build portion of react-native run-android is successful, hence you can see the BUILD SUCCESSFUL output, but since, other processes fail, it fails as a whole command.



来源:https://stackoverflow.com/questions/52901338/react-native-run-android-vs-gradlew-assembledebug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!