使用 react-native-camera 创建非常简单的应用程序时出错
Posted
技术标签:
【中文标题】使用 react-native-camera 创建非常简单的应用程序时出错【英文标题】:Error on creating very very simple app using react-native-camera 【发布时间】:2018-05-21 17:49:53 【问题描述】:我最近想用相机创建一个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 Studio,当我去构建 apk 时,Android Studio 会创建确切的错误)
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 Studio 来修复这个错误,但我真的很累,不知道下一步该怎么做。 :\
这是我的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 是它的链接。
【问题讨论】:
显示 .gradle 文件 @shivam 我将所有项目文件 git 推送到 github 存储库,链接在最后一行。 tnx 的帮助 您是否尝试过在您的 app/build.gradle 中启用“multiDexEnabled” 是的,它只是给了我另一个错误,我再也不能容忍了,决定使用本机模块而不使用 react-native-camera 但感谢您的帮助,很抱歉我改变了我的策略,并没有在这里尽快回答 【参考方案1】:尝试启用 multiDex
在 app/build.gradle:
android
defaultConfig
multiDexEnabled true
【讨论】:
以上是关于使用 react-native-camera 创建非常简单的应用程序时出错的主要内容,如果未能解决你的问题,请参考以下文章
如何使用带有 react-native-camera 的默认 iOS 相机控件
[RN] React Native 使用 react-native-camera 过程中报错 Found react-native-camera 'mlkit' but wasn