如何安装依赖项以迁移到androidx

时间:2019-07-08 11:29:10

标签: android gradle androidx

我正在尝试构建我的react-native应用程序,但它返回此错误:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:lintVitalRelease'.
> Could not resolve all task dependencies for configuration ':app:releaseRuntimeClasspath'.
   > Could not find any version that matches androidx.appcompat:appcompat:28.+.
     Versions that do not match:
       - 1.1.0-rc01
       - 1.1.0-beta01
       - 1.1.0-alpha05
       - 1.1.0-alpha04
       - 1.1.0-alpha03
       - + 10 more
     Searched in the following locations:
       - file:/Users/myuser/Library/Android/sdk/extras/m2repository/androidx/appcompat/appcompat/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/m2repository/androidx/appcompat/appcompat/
       - file:/Users/myuser/Library/Android/sdk/extras/google/m2repository/androidx/appcompat/appcompat/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/google/m2repository/androidx/appcompat/appcompat/
       - file:/Users/myuser/Library/Android/sdk/extras/android/m2repository/androidx/appcompat/appcompat/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/android/m2repository/androidx/appcompat/appcompat/
       - https://jitpack.io/androidx/appcompat/appcompat/maven-metadata.xml
       - https://jitpack.io/androidx/appcompat/appcompat/
       - https://maven.google.com/androidx/appcompat/appcompat/maven-metadata.xml
       - file:/Users/myuser/.m2/repository/androidx/appcompat/appcompat/maven-metadata.xml
       - file:/Users/myuser/.m2/repository/androidx/appcompat/appcompat/
       - https://dl.google.com/dl/android/maven2/androidx/appcompat/appcompat/maven-metadata.xml
       - file:/Users/myuser/myproject/node_modules/react-native/android/androidx/appcompat/appcompat/maven-metadata.xml
       - file:/Users/myuser/myproject/node_modules/react-native/android/androidx/appcompat/appcompat/
       - https://maven.google.com/androidx/appcompat/appcompat/maven-metadata.xml
       - https://jcenter.bintray.com/androidx/appcompat/appcompat/maven-metadata.xml
       - https://jcenter.bintray.com/androidx/appcompat/appcompat/
     Required by:
         project :app > project :react-native-device-info
         project :app > project :react-native-splash-screen
         project :app > project :react-native-maps
   > Could not find any version that matches androidx.legacy:legacy-support-v4:28.+.
     Versions that do not match:
       - 1.0.0
       - 1.0.0-rc02
       - 1.0.0-rc01
       - 1.0.0-beta01
       - 1.0.0-alpha3
       - + 1 more
     Searched in the following locations:
       - file:/Users/myuser/Library/Android/sdk/extras/m2repository/androidx/legacy/legacy-support-v4/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/m2repository/androidx/legacy/legacy-support-v4/
       - file:/Users/myuser/Library/Android/sdk/extras/google/m2repository/androidx/legacy/legacy-support-v4/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/google/m2repository/androidx/legacy/legacy-support-v4/
       - file:/Users/myuser/Library/Android/sdk/extras/android/m2repository/androidx/legacy/legacy-support-v4/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/android/m2repository/androidx/legacy/legacy-support-v4/
       - https://jitpack.io/androidx/legacy/legacy-support-v4/maven-metadata.xml
       - https://jitpack.io/androidx/legacy/legacy-support-v4/
       - https://maven.google.com/androidx/legacy/legacy-support-v4/maven-metadata.xml
       - file:/Users/myuser/.m2/repository/androidx/legacy/legacy-support-v4/maven-metadata.xml
       - file:/Users/myuser/.m2/repository/androidx/legacy/legacy-support-v4/
       - https://dl.google.com/dl/android/maven2/androidx/legacy/legacy-support-v4/maven-metadata.xml
       - file:/Users/myuser/myproject/node_modules/react-native/android/androidx/legacy/legacy-support-v4/maven-metadata.xml
       - file:/Users/myuser/myproject/node_modules/react-native/android/androidx/legacy/legacy-support-v4/
       - https://maven.google.com/androidx/legacy/legacy-support-v4/maven-metadata.xml
       - https://jcenter.bintray.com/androidx/legacy/legacy-support-v4/maven-metadata.xml
       - https://jcenter.bintray.com/androidx/legacy/legacy-support-v4/
     Required by:
         project :app > project :react-native-device-info
         project :app > project :react-native-firebase
   > Could not find any version that matches androidx.media:media:28.+.
     Versions that do not match:
       - 1.1.0-rc01
       - 1.1.0-beta02
       - 1.1.0-beta01
       - 1.1.0-alpha04
       - 1.1.0-alpha03
       - + 9 more
     Searched in the following locations:
       - file:/Users/myuser/Library/Android/sdk/extras/m2repository/androidx/media/media/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/m2repository/androidx/media/media/
       - file:/Users/myuser/Library/Android/sdk/extras/google/m2repository/androidx/media/media/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/google/m2repository/androidx/media/media/
       - file:/Users/myuser/Library/Android/sdk/extras/android/m2repository/androidx/media/media/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/android/m2repository/androidx/media/media/
       - https://jitpack.io/androidx/media/media/maven-metadata.xml
       - https://jitpack.io/androidx/media/media/
       - https://maven.google.com/androidx/media/media/maven-metadata.xml
       - file:/Users/myuser/.m2/repository/androidx/media/media/maven-metadata.xml
       - file:/Users/myuser/.m2/repository/androidx/media/media/
       - https://dl.google.com/dl/android/maven2/androidx/media/media/maven-metadata.xml
       - file:/Users/myuser/myproject/node_modules/react-native/android/androidx/media/media/maven-metadata.xml
       - file:/Users/myuser/myproject/node_modules/react-native/android/androidx/media/media/
       - https://maven.google.com/androidx/media/media/maven-metadata.xml
       - https://jcenter.bintray.com/androidx/media/media/maven-metadata.xml
       - https://jcenter.bintray.com/androidx/media/media/
     Required by:
         project :app > project :react-native-device-info
   > Could not find any version that matches androidx.exifinterface:exifinterface:28.+.
     Versions that do not match:
       - 1.1.0-beta01
       - 1.1.0-alpha01
       - 1.0.0
       - 1.0.0-rc02
       - 1.0.0-rc01
       - + 3 more
     Searched in the following locations:
       - file:/Users/myuser/Library/Android/sdk/extras/m2repository/androidx/exifinterface/exifinterface/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/m2repository/androidx/exifinterface/exifinterface/
       - file:/Users/myuser/Library/Android/sdk/extras/google/m2repository/androidx/exifinterface/exifinterface/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/google/m2repository/androidx/exifinterface/exifinterface/
       - file:/Users/myuser/Library/Android/sdk/extras/android/m2repository/androidx/exifinterface/exifinterface/maven-metadata.xml
       - file:/Users/myuser/Library/Android/sdk/extras/android/m2repository/androidx/exifinterface/exifinterface/
       - https://jitpack.io/androidx/exifinterface/exifinterface/maven-metadata.xml
       - https://jitpack.io/androidx/exifinterface/exifinterface/
       - https://maven.google.com/androidx/exifinterface/exifinterface/maven-metadata.xml
       - file:/Users/myuser/.m2/repository/androidx/exifinterface/exifinterface/maven-metadata.xml
       - file:/Users/myuser/.m2/repository/androidx/exifinterface/exifinterface/
       - https://dl.google.com/dl/android/maven2/androidx/exifinterface/exifinterface/maven-metadata.xml
       - file:/Users/myuser/myproject/node_modules/react-native/android/androidx/exifinterface/exifinterface/maven-metadata.xml
       - file:/Users/myuser/myproject/node_modules/react-native/android/androidx/exifinterface/exifinterface/
       - https://maven.google.com/androidx/exifinterface/exifinterface/maven-metadata.xml
       - https://jcenter.bintray.com/androidx/exifinterface/exifinterface/maven-metadata.xml
       - https://jcenter.bintray.com/androidx/exifinterface/exifinterface/
     Required by:
         project :app > project :react-native-camera

我的build.gradle文件具有:

android.useAndroidX=true
android.enableJetifier=true

我的app / build.gradle文件具有:

implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"

我也尝试过:

implementation "com.android.support:appcompat-v7:28.+"

在Android Studio中打开项目,“迁移到AndroidX”按钮不会出现。

我在做什么错了?

对不起,我是Java的新手,对如何处理它一无所知:(


这是我的build.gradle文件

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

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 23
        compileSdkVersion = 28
        targetSdkVersion = 26
        supportLibVersion = "28.0.0"
        playServicesVersion = "16.0.0"
    }
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:4.0.1'

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

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

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "28.0.0"
            }
        }
    }
    afterEvaluate {
        android {
            compileSdkVersion 28
            buildToolsVersion "27.0.3"

            defaultConfig {
                targetSdkVersion 27
            }
        }
    }
}

ext {
    buildToolsVersion = "27.0.3"
    minSdkVersion = 16
    compileSdkVersion = 28
    targetSdkVersion = 27
    supportLibVersion = "27.1.0"
}

3 个答案:

答案 0 :(得分:0)

最有可能在未看到build.gradle的情况下迁移了完整版本号:

implementation "com.android.support:appcompat-v7:28.0.0"

答案 1 :(得分:0)

尝试一下

implementation "com.android.support:appcompat-v7:28.0.0"

28.0.0应用程序兼容转换为androidx之后,因此“ androidx .....:1.0.0”本身就是implementation "com.android.support:appcompat-v7:29.0.0"

support:appcompat不得大于“ 28.0.0”

答案 2 :(得分:0)

Android Studio在菜单栏中提供了一个将现有android项目迁移到Androidx的选项。菜单->重构-迁移到AndroidX