好的,这是我一步一步做的:
1- 配置 ANDROID_HOME 环境变量。我设置sdk路径
2- 将平台工具添加到环境变量 PATH。
3- 运行 npx react-native init MyApp
4-连接我的手机,启用usb调试
5-下载并安装gradle 6.5.all
4-下载并安装sdk构建工具29.0.2
5- 启动 npx react-native 启动
6- 打开另一个终端并运行 npx react-native run-android
这是我手机上应该安装应用程序的地方,但我收到此错误:
FAILURE: Build failed with an exception.
* What went wrong:
> Could not find swiperefreshlayout-1.0.0.aar (androidx.swiperefreshlayout:swiperefreshlayout:1.0.0).
Searched in the following locations:
file:/C:/Users/ali/Desktop/react-native/myApp/node_modules/react-native/android/androidx/swiperefreshlayout/swiperefreshlayout/1.0.0/swiperefreshlayout-1.0.0.aar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 59s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
这是我的 build.gradle 文件(myApp\android\build.gradle):
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
enableHermes: false, // clean and rebuild if changing
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.myapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate auniversal 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
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 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
}
}
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)
我已经拔头发 3 天了。我试过 this但徒劳无功
最佳答案
抱歉,如果这对您来说很明显,但是 react-native masked view library不是干净的 React Native 项目的一部分:
Execution failed for task ':react-native-community_masked-view:generateDebugRFile‘.
我最好的猜测是您正在尝试从不同于您刚创建的目录的目录运行 react-native run-android
。错误日志表明您正在从 C:/Users/ali/Desktop/react-native/myApp
运行 run-android
– 您能验证这是您拥有的同一目录吗将干净的 react-native 应用程序安装到?在终端中运行 cd
(Windows) 或 pwd
(macOS, Unix, …) 会打印出您当前所在的目录。
再次抱歉,如果这对您来说很清楚:以下应该从一个新项目开始:
- 从您选择的目录运行
npx react-native init NewApp
,例如你的桌面。现在您的 table 面上应该有一个名为NewApp
的文件夹。 - 确保你在正确的文件夹中(而不是子文件夹或上面的文件夹)
C:/Users/ali/Desktop/NewApp
启动任何 react-native 任务时,如npx react-native run-android
.如果有疑问,请运行cd
进行验证。 - 编码愉快!
关于android - 安装新的 react-native 项目时找不到 swiperefreshlayout-1.0.0.aar 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65161054/