use*_*363 5 android react-native
我正在关注这篇文章,以解决我的RN 0.59应用程序中的错误。我所做的是将2行添加到
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
但是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.
Run Code Online (Sandbox Code Playgroud)
我的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'
}
Run Code Online (Sandbox Code Playgroud)
这是顶级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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
请不要在 AndroidManifest.xml 中使用以下行。
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Run Code Online (Sandbox Code Playgroud)
但要运行 Android 应用程序,您可以使用 Android Studio。因为有时它不是通过命令行运行的。因此,您可以使用 android studio 并以与 android 应用程序相同的方式运行,但您需要打开 YourApp>android> 运行您的应用程序。
| 归档时间: |
|
| 查看次数: |
293 次 |
| 最近记录: |