android - Gradle 未在 Android Studio 中安装依赖项

标签 android android-studio android-gradle-plugin react-native

我有一个 React native 应用程序,我无法构建它,因为依赖项不可用。 View full error output ,或者这个 fragment :

> Could not resolve all dependencies for configuration ':app:_debugApk'.
   > A problem occurred configuring project ':react-native-admob'.
      > Could not resolve all dependencies for configuration ':react-native-admob:_debugPublishCopy'.
         > Could not find com.android.support:support-core-ui:25.2.0.
           Required by:
               TennisAce:react-native-admob:unspecified
               TennisAce:react-native-admob:unspecified > com.facebook.react:react-native:0.42.3 > com.android.support:appcompat-v7:23.0.1 > com.android.support:support-v4:25.2.0
               TennisAce:react-native-admob:unspecified > com.facebook.react:react-native:0.42.3 > com.android.support:appcompat-v7:23.0.1 > com.android.support:support-v4:25.2.0 > com.android.support:support-fragment:25.2.0

在 Android Studio 中,我尝试了几次将项目与 Gradle 文件同步,但没有安装依赖项。

我尝试过使缓存无效/重新启动,之后 Gradle 构建失败并出现相同的错误

这是我的android/build.gradle 文件

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

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

        // 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"
        }
    }
}

这是我的android/app/build.gradle 文件

apply plugin: "com.android.application"

import com.android.build.OutputFile

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

def enableSeparateBuildPerCPUArchitecture = false

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

android {
    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
            }
        }
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        applicationId "com.tennisace"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 5
        versionName "1.1"
        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"
            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
            }
        }
    }
}

dependencies {
    compile project(':react-native-admob')
    compile project(':react-native-photo-view')
    compile project(':react-native-share')
    compile project(':react-native-linear-gradient')
    compile project(':react-native-vector-icons')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.facebook.react:react-native:+'
    // From node_modules
    compile 'com.google.android.gms:play-services-base:+'
    compile 'com.google.android.gms:play-services-ads:+'
    compile project(':react-native-onesignal')
    compile project(':react-native-billing')
}

// 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'
}

最佳答案

您可以尝试在存储库中添加 google(),如 * 之间所示

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

        // 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"
        }
    }
}

关于android - Gradle 未在 Android Studio 中安装依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45205868/

相关文章:

android - 向上导航和工具栏标题之间​​的空间太大

android - 如何升级安装在.gradle文件夹中的appengine-java-sdk

android - 无法解析 com.google.android.gms :play-services-measurement-base:[18. 0.0]

android - 运行程序的主要功能

android - "Device already has a newer version"错误

java - 适用于 Android 的 BBC iPlayer 广播应用程序 - 滚轮导航

javascript - 为什么在Android中旋转屏幕时setIntervals不能被杀死?

带有multidex的Android ClassNotFound

java - 不兼容的类型,发现 List<capture<?仅在 Java 8 中扩展模型>>

android - 禁用gradle中的特定 Activity 库