Expo 49 Gradle 在本地运行 eas build 进行开发时出现错误

k_k*_*rrs 5 android gradle react-native expo

我正在尝试在本地构建一个 Expo React Native 应用程序以在 Android 模拟器上进行测试,因为我使用的是不支持 Expo Go 的react-native-auth0。但是,当我尝试构建时,我收到此错误:

[RUN_GRADLEW] FAILURE: Build failed with an exception.
[RUN_GRADLEW] * What went wrong:
[RUN_GRADLEW] A problem occurred configuring root project 'FIRST2'.
[RUN_GRADLEW] > Could not determine the dependencies of null.
[RUN_GRADLEW]    > Could not resolve all task dependencies for configuration ':classpath'.
[RUN_GRADLEW]       > Could not resolve expo.modules:expo-dev-launcher-gradle-plugin.
[RUN_GRADLEW] Required by:
[RUN_GRADLEW]             project :
[RUN_GRADLEW] > No matching variant of project :expo-dev-launcher-gradle-plugin
[RUN_GRADLEW] was found. The consumer was configured to find
[RUN_GRADLEW] a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.4.2'
[RUN_GRADLEW] but:
[RUN_GRADLEW] - Variant 'apiElements' capability expo.modules:expo-dev-launcher-gradle-plugin:unspecified declares
[RUN_GRADLEW] a library, packaged as a jar, and its dependencies declared externally:
[RUN_GRADLEW] - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed
[RUN_GRADLEW] a runtime of a component compatible with Java 8
[RUN_GRADLEW] - Other compatible attribute:
[RUN_GRADLEW] - Doesn't say anything about
[RUN_GRADLEW] org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW] - Variant 'mainSourceElements' capability expo.modules:expo-dev-launcher-gradle-plugin:unspecified declares a component, and its dependencies declared externally:
[RUN_GRADLEW] - Incompatible because this component declares
[RUN_GRADLEW] a component of category 'verification' and the consumer needed
[RUN_GRADLEW] a library
[RUN_GRADLEW] - Other compatible attributes:
[RUN_GRADLEW] - Doesn't say anything about
[RUN_GRADLEW] its target Java version (required compatibility with Java 8)
[RUN_GRADLEW]                      - Doesn't say anything about
[RUN_GRADLEW] its elements (required them packaged as a jar)
[RUN_GRADLEW]                      - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW] - Doesn't say anything about its usage (required a runtime)
[RUN_GRADLEW]              - Variant 'runtimeElements' capability expo.modules:expo-dev-launcher-gradle-plugin:unspecified declares
[RUN_GRADLEW] a runtime of a library, packaged as a jar, and its dependencies declared externally:
[RUN_GRADLEW]                  - Incompatible because this component declares a component compatible with Java 11 and the consumer needed
[RUN_GRADLEW] a component compatible with Java 8
[RUN_GRADLEW]                  - Other compatible attribute:
[RUN_GRADLEW]                      - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW] - Variant 'testResultsElementsForTest' capability expo.modules:expo-dev-launcher-gradle-plugin:unspecified:
[RUN_GRADLEW] - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
[RUN_GRADLEW] - Other compatible attributes:
[RUN_GRADLEW]                      - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
[RUN_GRADLEW]                      - Doesn't say anything about its target Java version (required compatibility with Java 8)
[RUN_GRADLEW]                      - Doesn't say anything about its elements (required them packaged as a jar)
[RUN_GRADLEW] - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW] - Doesn't say anything about its usage (required a runtime)
[RUN_GRADLEW] > Could not resolve com.android.tools.build:gradle:7.4.2.
[RUN_GRADLEW]         Required by:
[RUN_GRADLEW]             project :
[RUN_GRADLEW]          > No matching variant of com.android.tools.build:gradle:7.4.2
[RUN_GRADLEW] was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.4.2' but:
[RUN_GRADLEW]              - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.2 declares a library, packaged as a jar, and its dependencies declared externally:
[RUN_GRADLEW]                  - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
[RUN_GRADLEW]                  - Other compatible attribute:
[RUN_GRADLEW]                      - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW]              - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
[RUN_GRADLEW]                  - Incompatible because this component declares documentation and the consumer needed a library
[RUN_GRADLEW]                  - Other compatible attributes:
[RUN_GRADLEW] - Doesn't say anything about its target Java version (required compatibility with Java 8)
[RUN_GRADLEW]                      - Doesn't say anything about its elements (required them packaged as a jar)
[RUN_GRADLEW]                      - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW]              - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
[RUN_GRADLEW]                  - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
[RUN_GRADLEW]                  - Other compatible attribute:
[RUN_GRADLEW] - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW]              - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
[RUN_GRADLEW]                  - Incompatible because this component declares documentation and the consumer needed a library
[RUN_GRADLEW]                  - Other compatible attributes:
[RUN_GRADLEW]                      - Doesn't say anything about its target Java version (required compatibility with Java 8)
[RUN_GRADLEW]                      - Doesn't say anything about its elements (required them packaged as a jar)
[RUN_GRADLEW]                      - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW]       > Could not resolve com.facebook.react:react-native-gradle-plugin.
[RUN_GRADLEW]         Required by:
[RUN_GRADLEW]             project :
[RUN_GRADLEW]          > No matching variant of project :gradle-plugin was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.4.2' but:
[RUN_GRADLEW]              - Variant 'apiElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a library, packaged as a jar, and its dependencies declared externally:
[RUN_GRADLEW]                  - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
[RUN_GRADLEW]                  - Other compatible attribute:
[RUN_GRADLEW]                      - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW]              - Variant 'mainSourceElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a component, and its dependencies declared externally:
[RUN_GRADLEW]                  - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
[RUN_GRADLEW]                  - Other compatible attributes:
[RUN_GRADLEW]                      - Doesn't say anything about its target Java version (required compatibility with Java 8)
[RUN_GRADLEW]                      - Doesn't say anything about its elements (required them packaged as a jar)
[RUN_GRADLEW]                      - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW]                      - Doesn't say anything about its usage (required a runtime)
[RUN_GRADLEW]              - Variant 'runtimeElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
[RUN_GRADLEW]                  - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
[RUN_GRADLEW]                  - Other compatible attribute:
[RUN_GRADLEW]                      - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW]              - Variant 'testResultsElementsForTest' capability com.facebook.react:react-native-gradle-plugin:unspecified:
[RUN_GRADLEW]                  - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
[RUN_GRADLEW]                  - Other compatible attributes:
[RUN_GRADLEW]                      - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
[RUN_GRADLEW]                      - Doesn't say anything about its target Java version (required compatibility with Java 8)
[RUN_GRADLEW]                      - Doesn't say anything about its elements (required them packaged as a jar)
[RUN_GRADLEW]                      - Doesn't say anything about org.gradle.plugin.api-version (required '7.4.2')
[RUN_GRADLEW]                      - Doesn't say anything about its usage (required a runtime)
[RUN_GRADLEW] * Try:
[RUN_GRADLEW] > Run with --stacktrace option to get the stack trace.
[RUN_GRADLEW] > Run with --info or --debug option to get more log output.
[RUN_GRADLEW] > Run with --scan to get full insights.
[RUN_GRADLEW] * Get more help at https://help.gradle.org
[RUN_GRADLEW] BUILD FAILED in 4s
[RUN_GRADLEW] Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

     Build failed
     Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
    npx exited with non-zero code: 1
Run Code Online (Sandbox Code Playgroud)

我尝试更改 JDK 版本(使用 OpenJDK 21)、Gradle 版本(尝试使用 8.0.1、7.5.1 和 7.4.2)。我完全迷失在这里了。

这是我的 package.json:

{
  "name": "first2-app",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "start-clearcache": "expo start -c"
  },
  "dependencies": {
    "@react-navigation/native": "^6.1.9",
    "@react-navigation/native-stack": "^6.9.15",
    "@reduxjs/toolkit": "^1.9.7",
    "axios": "^1.5.1",
    "expo": "~49.0.15",
    "expo-dev-client": "~2.4.11",
    "expo-location": "~16.1.0",
    "expo-splash-screen": "~0.20.5",
    "expo-status-bar": "~1.6.0",
    "nativewind": "^2.0.11",
    "react": "18.2.0",
    "react-native": "0.72.6",
    "react-native-auth0": "^3.0.2",
    "react-native-maps": "1.7.1",
    "react-native-safe-area-context": "4.6.3",
    "react-native-screens": "~3.22.0",
    "react-redux": "^8.1.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/react": "~18.2.14",
    "tailwindcss": "^3.3.2",
    "typescript": "^5.1.3"
  },
  "private": true
}
Run Code Online (Sandbox Code Playgroud)

eas.json:

{
    "cli": {
        "version": ">= 0.42.4"
    },
    "build": {
        "development": {
            "distribution": "internal",
            "android": {
                "gradleCommand": ":app:assembleDebug"
            },
            "ios": {
                "buildConfiguration": "Debug"
            }
        },
        "preview": {
            "distribution": "internal",
            "ios": {
                "simulator": true
            }
        },
        "production": {}
    },
    "submit": {
        "production": {}
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 0

eas.json 文件需要包含“channels”

{
    "cli": {
        "version": ">= 0.42.4"
    },
    "build": {
        "development": {
            "distribution": "internal",
            "android": {
                "gradleCommand": ":app:assembleDebug"
            },
            "ios": {
                "buildConfiguration": "Debug"
            },
         "channel": "development" 
        },
        "preview": {
            "distribution": "internal",
            "ios": {
                "simulator": true
            },
        "channel": "preview"
        },

        "production": {}
    },
    "submit": {
        "production": {}
    }
}
Run Code Online (Sandbox Code Playgroud)