在尝试为 Android 构建我的 React Native 应用程序 (0.72.17) 时,出现错误:“重复的类:com.facebook.react.PackageList”。 这个类确实可以在两个位置找到:
/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java
和
/android/app/build/generated/autolinking/src/main/java/com/facebook/react/PackageList.java
所以它位于“autolinking”文件夹和“rncli”文件夹中。
该错误消息并没有说明我上面发布的内容,因此没有太大帮助。
这是我的
android/app/build.gradle
文件:
apply plugin: "com.facebook.react"
/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
*/
react {
/* Only comments here */
}
/**
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
*/
def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore (JSC)
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
namespace "com.hallonewyorkrn"
defaultConfig {
applicationId "com.hallonewyorkrn"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 12
versionName "1.0.3"
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
if (project.hasProperty('ENV_VAR')) {
storeFile file(ENV_VAR_FILE)
storePassword ENV_VAR_PASS
keyAlias ENV_VAR_ALIAS
keyPassword ENV_VAR_KEY_PASSWORD
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
packagingOptions {
jniLibs {
pickFirsts += ['lib/x86/libc++_shared.so', 'lib/x86_64/libjsc.so', 'lib/arm64-v8a/libjsc.so', 'lib/arm64-v8a/libc++_shared.so', 'lib/x86_64/libc++_shared.so', 'lib/armeabi-v7a/libc++_shared.so']
}
}
}
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
implementation "androidx.appcompat:appcompat:1.7.0"
implementation project(':react-native-video')
implementation project(':react-native-fs')
implementation project(':react-native-inappbrowser-reborn')
}
apply from: "../../node_modules/react-native-vector-image/strip_svgs.gradle"
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
``
如果您还没有在 android 文件夹中编写任何本机代码,我建议尝试 删除android文件夹并运行
npx expo prebuild
这应该会带回 android 和 ios 文件夹,然后尝试再次运行该应用程序。