我正在遵循此post来解决我的RN 0.59应用程序中的错误。我所做的就是在
中添加2行 tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
AndroidManifest.xml
在android/src/main
下。这是更改后的xml文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.emps_app">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory" //<<===added 2 lines
android:appComponentFactory="whateverString">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
但是react-native run-android
仍然会引发错误:
* What went wrong:
Execution failed for task ':app:generateDebugBuildConfig'.
> org.xml.sax.SAXParseException; systemId: file:/C:/D/code/js/emps_app/android/app/src/main/AndroidManifest.xml; lineNumber: 14; columnNumber: 52; The prefix "tools" for attribute "tools:replace" associated with an element type "application" is not bound.
我的RN应用在抛出有关Android库版本的错误之前运行良好。有几篇关于该错误的帖子,但在我看来,这些帖子似乎都不起作用。我的模拟器运行的是Android 8.1 / API27。另外请记住,RN 0.60将支持Androidx。
这里是build.gradle
(在android / app /下。为了便于阅读已删除注释):
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.emps_app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
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, "arm64-v8a": 3, "x86_64": 4]
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
}
}
}
}
dependencies {
implementation project(':react-native-vector-icons')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-keychain')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-device-info')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
}
// 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'
}
这是顶级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 = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
答案 0 :(得分:1)
请勿在AndroidManifest.xml中的以下行使用
。tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
但是要运行android应用,您可以使用android studio。 因为有时它无法通过命令行运行。 因此,您可以使用android studio并以与android应用程序相同的方式运行,但需要打开YourApp> android>运行您的应用。
答案 1 :(得分:1)
我自己正在将RN升级到0.60.0 gauntlet :-)让我感到st恼的是我的build.gradle列出了版本号为'+'的依赖项:因此gradle开始使用比我更高的版本已经意识到,并且该版本具有重复的类。
从命令行在项目的android子目录中运行./gradlew app:dependencies
。
我怀疑反应本机依赖性正在拉扯一些可能无意间与某些东西碰撞的东西。