安装react-native-camera遇Gradle同步失败:找不到google()方法
Hey there, let's work through this Gradle sync error you're hitting with react-native-camera. That error usually boils down to an outdated Gradle setup that doesn't support the google() repository shortcut—here's how to fix it step by step:
1. Upgrade Gradle and Android Build Plugin
The google() method was introduced in Gradle 4.1+ and Android Plugin for Gradle 3.0.0+. Your current setup is likely using older versions that don't recognize this method.
Update root-level build.gradle
Open your project's root build.gradle file and update the buildscript and allprojects sections:
buildscript { repositories { google() // Add this first jcenter() } dependencies { // Use a plugin version compatible with your React Native version (3.2.1 works for most RN 0.50+ setups) classpath 'com.android.tools.build:gradle:3.2.1' } } allprojects { repositories { mavenLocal() google() // Include google() here too jcenter() maven { url "https://jitpack.io" } maven { url "$rootDir/../node_modules/react-native/android" } } }
Update Gradle wrapper version
Navigate to android/gradle/wrapper/gradle-wrapper.properties and set the distribution URL to match your plugin version:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
This version pairs perfectly with the 3.2.1 Android plugin we specified.
2. Verify react-native-camera Configuration
Since you already started manual linking, double-check these details:
- In
android/settings.gradle, ensure you have:include ':react-native-camera' project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') - In
android/app/build.gradle, confirm the ExifInterface dependency is set to 27.+:dependencies { // ... other dependencies compile 'com.android.support:exifinterface:27.+' }
3. Clean and Rebuild
Finally, clear any cached build files to avoid leftover issues:
- Open a terminal, navigate to your project's
androidfolder - Run
./gradlew clean - Restart Android Studio and trigger a Gradle sync
This should resolve the google() method error, as your build setup will now support the modern repository syntax required by react-native-camera.
内容的提问来源于stack exchange,提问作者Green Eagle

