【问题标题】:Could not find com.android.support:appcompat-v7:25.3.1找不到 com.android.support:appcompat-v7:25.3.1
【发布时间】:2017-10-28 00:46:45
【问题描述】:

我在尝试构建时突然开始收到此错误。几周前这一切都在起作用,据我所知没有任何变化。这个问题似乎与react-native-fbsdk 有关,但通过它的build.gradle 并没有列出support.appcompat-v7.25.x。有什么建议吗?

A problem occurred configuring project ':app'.
> A problem occurred configuring project ':react-native-fbsdk'.
   > Could not resolve all dependencies for configuration ':react-native-fbsdk:_debugCompile'.
      > Could not find com.android.support:appcompat-v7:25.3.1.
        Searched in the following locations:
            file:/Users/a/.m2/repository/com/android/support/appcompat-v7/25.3.1/appcompat-v7-25.3.1.pom
            file:/Users/a/.m2/repository/com/android/support/appcompat-v7/25.3.1/appcompat-v7-25.3.1.jar
            https://jcenter.bintray.com/com/android/support/appcompat-v7/25.3.1/appcompat-v7-25.3.1.pom
            https://jcenter.bintray.com/com/android/support/appcompat-v7/25.3.1/appcompat-v7-25.3.1.jar

build.gradle

apply plugin: "com.android.application"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

import com.android.build.OutputFile

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "___"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 22
        versionName "1.5.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        manifestPlaceholders = [manifestApplicationId: "___",
                                onesignal_app_id: "___",
                                onesignal_google_project_number: "___"]
        multiDexEnabled true
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
    }
    signingConfigs {
      release {
        storeFile file(MYAPP_RELEASE_STORE_FILE)
        storePassword MYAPP_RELEASE_STORE_PASSWORD
        keyAlias MYAPP_RELEASE_KEY_ALIAS
        keyPassword MYAPP_RELEASE_KEY_PASSWORD
      }
    }
    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.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-device-info')
    compile project(':react-native-code-push')
    compile project(':react-native-image-crop-picker')
    compile project(':react-native-image-picker')
    compile project(':react-native-fs')
    compile project(':react-native-vector-icons')
    compile project(':react-native-material-kit')
    compile project(':react-native-config')
    compile project(':react-native-onesignal')
    compile project(':react-native-push-notification')
    compile project(':react-native-android-permissions')
    compile project(':react-native-android-keyboard-adjust')
    compile project(':react-native-fbsdk')
    compile (project(':react-native-fbads')) {
      exclude group: 'com.google.android.gms'
    }
    compile 'com.facebook.android:audience-network-sdk:4.18.+'
    compile 'com.google.ads.mediation:facebook:4.18.+'
    compile 'com.google.firebase:firebase-core:10.2.0'
    compile 'com.google.firebase:firebase-crash:10.2.0'
    compile 'com.google.firebase:firebase-ads:10.2.0'
    compile project(':react-native-billing')
    compile project(':react-native-blur')
    compile project(':instabug-reactnative')
    compile project(':mobile-center-analytics')
    compile project(':mobile-center-crashes')
    compile (project(':react-native-appodeal')) {
      exclude group: 'com.facebook.ads'
      exclude (group: 'javax.inject', module: 'javax.inject')
    }
    compile project(':cheetah')

    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile "com.facebook.fresco:animated-gif:0.12.0"
    compile "com.android.support:multidex:1.0.1"
}

task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 放你的gradle文件
  • 试试./gradlew --refresh-dependencies
  • 您设法解决了这个问题吗?我也发生了同样的事情,这个问题的建议答案都没有解决它
  • @MindaugasJačionis 是的,我刚刚为我的情况想通了。发布了答案。

标签: android react-native-android fbsdk react-native-fbsdk


【解决方案1】:

我在一个 android 项目上遇到了同样的问题 (appcompat-v7:25.3.1),但没有使用 react。

我首先尝试清理 gradle 缓存 (~/.gradle/caches),就像 here 解释的那样,但没有帮助。

然后我查看了 SDK 管理器。
Android 支持库通常通过 sdkmanager 安装。 然后将这些库存储在本地 maven 存储库中:<SDK_HOME>/sdk/extras/android/m2repository/

例如,对于appcompat-v7,安装的版本列表位于<SDK_HOME>/sdk/extras/android/m2repository/com/android/support/appcompat-v7/maven-metadata.xml
因此,对于 Android 支持存储库(修订:47.0.0),最后一个版本通常是 25.3.1

要解决我的问题,我必须通过 SDK 管理器卸载 Android Support Repository,然后重新安装

我还找到了另一种获取支持库的方法:远程。 在阅读此处 (https://developer.android.com/topic/libraries/support-library/setup.html#add-library) 并像这样修改<PROJECT_ROOT>/build.gradle 后:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

然后我尝试使用不在本地 maven 存储库中的 appcompat-v7:25.4.0 的较新版本,并且成功了!
可以在此处查看此库的此 Google Maven 存储库版本的列表:https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/maven-metadata.xml

【讨论】:

    【解决方案2】:

    按照步骤,

    1. 在项目 gradle (Project: build.gradle) 中添加 google maven,

      allprojects { repositories { jcenter() maven { url "https://maven.google.com" } } }

    2. 使用以下命令删除现有的 gradle cache

      rm -fr ~/.gradle/caches/

    3. 进行干净的构建并运行

    【讨论】:

    • 这应该是正确和最简单的答案。对我来说这不是必需的:rm -fr ~/.gradle/caches/
    【解决方案3】:

    我的情况是这是react-native-fbsdk build.gradle (https://github.com/facebook/react-native-fbsdk/blob/master/android/build.gradle):

    apply plugin: 'com.android.library'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
    
        defaultConfig {
            minSdkVersion 16
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.1.0'
        compile 'com.facebook.react:react-native:+' // support react-native-v0.22-rc+
        compile('com.facebook.android:facebook-android-sdk:4.+')
    }
    

    我使用的是 React Native 0.37,所以这对我来说是一条线:

    compile('com.facebook.android:facebook-android-sdk:4.+')
    

    为了兼容性不得不改成这个:

    compile('com.facebook.android:facebook-android-sdk:4.18.+')
    

    【讨论】:

    • 谢谢,这也是我的问题,我又回到了 React Native 0.22。
    【解决方案4】:

    为此,请尝试以下选项之一:

    1. 更新您的 SDK manager > 转到 build 菜单 > clean project > 然后 build project

    2.右键项目文件夹>打开module setting>libraries>添加com.android.support:appcompat-v7:25.3.1>sync项目

    3.点击file菜单>打开project structure>并归档libraries

    【讨论】:

    【解决方案5】:

    解决这个问题:

    1. 打开 package.json 并将 react 版本编辑为:

      "react": "16.0.0-alpha.3", "react-native": "0.43.1",

    2. 删除node_modules目录

    3. 然后使用命令npm install重新安装npm

    4. 另外:如果您收到 app:compileDebugJava 错误,请运行 react-native upgrade

    (从this github page 获得解决方案,它对我有用)

    【讨论】:

    • 酷,但我被困在 React Native 0.37 上。我觉得它不应该突然就这样坏掉。
    【解决方案6】:

    由于 gradle 还不支持基于每个工件声明存储库。

    我修改了我的 build.gradle(不是 app/build.gradle)以强制所有依赖项对特定版本反应原生:

    allprojects {
         configurations.all {
           resolutionStrategy {
             eachDependency { DependencyResolveDetails details ->
               if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native') {
                    def file = new File("$rootDir/../node_modules/react-native/package.json")
                    def version = new groovy.json.JsonSlurper().parseText(file.text).version
                    details.useVersion version
               }
             }
           }
         }
      }
    

    【讨论】:

    • 在 github 问题 github.com/facebook/react-native/issues/14223 中有一个稍微好一点的版本,它从已安装的 node_modules 中读取您的实际 react-native 版本,因此您不必在两个地方进行更新。
    【解决方案7】:

    这似乎是 react-native 本身的问题。 (目前)还没有官方修复,但是有些人报告说升级已经解决了他们的问题。您可以查看更多详情here

    更新 1: 嗨@roachman,这是我得到的确切错误,它让我在上面搜索。有另一张票记录 #14225 相同(由于某种原因无法发布链接)。我只是能够解决它,通过在 build.gradle 依赖行 compile "com.facebook.react:react-native:0.xx.y" 而不是 compile 'com.facebook.react:react-native:+' 中包含 react-native 版本的确切版本您可能想尝试 所有项目 使用该设置或用户 david50407 在上述问题 #14223 中建议的更优雅的设置

    更新 2 这是官方修复的现在看看https://github.com/facebook/react-native/issues/14225#issuecomment-305073392(必须删除问题 14223 的早期链接,因为我不能发布超过 2 个链接)

    【讨论】:

    • 这似乎与我遇到的问题不同。
    【解决方案8】:

    如果您将 react-native-fbsdk 从 0.5 升级到 0.6 版本并遇到此问题,请在 Android Studio 中打开您的 android 项目 (pathToYourApp/android),它会自动为您提供更新依赖项。现在它应该可以正常工作了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      相关资源
      最近更新 更多