26

This is a React Native project. Worked fine on another machine but once moved to my machine it fails.

Most solutions I found, suggested adding jcenter() to the reposistories of project level gradle.build. In my case, it was already added.

Gradle sync fails with this error:

Could not find any matches for com.android.tools.build:gradle:2.2.+ as no versions of com.android.tools.build:gradle are available. Searched in the following locations: https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml https://jcenter.bintray.com/com/android/tools/build/gradle/ Required by: project :react-native-image-picker

Android build.gradle file:

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

buildscript {
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        jcenter()

    dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'    }
}

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

       maven { url 'https://jitpack.io' }
    }
}

ext {
    buildToolsVersion = "27.0.3"
    minSdkVersion = 19
    compileSdkVersion = 26
    targetSdkVersion = 26
    supportLibVersion = "26.1.0"

    googlePlayServicesVersion = "11.8.0"
    androidMapsUtilsVersion = "0.5+"
}
subprojects { subproject ->
    afterEvaluate {
        if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                variantFilter { variant ->
                    def names = variant.flavors*.name
                    if (names.contains("reactNative51") || names.contains("reactNative55")) {
                        setIgnore(true)
                    }
                }
            }
        }
    }
}
}

App build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.sos"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
  missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57"

        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
        signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release

        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support' && requested.name != 'multidex') {
            details.useVersion "${rootProject.ext.supportLibVersion}"
        }
    }
}
dependencies {
    implementation project(':react-native-fetch-blob')
    implementation project(':react-native-linear-gradient')
    implementation project(':react-native-maps')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-vector-icons')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation project(':react-native-navigation')
    implementation 'com.android.support:design:25.4.0'
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation project(':react-native-maps')
}


// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

By the way, in app build.gralde file, the android in import com.android.build.OutputFile throws an error: can't be resolved

Edit:

Now that part of the build process is already passed, succesfully, but I started to get this error: Unable to find a matching configuration of project :react-native-fetch-blob: None of the consumable configurations have attributes.

enter image description here

M.Ricciuti
  • 11,070
  • 2
  • 34
  • 54
Abdulrahman Hassoun
  • 1,151
  • 1
  • 9
  • 15

7 Answers7

28

If you don't want to wait until this library will release fixed version, here is how you can fix it:

Just add it to your build.gradle under subprojects section in the root (not app/gradle)

subprojects {
    if (project.name.contains('react-native-image-picker') || 
        project.name.contains('react-native-vector-icons')) {
        buildscript {
            repositories {
                jcenter()
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}

credit goes to https://github.com/akolpakov

Mukundhan
  • 3,284
  • 23
  • 36
10

This is a new issue which was addressed in the new version of react-native-image-picker Go to your root folder and reinstall react-native-image-picker:

npm install --save react-native-image-picker

Then go to your root folder and ensure that your react-native-image-picker is on version "^0.27.2"

David A Six
  • 360
  • 2
  • 5
  • 1
    Thanks! This solved that particular issue, I am having a new one now but at least that part of the build is passed! Now I am getting ```Unable to find a matching configuration of project :react-native-fetch-blob: None of the consumable configurations have attributes.``` – Abdulrahman Hassoun Dec 11 '18 at 07:27
4

The react-native-vector-icons package also encounters the same problem.

Is that caused by these two broken repositories?

https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml
https://jcenter.bintray.com/com/android/tools/build/gradle/

They both response "The requested path was not found."

Edit

Based on the log information:

project :react-native-vector-icons 
com.intellij.openapi.externalSystem.model.ExternalSystemException: 
Could not find any matches for com.android.tools.build:gradle:2.3.+ as 
no versions of com.android.tools.build:gradle are available.

search the '2.3.+' and replace it with explicit version # (e.g. 2.3.0) The problem will be solved.

I have read the suggestion from Android about avoiding the use of + in version code, that suggestion might be enforced now.

吳強福
  • 373
  • 1
  • 2
  • 18
  • 1
    you mean to change the dependencies in the react-native-vector-icons package right? that seems like a quickfix that can backfire soon :P – mezod Dec 11 '18 at 17:46
  • 1
    Upgrading react-native-vector-icons to 6.0.2 seems to do the trick and you don't need to mess with node_modules :) – mezod Dec 11 '18 at 18:12
4

On the day this question was made - 2018-12-10 - there was an issue lasting for over a day because JCenter received a request from Google to remove several binaries from their repository:

Google asked us to stop providing their binaries. Please use the official Google repository for them. https://twitter.com/bintray/status/1072275597315923971

If you need an immediate workaround, the best course of action would be to add any dependencies you need directly with their Maven URL. E.g.: repositories { (...) maven { url 'https://dl.bintray.com/android/android-tools' } } https://issuetracker.google.com/issues/120759347#comment3

The thread above is a good place to follow the resolution of the issue as it's still ongoing as I write this.

Danilo Moret
  • 1,580
  • 1
  • 10
  • 10
4

It looks like some repos were removed by mistake, and according to a Google representative it's something they are currently working on restoring:

https://issuetracker.google.com/issues/120759347#comment30

Hello again everyone,

We now know what happened, and are working on rolling it back in a sensible way. Here's a basic outline of the problem:

  1. There were some bogus/malformed com.google.* and com.android.* artifacts on jCenter
  2. Most of these artifacts were properly hosted on maven.google.com (aka google())
  3. If your build system found the jCenter version before it found the Google Maven version, your build would break
  4. Google noticed this and asked jFrog to remove basically everything under com.google.* and com.android.* because we assumed it was all on Google Maven as well
  5. We were wrong :-(
  6. Some artifacts deleted from jCenter are causing errors in your builds

We are working on doing a few things:

  • Some libraries that were deleted are being pushed to Google Maven. This includes the com.google.gms:google-services plugin, the firebase performance plugin, and Exoplayer. Try adding google() to your buildscript and app repositories blocks to see if that helps. We expect this to help many people, but not everyone. * We are working to make a list of which libraries were improperly deleted. Some of the things deleted in step #4 above were done for good reason, so we don't want to restore those as well.

As I said before, we hate that we broke your builds and we appreciate your patience while we fix it!

  • Sam

They also suggest the following workarounds in the meantime:

https://issuetracker.google.com/issues/120759347#comment36

STATUS

  • The Google Services library (com.google.gms:google-services) library has been restored, see update #31.
  • Requests have been submitted to jCenter to re-publish all repositories hosted on bintray.com/google. The jCenter admins at JFrog are working to get them back online for us, at this point all we can do is wait. We expect them to come online soon. Some libraries are already back.
  • Some Android/Firebase libraries that were dual-homed on both jcenter.bintray.com and maven.google.com are missing older versions (previously hosted on jCenter). We're still working at getting these back online in either jcenter.bintray.com or maven.google.com, as appropriate -- we're working carefully here to avoid re-creating the initial conflicts that caused problems. Work is ongoing. Newer versions of these libraries are unaffected, as they're available on maven.google.com.

WORKAROUNDS

  1. For the Google Services library, no workaround is necessary. This library is already restored. Other libraries in /google are in the progress of being restored as well.
  2. For projects served from bintray.com/android or bintray.com/firebase that are not resolving, consider upgrading to a newer version that is already hosted on maven.google.com. (See below if this is not feasible.)
  3. For projects from bintray.com/google, or if you are unable to upgrade to a newer version of a Android or Firebase library...you will need to temporarily add a block similar to the following to your build.gradle:

    repositories { maven { url "https://google.bintray.com/$(REPOSITORY)" } }

    Replace $(REPOSITORY) with the project name from https://bintray.com/google.

    For bintray.com/firebase, use "https://firebase.bintray.com/$(REPOSITORY)". For bintray.com/android, use "https://dl.bintray.com/android/$(REPOSITORY)".

    Again, this workaround is only temporary until we can get all versions either re-listed in jCenter or mirrored into maven.google.com.

INVESTIGATION

The request submitted to de-list projects from jCenter appears to have been overly broad, and was submitted by another team at Google that did not have full authority to make that change. The repository admins at Google were not consulted before this request was executed by jCenter. We'll be looking into this more in the days to come, right now our first priority is in restoring access to all versions of affected libraries.

Additionally, it appears that there may be a misconfiguration in Google's repository that is preventing mirroring from maven.google.com into jCenter, which in turn was the cause of the initial takedown request. Correcting this misconfiguration may have avoided the need to remove anything. Additional followup is occurring internally.

Eric
  • 573
  • 1
  • 5
  • 11
2

Try using the exact version of gradle it worked for me

classpath 'com.android.tools.build:gradle:2.2.3'

warl0ck
  • 3,356
  • 4
  • 27
  • 57
1

For people coming across this error with react-native-vector-icons package:

  1. Upgrade "react-native-vector-icons": "^6.0.2" in package.json

Source: https://github.com/oblador/react-native-vector-icons/issues/605#issuecomment-446081342

mezod
  • 2,313
  • 3
  • 21
  • 31