在本机升级后,如何包括必需的appcompat库?

时间:2019-06-17 05:12:57

标签: android react-native gradle android-appcompat

我已更新为反应型0.59.9,以支持64位APK创建-https://medium.com/@andriidrozdov/reactnative-and-android-64-bit-new-google-play-market-rules-what-to-do-584b067d6f1a

 "react": "16.8.3",
 "react-native": "0.59.9",

但是在使用react-native run-android运行应用程序之后,它会引发构建异常:

A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
   > Could not find com.android.support:appcompat-v7:28.0.0.
     Searched in the following locations:
         file:/C:/Users/brian-varley/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/28.0.0/appcompat-v7-28.0.0.pom

当我搜索appcompat-v7-28.0.0的给定路径时。我发现缺少28.0.0,而我拥有的最新I版本是26.0.0-alpha1。这里有一个类似的问题,但答案无法解决此本机项目中缺少的appcompat lib:Failed to resolve: com.android.support:appcompat-v7:28.0

问题

如何在本机项目中安装缺少的appcompat-v7库?

这些是我的应用程序和项目级别的build.gralde文件,显示了已定义的依赖项和存储库。

项目级别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"
        }
    }
}

应用程序级别build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile


def enableSeparateBuildPerCPUArchitecture = false

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

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.1"

    defaultConfig {
        applicationId "com.simple-offset-pro"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86", "x86_64"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "x86_64"
        }
    }
    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, "x86_64":3]
            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 fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:28.0.0"
    compile "com.facebook.react:react-native:+"  // 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
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

1 个答案:

答案 0 :(得分:1)

Android不建议编译。使用实现或API。

并添加以管理依赖项。

android{
      ...
configurations.all {
    resolutionStrategy.force "com.android.support:appcompat-v7:28.0.0"
   }
}
...
dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:28.0.0"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}