安装react-native-camera后确认此错误 . 尝试改变版本和sdk工具,如git中的一些答案所示,但没有解决方案

错误:找不到com.android.tools.build:gradle:3.1.2 . 在以下位置搜索:file:/ Applications / Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.pom文件:/ Applications / Android Studio .app / Contents / gradle / m2repository / com / android / tools / build / gradle / 3.1.2 / gradle-3.1.2.jar https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.pom https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.jar必需者:project:react-native-push-notification打开文件

我的gradle-wrapper.properties-

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

我的android / build.gradle-

buildscript {
  repositories {
    jcenter()
    google()
    maven {
      url 'https://maven.google.com'
    }
  }

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

apply plugin: 'com.android.library'

def DEFAULT_COMPILE_SDK_VERSION             = 26
def DEFAULT_BUILD_TOOLS_VERSION             = "26.0.1"
def DEFAULT_TARGET_SDK_VERSION              = 26
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION    = "12.0.1"
def DEFAULT_SUPPORT_LIBRARY_VERSION         = "27.1.0"

android {
  compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
  buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION

  defaultConfig {
    minSdkVersion 16
    targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION

    versionCode 1
    versionName "1.0.0"
  }
  lintOptions {
    abortOnError false
    warning 'InvalidPackage'
  }
}

repositories {
  mavenCentral()
  maven {
   url 'https://maven.google.com'
  }
  maven { url "https://jitpack.io" }
  maven {
    // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
    url "$rootDir/../node_modules/react-native/android"
  }
}

dependencies {
  def googlePlayServicesVersion = rootProject.hasProperty('googlePlayServicesVersion')  ? rootProject.googlePlayServicesVersion : DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
  def supportLibVersion = rootProject.hasProperty('supportLibVersion')  ? rootProject.supportLibVersion : DEFAULT_SUPPORT_LIBRARY_VERSION

  compileOnly 'com.facebook.react:react-native:+'
  compileOnly 'com.facebook.infer.annotation:infer-annotation:+'
  implementation "com.google.zxing:core:3.2.1"
  implementation "com.drewnoakes:metadata-extractor:2.9.1"
  implementation "com.google.android.gms:play-services-vision:$googlePlayServicesVersion"
  implementation "com.android.support:exifinterface:$supportLibVersion"
  implementation "com.android.support:support-annotations:$supportLibVersion"
  implementation "com.android.support:support-v4:$supportLibVersion"
}



my app file-
apply plugin: "com.android.application"

import com.android.build.OutputFile
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.myappname"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // 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
            }
        }
    }
}

dependencies {
    compile project(':react-native-camera')
    compile project(':react-native-vector-icons')
    compile project(':react-native-restart')
    compile project(':react-native-push-notification')
    compile project(':react-native-maps')
    compile project(':react-native-i18n')
//    compile project(':react-native-vector-icons')
//    compile project(':react-native-restart')
//    compile project(':react-native-push-notification')
//    compile project(':react-native-maps')
//    compile project(':react-native-i18n')
    compile project(':react-native-vector-icons')
    compile project(':react-native-restart')
    compile project(':react-native-push-notification')
    compile(project(':react-native-maps')) {
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    compile 'com.google.android.gms:play-services-base:11.0.2'
    compile 'com.google.android.gms:play-services-maps:11.0.2'
    compile 'com.google.android.gms:play-services-location:11.0.2'
    compile project(':react-native-i18n')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile "com.android.support:appcompat-v7:23.4.1"
    compile ("com.facebook.react:react-native:0.53.3") { force = true }  // From node_modules
}

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

myAppname文件 -

// 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.1.2 '

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

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

回答(1)

2 years ago

这仅与版本有关 . 尝试下面提到的更改,这可能会有所帮助 .

gradle-wrapper.properties -

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

android / build.gradle -

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