npm 运行 android 不启动 Android 应用程序
npm run android does not launch the Android app
问题
我能够清除我的最后一个 after ignoring the errors and following the rest of the steps in the React Native Navigation installation。那些警告消失了。
但是,当我 运行 npm run android
时,它构建成功但没有启动应用程序
Configure project :app
...
Configure project :react-native-navigation
...
Task :app:installDebug
...
BUILD SUCCESSFUL in 6s
android 模拟器进入其主屏幕,但应用程序未启动。
我试过的
- 我已经尝试从 android 工作室 running/building/clean&重建。这导致当我从白色空白屏幕刷新时
Could not connect to development server
。
我已按照 here 中的步骤创建资产文件夹并运行使用此代码
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 19
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { url 'https://jitpack.io' }
}
}
app/build.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.appname"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57_5"
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support' && requested.name != 'multidex') {
details.useVersion "${rootProject.ext.supportLibVersion}"
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:design:28.0.0"
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation project(':react-native-navigation')
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
- 本机反应:“0.57.8”
- react-native-navigation: "^2.7.0"
- Android 9.0 API 28
我想你可能必须 运行 在 运行ning npm 运行 android.
之前使用 metro bundler
react-native start --reset-cache
这将启动捆绑器,因此您必须 运行
npm run android
在不同的终端 window,但项目目录相同。这个脚本在下面提到!这就是我正在做的方式。自 RN 57.2 以来,metro bundler 出现了一些问题,这一直是一个问题,这是解决方法。与此同时,我已经更新到 RN 57.8 和最新的 RNN,但我仍然 运行 那样的项目。
我还必须提到,我 运行 在带有 API 26 和 Android Studio 3.3 的模拟器上使用它,通常如果我 运行 它作为我上面说了,它会在模拟器中启动应用程序。
构建脚本
"scripts": {
"build-android": "cd ./android && ./gradlew app:assembleDebug && ./gradlew installDebug && cd ../",
"android": "npm run build-android && (adb reverse tcp:8081 tcp:8081 || true) && react-native run-android"
}
编辑
请务必遵循 RNN 团队在此 link 下为 运行 在 Android 上安装您的应用程序给出的说明:
The instructions from RNN team for running your app on an Android emulator or device.
编辑 2
根据要求,API 26 是必需的,因为这是您的编译 SDK 版本(当前用于 RNN v2.7.1)以及您的目标 SDK 版本。您可以在与上述 link 相同的 RNN 文档中找到此信息。
问题
我能够清除我的最后一个
但是,当我 运行 npm run android
时,它构建成功但没有启动应用程序
Configure project :app
...
Configure project :react-native-navigation
...
Task :app:installDebug
...
BUILD SUCCESSFUL in 6s
android 模拟器进入其主屏幕,但应用程序未启动。
我试过的
- 我已经尝试从 android 工作室 running/building/clean&重建。这导致当我从白色空白屏幕刷新时
Could not connect to development server
。 我已按照 here 中的步骤创建资产文件夹并运行使用此代码
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 19
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { url 'https://jitpack.io' }
}
}
app/build.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.appname"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57_5"
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support' && requested.name != 'multidex') {
details.useVersion "${rootProject.ext.supportLibVersion}"
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:design:28.0.0"
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation project(':react-native-navigation')
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
- 本机反应:“0.57.8”
- react-native-navigation: "^2.7.0"
- Android 9.0 API 28
我想你可能必须 运行 在 运行ning npm 运行 android.
之前使用 metro bundlerreact-native start --reset-cache
这将启动捆绑器,因此您必须 运行
npm run android
在不同的终端 window,但项目目录相同。这个脚本在下面提到!这就是我正在做的方式。自 RN 57.2 以来,metro bundler 出现了一些问题,这一直是一个问题,这是解决方法。与此同时,我已经更新到 RN 57.8 和最新的 RNN,但我仍然 运行 那样的项目。
我还必须提到,我 运行 在带有 API 26 和 Android Studio 3.3 的模拟器上使用它,通常如果我 运行 它作为我上面说了,它会在模拟器中启动应用程序。
构建脚本
"scripts": {
"build-android": "cd ./android && ./gradlew app:assembleDebug && ./gradlew installDebug && cd ../",
"android": "npm run build-android && (adb reverse tcp:8081 tcp:8081 || true) && react-native run-android"
}
编辑
请务必遵循 RNN 团队在此 link 下为 运行 在 Android 上安装您的应用程序给出的说明: The instructions from RNN team for running your app on an Android emulator or device.
编辑 2
根据要求,API 26 是必需的,因为这是您的编译 SDK 版本(当前用于 RNN v2.7.1)以及您的目标 SDK 版本。您可以在与上述 link 相同的 RNN 文档中找到此信息。