20

我在尝试构建时突然开始收到此错误。几周前这一切都在工作,据我所知没有任何变化。这个问题似乎与它有关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

构建.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'
4

8 回答 8

15

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

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

然后我查看了 SDK Manager。
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 Support Repository (revision: 47.0.0),最后一个版本通常是25.3.1

为了解决我的问题,我必须通过 SDK Manager卸载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 。

于 2017-06-15T19:44:34.447 回答
10

按照步骤,

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

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

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

    rm -fr ~/.gradle/caches/

  3. 进行干净的构建并运行
于 2019-07-04T07:04:59.073 回答
6

我的情况是这是react-native-fbsdkbuild.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.+')
于 2017-05-30T02:44:54.027 回答
2

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

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

或者

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

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

于 2017-05-27T05:21:14.330 回答
0

由于 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
           }
         }
       }
     }
  }
于 2017-05-30T09:19:49.650 回答
0

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

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

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

于 2017-05-29T11:00:28.230 回答
0

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

于 2017-06-06T19:15:08.073 回答
0

要解决这个问题:

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

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

  2. 删除 node_modules 目录

  3. 并使用命令重新安装 npmnpm install

  4. 另外:如果你得到一个app:compileDebugJava错误,运行react-native upgrade

(从这个 github 页面获得了解决方案,它对我有用)

于 2017-05-29T12:45:02.343 回答