我想设置我的 react native 构建,并完全按照 0.64 版官方 react native 文档中的环境设置步骤,使用 Google APIs Intel x86 Atom System Image 部分的 Android 10.0。 https://reactnative.dev/docs/environment-setup
构建: https://github.com/NicChoo96/ReactNative0.64_Build
我什至还没有成功构建它并在我的模拟器上显示第一个 React Native 屏幕。模拟器工作正常。
我也谷歌搜索了很多次,我的标签只是堆叠,但我找不到任何解决方案。
经过多天的构建和重建,对于我的用例,我将无法使用 expo,所以我只能坚持使用 react-native-cli。如果您想知道什么,我想使用 web3.js/ether.js,但我什至无法建立基本构建,如何开始任何事情?
API Level: 29 (Android 10.0 Q)
Android SDK Build-Tools: 29.0.3
JDK: openjdk-8u292-b10
User variables for User:
ANDROID_HOME: %LOCALAPPDATA%\Android\sdk
JAVA_HOME: C:\Program Files\OpenJDK\openjdk-8u292-b10
Node Version:v16.4.0
Yarn Version: 1.22.10
Path:
{
C:\Program Files\OpenJDK\openjdk-8u292-b10\bin,
%LOCALAPPDATA%\Android\Sdk\platform-tools,
%USERPROFILE%\AppData\Local\Android\sdk\emulator
}
以下错误是一次又一次出现的错误:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class com.facebook.soloader.ApkSoSource found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.DirectorySoSource found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.Elf32_Dyn found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.Elf32_Ehdr found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.Elf32_Phdr found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.Elf32_Shdr found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.Elf64_Dyn found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.Elf64_Ehdr found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.Elf64_Phdr found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.Elf64_Shdr found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.ExoSoSource found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.FileLocker found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.MinElf found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.MinElf$ElfError found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.NativeLibrary found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.NoopSoSource found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.SoLoader found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.SoSource found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.SysUtil found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
Duplicate class com.facebook.soloader.SysUtil$LollipopSysdeps found in modules jetified-react-native-0.20.1-runtime (com.facebook.react:react-native:0.20.1) and jetified-soloader-0.10.1-runtime (com.facebook.soloader:soloader:0.10.1)
> Task :app:compileDebugJavaWithJavac FAILED
15 actionable tasks: 2 executed, 13 up-to-date
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainApplication.java:6: error: cannot find symbol
import com.facebook.react.ReactApplication;
^
symbol: class ReactApplication
location: package com.facebook.react
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainApplication.java:8: error: cannot find symbol
import com.facebook.react.ReactNativeHost;
^
symbol: class ReactNativeHost
location: package com.facebook.react
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainApplication.java:14: error: cannot find symbol
public class MainApplication extends Application implements ReactApplication {
^
symbol: class ReactApplication
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainApplication.java:16: error: cannot find symbol
private final ReactNativeHost mReactNativeHost =
^
symbol: class ReactNativeHost
location: class MainApplication
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainApplication.java:39: error: cannot find symbol
public ReactNativeHost getReactNativeHost() {
^
symbol: class ReactNativeHost
location: class MainApplication
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:9: error: cannot find symbol
import com.facebook.react.shell.MainPackageConfig;
^
symbol: class MainPackageConfig
location: package com.facebook.react.shell
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:18: error: cannot find symbol
private ReactNativeHost reactNativeHost;
^
symbol: class ReactNativeHost
location: class PackageList
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:19: error: cannot find symbol
private MainPackageConfig mConfig;
^
symbol: class MainPackageConfig
location: class PackageList
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:21: error: cannot find symbol
public PackageList(ReactNativeHost reactNativeHost) {
^
symbol: class ReactNativeHost
location: class PackageList
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:29: error: cannot find symbol
public PackageList(ReactNativeHost reactNativeHost, MainPackageConfig config) {
^
symbol: class ReactNativeHost
location: class PackageList
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:29: error: cannot find symbol
public PackageList(ReactNativeHost reactNativeHost, MainPackageConfig config) {
^
symbol: class MainPackageConfig
location: class PackageList
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:34: error: cannot find symbol
public PackageList(Application application, MainPackageConfig config) {
^
symbol: class MainPackageConfig
location: class PackageList
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:40: error: cannot find symbol
private ReactNativeHost getReactNativeHost() {
^
symbol: class ReactNativeHost
location: class PackageList
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\debug\java\com\web3rn\ReactNativeFlipper.java:25: error: package okhttp3 does not exist
import okhttp3.OkHttpClient;
^
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainActivity.java:5: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity
public class MainActivity extends ReactActivity {
^
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainApplication.java:17: error: cannot find symbol
new ReactNativeHost(this) {
^
symbol: class ReactNativeHost
location: class MainApplication
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainApplication.java:18: error: method does not override or implement a method from a supertype
@Override
^
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainApplication.java:23: error: method does not override or implement a method from a supertype
@Override
^
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainApplication.java:32: error: method does not override or implement a method from a supertype
@Override
^
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\main\java\com\web3rn\MainApplication.java:38: error: method does not override or implement a method from a supertype
@Override
^
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:26: error: reference to PackageList is ambiguous
this(application, null);
^
both constructor PackageList(ReactNativeHost,MainPackageConfig) in PackageList and constructor PackageList(Application,MainPackageConfig) in PackageList match
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\debug\java\com\web3rn\ReactNativeFlipper.java:40: error: cannot find symbol
new NetworkingModule.CustomClientBuilder() {
^
symbol: class CustomClientBuilder
location: class NetworkingModule
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\debug\java\com\web3rn\ReactNativeFlipper.java:42: error: package OkHttpClient does not exist
public void apply(OkHttpClient.Builder builder) {
^
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\debug\java\com\web3rn\ReactNativeFlipper.java:41: error: method does not override or implement a method from a supertype
@Override
^
D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\debug\java\com\web3rn\ReactNativeFlipper.java:57: error: cannot find symbol
reactInstanceManager.removeReactInstanceEventListener(this);
^
symbol: method removeReactInstanceEventListener(<anonymous ReactInstanceEventListener>)
location: variable reactInstanceManager of type ReactInstanceManager
Note: D:\1) ProjectsFolder\FYP\Learning\web3RN\android\app\src\debug\java\com\web3rn\ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
25 errors
我已经尝试过使用 JDK、JRE、build.gradle、构建工具版本。似乎我从来没有一次又一次地从这些同样的错误中逃脱。目前,我只想知道导致此错误的根本原因是什么,尽管我努力尝试使其正常工作。
android/app/build.gradle
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group: 'com.facebook.soloader'
exclude group:'com.facebook.fbjni'
}
尝试了很多很多方法,但我不知道这些依赖项中的哪些导致了这个错误并阻止我构建一个 Hello World 页面。
apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation. If none specified and
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
* // default. Can be overridden with ENTRY_FILE environment variable.
* entryFile: "index.android.js",
*
* // https://reactnative.dev/docs/performance#enable-the-ram-format
* bundleCommand: "ram-bundle",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
enableHermes: false, // clean and rebuild if changing
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore.
*
* 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:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.awesomeproject"
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"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
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.
signingConfig signingConfigs.debug
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:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
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 =
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// 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'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}