我注意到在构建android构建时,react-native和gradle具有两个不同的输出。
react-native-config
等插件的一些预构建工作BUILD SUCCESSFUL
输出,特别是error type 3
react-native
问题
除了安装部分(4)之外,这两个命令的构建部分为何不同?
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
答案 0 :(得分:2)
react-native run-android
包含命令./gradlew installDebug
./gradlew installDebug
用于需要将apk推送到设备时,而./gradlew assembleDebug
仅用于构建apk。
如果必须要有一个观点,可以说./gradlew assembleDebug
是./gradlew installDebug
执行的过程的子集
从本质上讲,如果我必须列出,react-native run-android
执行的过程包括-
./gradlew installDebug
reverse tcp:8081 tcp:8081
,它将您的Metro Bundle捆绑到应用仿真器/设备然后./gradlew assembleDebug
会构建apk。没有了
希望它会有所帮助:)
PS:如果仔细检查,react-native run-android
的构建部分是成功的,因此可以看到BUILD SUCCESSFUL
的输出,但是由于其他进程失败,因此它整体上会失败。
答案 1 :(得分:1)
根据我的说法,您正在比较两种不同的事物。
react-native run-android
:
它执行cd android && ./gradlew installDebug
(在打印的日志中可以看到),它专门用于安装已经构建并签名的apk,或者构建apk并立即将其安装在正在运行的模拟器或连接的设备上。
/>
由于安装不成功,它会引发错误。
./gradlew assembleDebug
:
另一方面,./gradlew assembleDebug
仅用于构建应用程序。(这意味着您可以使用此命令构建调试APK。)成功创建调试apk时,它会显示消息“ BUILD SUCCESSFUL”(构建成功)