react-native-svg: Build failing with 'Could not find method google() for arguments [] on repository container'

Message shown in console after react-native run-android:

Building and installing the app on the device (cd android && ./gradlew installDebug)...

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/jskidd3/Desktop/Apps/AppName/node_modules/react-native-svg/android/build.gradle' line: 4

* What went wrong:
A problem occurred evaluating project ':react-native-svg'.
> Could not find method google() for arguments [] on repository container.

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

BUILD FAILED

I installed the plugin in a fresh project on OSX. Versions:

react-native-cli: 2.0.1
react-native: 0.52.0
Android Studio: 3.0.1

My package.json looks like this:

{
  "name": "AppName",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.2.0",
    "react-native": "0.52.0",
    "react-native-svg": "^6.0.1-rc.3",
    "react-native-vector-icons": "^4.5.0"
  },
  "devDependencies": {
    "babel-jest": "22.1.0",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.1.4",
    "react-test-renderer": "16.2.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

Any ideas as to how I can fix this?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 35
  • Comments: 34

Most upvoted comments

Make sure you have v4.1 of the gradle wrapper as well: https://github.com/msand/SVGPodTest/blob/master/android/gradle/wrapper/gradle-wrapper.properties

#Thu Jan 18 18:05:34 EET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

Try changing to this:

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

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        google()
    }
}

@msand That gives me this:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/joelkidd/Desktop/Apps/MyApp/android/build.gradle' line: 6

* What went wrong:
A problem occurred evaluating root project 'MyApp'.
> Could not find method google() for arguments [] on repository container.

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

BUILD FAILED

Output from Gradle Build within Android Studio after clean & rebuild:

Information:Gradle tasks [clean, :app:assembleDebug, :react-native-maps:assembleDebug, :react-native-svg:assembleDebug]
Warning:The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (26.0.2) for Android Gradle Plugin 3.0.1.
Android SDK Build Tools 26.0.2 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
Warning:The specified Android SDK Build Tools version (25.0.3) is ignored, as it is below the minimum supported version (26.0.2) for Android Gradle Plugin 3.0.1.
Android SDK Build Tools 26.0.2 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
/Users/jskidd3/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.0.2.aar/59539aab2a9f3f2996f368b98efa0b8b/res/values-v26/values-v26.xml
Error:(9, 5) error: resource android:attr/colorError not found.
Error:(13, 5) error: resource android:attr/colorError not found.
Error:(17, 5) error: style attribute 'android:attr/keyboardNavigationCluster' not found.
/Users/jskidd3/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.0.2.aar/59539aab2a9f3f2996f368b98efa0b8b/res/values/values.xml
Error:(252, 5) error: resource android:attr/fontStyle not found.
Error:(252, 5) error: resource android:attr/font not found.
Error:(252, 5) error: resource android:attr/fontWeight not found.
Error:resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
Error:resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
/Users/jskidd3/Desktop/Apps/MyApp/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values-v26/values-v26.xml
Error:(7) resource android:attr/colorError not found.
Error:(11) resource android:attr/colorError not found.
Error:(15) style attribute 'android:attr/keyboardNavigationCluster' not found.
/Users/jskidd3/Desktop/Apps/MyApp/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml
Error:(171) resource android:attr/fontStyle not found.
Error:(171) resource android:attr/font not found.
Error:(171) resource android:attr/fontWeight not found.
Error:failed linking references.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 4s

Appreciate the fast responses whilst trying to sort this by the way 👍

When you open/build the project in the latest Android studio, it asks if you want it to make these upgrades for you.

same issue

It should mostly make it so that newer android version don’t need to run in backwards compatibility mode. The minSdkVersion 16 set the minimum sdk support level and decided how old versions it works with. https://medium.com/google-developers/picking-your-compilesdkversion-minsdkversion-targetsdkversion-a098a0341ebd

https://developer.android.com/training/basics/supporting-devices/platforms.html#sdk-versions

To maintain your application along with each Android release, you should increase the value of this attribute to match the latest API level, then thoroughly test your application on the corresponding platform version. https://developer.android.com/guide/topics/manifest/uses-sdk-element.html

Just delete the whole android folder and run a command to add.

I got the same error when I use react-native-sqlite-storage , only this website solve my problem , https://github.com/react-native-community/react-native-camera/blob/master/docs/GradleUpgradeGuide.md

Seems you’re using an older version of gradle. Make sure you have v4.1 in: android/gradle/wrapper/gradle-wrapper.properties

@@ -1,5 +1,6 @@ +#Mon Jan 29 13:59:51 EET 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip

Thanks for solving this but doesn’t updating the API to 25-27 make the apps using this module limited to supporting only 5% of the android market?

I had the same problem and I’ve resolved change the version of my “react-native-svg”: “^6.0.1-rc.1” to “react-native-svg”: “6.0.1-rc.1” and run again npm install .

My react-native-svg module had the version: [Error] error-react-native-svg

Now its probably the app specific build.gradle file: android/app/build.gradle

@@ -94,12 +94,12 @@ def enableSeparateBuildPerCPUArchitecture = false
 def enableProguardInReleaseBuilds = false
 
 android {
-    compileSdkVersion 25
+    compileSdkVersion 27
 
     defaultConfig {
         applicationId "com.svgpodtest"
         minSdkVersion 16
-        targetSdkVersion 25
+        targetSdkVersion 27
         versionCode 1
         versionName "1.0"
         ndk {
@@ -138,7 +138,7 @@ android {
 dependencies {
     compile project(':react-native-svg')
     compile fileTree(dir: "libs", include: ["*.jar"])
-    compile "com.android.support:appcompat-v7:25.4.0"
+    compile "com.android.support:appcompat-v7:27.0.2"
     compile "com.facebook.react:react-native:+"  // From node_modules
 }