簡體   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