使用react-native-camera

时间:2018-05-21 17:49:53

标签: android react-native gradle react-native-camera

我最近想用相机创建一个react-native应用,并开始使用react-native-camera,所以我就这样做了:

$ react-native init testApp2
$ npm install --save react-native-camera
$ react-native link react-native-camera
$ react-native run-android

在最后一行之后我得到了奇怪的输出(下面)(我在我的电脑上安装了Android工作室,当我去构建apk时,Android工作室会创建确切的错误)

Scanning folders for symlinks in C:\Users\seyye_000\Documents\testApp2\node_modules (31ms)
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: The specified Android SDK Build Tools version (26.0.2) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.2.
Android SDK Build Tools 27.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '26.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
:app:preBuild UP-TO-DATE
:react-native-camera:preBuild UP-TO-DATE
:react-native-camera:preDebugBuild UP-TO-DATE
:react-native-camera:checkDebugManifest UP-TO-DATE
:react-native-camera:processDebugManifest UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:react-native-camera:compileDebugAidl UP-TO-DATE
:app:compileDebugAidl UP-TO-DATE
:react-native-camera:packageDebugRenderscript NO-SOURCE
:app:compileDebugRenderscript UP-TO-DATE
:app:checkDebugManifest UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:prepareLintJar UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:react-native-camera:mergeDebugShaders UP-TO-DATE
:react-native-camera:compileDebugShaders UP-TO-DATE
:react-native-camera:generateDebugAssets UP-TO-DATE
:react-native-camera:packageDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:react-native-camera:compileDebugRenderscript UP-TO-DATE
:react-native-camera:generateDebugResValues UP-TO-DATE
:react-native-camera:generateDebugResources UP-TO-DATE
:react-native-camera:packageDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:bundleDebugJsAndAssets SKIPPED
:app:mainApkListPersistenceDebug UP-TO-DATE
:app:createDebugCompatibleScreenManifests UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:splitsDiscoveryTaskDebug UP-TO-DATE
:react-native-camera:platformAttrExtractor UP-TO-DATE
:react-native-camera:generateDebugRFile UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:react-native-camera:generateDebugBuildConfig UP-TO-DATE
:react-native-camera:prepareLintJar UP-TO-DATE
:react-native-camera:generateDebugSources UP-TO-DATE
:react-native-camera:javaPreCompileDebug UP-TO-DATE
:react-native-camera:compileDebugJavaWithJavac UP-TO-DATE
:react-native-camera:processDebugJavaRes NO-SOURCE
:react-native-camera:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
:app:javaPreCompileDebug UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk NO-SOURCE
:app:compileDebugSources UP-TO-DATE
:app:transformClassesWithDexBuilderForDebug UP-TO-DATE
:app:transformDexArchiveWithExternalLibsDexMergerForDebugD8: Program type already present: com.facebook.infer.annotation.FalseOnNull

FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task 
':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\6.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\7.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\8.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\54.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\55.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\56.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\57.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\58.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\60.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\61.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\62.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\63.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\76.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\77.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\78.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\79.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\80.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\84.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\98.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\99.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\100.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\101.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\102.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\103.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\104.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\105.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\106.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\107.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\108.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\109.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\110.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\111.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\112.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\113.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\114.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\115.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\116.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\117.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\118.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\119.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\120.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\121.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\122.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\123.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\124.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\125.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\126.jar, C:\Users\seyye_000\Documents\testApp2\android\app\build\intermediates\transforms\dexBuilder\debug\127.jar

* 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 21s
36 actionable tasks: 1 executed, 35 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

我已经尝试了一切可能的方式来玩Android工作室以修复此错误但我真的很累,不知道接下来该做什么。 :\

这是我的package.json

{
  "name": "testApp2",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.3.1",
    "react-native": "0.55.4",
    "react-native-camera": "^1.1.3"
  },
  "devDependencies": {
    "babel-jest": "22.4.4",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.4.4",
    "react-test-renderer": "16.3.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

如果你知道这个请求有什么问题告诉我,我开始真的疯了......

因为我不知道如何将我的所有代码放在这里,我只是将它上传到GitHub上,HERE是它的链接。

1 个答案:

答案 0 :(得分:0)

尝试启用multiDex

app / build.gradle:

android {
    defaultConfig {
       multiDexEnabled true
    }
}