繁体   English   中英

安装新的 react-native 项目时找不到 swiperefreshlayout-1.0.0.aar 错误

[英]Could not find swiperefreshlayout-1.0.0.aar error when installing new react-native project

好的,这是我所做的一步一步:

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天的头发了。 我试过这个但徒劳无功

抱歉,如果这对您来说很明显,但是react-native 蒙版视图库不是干净的反应原生项目的一部分:

任务“: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, ...) 会打印您当前所在的目录。

再次道歉,如果这一切都对你很清楚:以下应该从一个新项目开始:

  1. 从您选择的目录(例如桌面)运行npx react-native init NewApp 现在,您的桌面上应该有一个名为NewApp的文件夹。
  2. 确保在启动任何 react-native 任务(如npx react-native run-android )时位于正确的文件夹(而不是其子文件夹或上面的文件夹) C:/Users/ali/Desktop/NewApp 如有疑问,请运行cd进行验证。
  3. 快乐编码!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM