条件:
打开已安装的应用程序(Android,使用VS Code。不是Android Studio)时发生错误
我运行了./gradlew assembleRelease和./gradlew installRelease。构建成功。我最近没有安装任何东西。已成功构建apk文件并已运行安装。然后,我引入了react-native元素并使用了它们的{Icon}。但此后已删除。无疑是问题的原因。
错误位于我的android.bundle文件的第66行。
NPM START错误
当我为模拟器运行npm start时,收到以下错误:React Native Version Mismatch。 Javascript:0.57.2。原生:0.55.4。我已经尝试过多次更新到0.57.2,并替换所有我要求0.55.4的情况。我确实更新了build.gradle文件以反映0.57.2。
要解决的步骤:
我已经删除了node_modules文件夹和软件包锁定文件,并通过npm i重新安装。尝试了一些行家配置。并通过以下方式手动更新了我的捆绑包:
react-native软件包--platform android --dev false --entry-file App.js --bundle-output android / app / src / main / assets / index.android.bundle --assets-目标android / app / src / main / res /
我试图包括所有可能需要的文件。任何帮助是极大的赞赏。很高兴提供任何有助于解决此错误的信息。
Package.JSON
{
"name": "blok",
"main": "node_modules/expo/AppEntry.js",
"private": true,
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject",
"test": "jest"
},
"dependencies": {
"babel-preset-react-native": "^5",
"expo": "^30.0.1",
"jest": "^23.6.0",
"react": "16.3.1",
"react-native": "^0.57.2",
"react-native-animatable": "^1.3.0",
"react-native-fbsdk": "^0.8.0",
"react-native-router-flux": "^4.0.5",
"react-redux": "^5.0.7",
"react-router-native": "^4.3.0",
"redux": "^4.0.0",
"remote-redux-devtools": "^0.5.13"
},
"jest": {
"preset": "react-native"
},
"devDependencies": {
"babel-preset-react-native": "^5",
"schedule": "^0.4.0"
}
}
build.gradle(根)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
task assemble{}
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
url 'https://maven.google.com/'
}
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
jcenter()
google()
}
}
// url "$rootDir/../node_modules/react-native/android"
build.gradle(android / app)
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "App.js",
bundleAssetName: "index.android.bundle",
bundleInRelease: true,
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.blok"
minSdkVersion 16
targetSdkVersion 28
versionCode 2
versionName "2.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
storeFile file(BLOK_RELEASE_STORE_FILE)
storePassword BLOK_RELEASE_STORE_PASSWORD
keyAlias BLOK_RELEASE_KEY_ALIAS
keyPassword BLOK_RELEASE_KEY_PASSWORD
}
}
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"
signingConfig signingConfigs.release
}
}
// 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
}
}
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
// compile("com.facebook.react:react-native:0.57.2") { force = true }
compile "com.facebook.react:react-native:+" // From node_modules'
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
MainApplication.java
package com.blok;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return true;
// return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "App";
// return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
gradle.properties
android.enableAapt2=false
答案 0 :(得分:1)
我在本机0.57.3中遇到了相同的错误。要解决此错误:我必须安装metro-react-native-babel-preset并在.babelrc和babel.config.js中进行更改:
const预设= ['react-native','@ babel / preset-flow'];
到
const预设= ['module:metro-react-native-babel-preset','@ babel / preset-flow'];