LoginSignup
2
2

More than 5 years have passed since last update.

react-native-qrcode-scannerのAndroidで詰まった話

Posted at

はじめに

検証時のデバイスは「Android 7.0」です。

詰まった箇所

iOSでは動くが、Androidで動作しない。

react-native-qrcode-scanner」を使うとこんなエラーがでる

FAILURE: Build failed with an exception.

* Where:
Build file '/YOUR_WORKING_FOLDER/react-native-apps/react-native-qrcode-scanner-test/node_modules/react-native-camera/android/build.gradle' line: 8

* What went wrong:
A problem occurred evaluating project ':react-native-camera'.
> Could not find method google() for arguments [] on repository container of type org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.305 secs
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

解決策

gradleの更新

gradle-3.5.1-all.zipのままだと、google()がないとかでエラーがでますが
gradle-4.1-all.zipにしたら出なくなりました。

/YOUR_WORKING_FOLDER/react-native-apps/react-native-qrcode-scanner-test/android/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.zip
↓
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

gradleを更新した際は「classpath」もアップデートしないとビルドで失敗します。

/YOUR_WORKING_FOLDER/react-native-apps/react-native-qrcode-scanner-test/android/build.gradle
dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
↓
dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

注意

gradleの変更でライブラリーによってはエラーがでるかもなので、導入する際は要注意です。(今の所はエラーにぶつかってないですが。。)

参考サイト

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2