expo-camera 模块破坏了 React Native 应用程序

问题描述 投票:0回答:2

我正在尝试集成 expo 模块和 React 本机 cli 应用程序, 我已经使用

npx react-native@latest init AwesomeProject

初始化了应用程序

npx install-expo-modules@latest

安装和配置展览包

一切正常,应用程序运行成功,但安装 expo-camera 后

expo install expo-camera
构建失败并出现错误:

WARNING:Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the `gradle.properties` file or use the new publishing DSL.
5 actionable tasks: 5 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not find com.google.android:cameraview:1.0.0.
     Required by:
         project :app > project :expo > project :expo-camera

* 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 27s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not find com.google.android:cameraview:1.0.0.
     Required by:
         project :app > project :expo > project :expo-camera

* 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 27s

    at makeError (C:\Users\matea\Desktop\react-native\insta\node_modules\@react-native-community\cli-platform-android\node_modules\execa\index.js:174:9)
    at C:\Users\matea\Desktop\react-native\insta\node_modules\@react-native-community\cli-platform-android\node_modules\execa\index.js:278:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runOnAllDevices (C:\Users\matea\Desktop\react-native\insta\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:82:7)
    at async Command.handleAction (C:\Users\matea\Desktop\react-native\insta\node_modules\@react-native-community\cli\build\index.js:108:9)
info Run CLI with --verbose flag for more details.

package.json

{
  "name": "insta",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "expo": "^48.0.0",
    "react": "18.2.0",
    "react-native": "0.71.3",
    "expo-camera": "~13.2.1"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.2.1",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.7",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "jest": {
    "preset": "react-native"
  }
}

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()         
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }
}

这是干净的模板,工作流程如下:

npx react-native@latest init AwesomeProject

npx install-expo-modules@latest

expo install expo-camera
<- app fails to build after this command/.

我对原生反应还很陌生,所以每个提示都会有帮助,谢谢

react-native expo
2个回答
1
投票

这个解决方案对我有用: 您必须在

android/build.gradle

中添加此存储库配置
allprojects {
    repositories {
        maven {
            url "$rootDir/../node_modules/expo-camera/android/maven"
        }
    }
}

0
投票

我也有类似的问题;对我有用的是添加另一个存储库块并用 allprojects{} 包装它,而不是尝试将其添加到已有的内容中。这就是我正在尝试的:

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 26
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "26.1.10909125"
        kotlinVersion = "1.9.24"
    }
    allprojects {
        repositories {
            google()
            mavenCentral()
            maven {
                url "$rootDir/../node_modules/expo-camera/android/maven"
            }
        }
    }
    dependencies {
        classpath('com.android.tools.build:gradle:8.4.1')
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
    }
}

这就是有效的:

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 26
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "26.1.10909125"
        kotlinVersion = "1.9.24"
    }

    repositories {
        google()
        mavenCentral()
    }
    
    allprojects {
        repositories {
            maven {
                url "$rootDir/../node_modules/expo-camera/android/maven"
            }
        }
    }

    dependencies {
        classpath('com.android.tools.build:gradle:8.4.1')
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
    }
}

apply plugin: "com.facebook.react.rootproject"
© www.soinside.com 2019 - 2024. All rights reserved.