gpt4 book ai didi

android-gradle-plugin - React Native : TypeError: Undefined is not a Function. 评估(r.render())

转载 作者:行者123 更新时间:2023-12-04 17:44:24 26 4
gpt4 key购买 nike

screenshot

条件:

打开已安装的应用程序时发生错误(Android,使用 VS Code。不是 Android Studio)

我运行了 ./gradlew assembleRelease 和 ./gradlew installRelease。构建成功。我最近没有安装任何东西。已成功构建 apk 文件并运行安装。然后我引入了 react-native-elements 并使用了它们的 {Icon}。但此后已将其删除。并且怀疑问题的原因。

错误位于我的 android.bundle 文件的第 66 行。

NPM START 错误

当我为模拟器运行 npm start 时,我收到以下错误:React Native 版本不匹配。 Javascript:0.57.2。 native :0.55.4。我已多次尝试更新到 0.57.2 并替换所有我要求 0.55.4 的地方。我确实更新了我的 build.gradle 文件以反射(reflect) 0.57.2。

解决步骤:

我已经删除了 node_modules 文件夹和包锁定文件,并通过 npm i 重新安装。尝试了一些 Maven 配置。并通过以下方式手动更新了我的 bundle :

react-native bundle --platform android --dev false --entry-file App.js --bundle-output android/app/src/main/assets/index.android.bundle --assets- dest 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(root)

// 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

最佳答案

我在 react-native 0.57.3 中遇到了同样的错误。要修复此错误:我必须安装 metro-react-native-babel-preset 并更改 .babelrc 和 babel.config.js:

const presets = ['react-native', '@babel/preset-flow'];

const presets = ['module:metro-react-native-babel-preset', '@babel/preset-flow'];

关于android-gradle-plugin - React Native : TypeError: Undefined is not a Function. 评估(r.render()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52777333/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com