【问题标题】:How can I solve this dependency issue in android studio?如何在 android studio 中解决这个依赖问题?
【发布时间】:2019-07-11 23:15:04
【问题描述】:

我开始在 android studio 中构建一个项目,在添加了一些 firebase 身份验证依赖项后遇到了这个问题.. 'com.android.support:appcompat-v7:28.0.0' 下似乎有一条弯曲的红线。

这是 gradle 应用代码:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.aden.adenmarket"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.google.firebase:firebase-core:17.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-auth:18.0.0'
}
apply plugin: 'com.google.gms.google-services'

这是项目 gradle:

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

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath 'com.google.gms:google-services:4.2.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

....... 这是输出错误:

错误:清单合并失败:uses-sdk:minSdkVersion 15 不能 小于库中声明的版本 16 [com.google.firebase:firebase-auth:18.0.0] C:\Users\PC.gradle\caches\transforms-2\files-2.1\ce1ab53339b3343f02313d46e1b6166b\AndroidManifest.xml 因为该库可能正在使用 15 建议中不可用的 API: 使用 minSdk 最多为 15 的兼容库,或增加 这个项目的 minSdk 版本至少要 16,或者使用 tools:overrideLibrary="com.google.firebase.auth" 强制使用(可能 导致运行时失败)

【问题讨论】:

    标签: java android


    【解决方案1】:

    尝试将 minSdkVersion 更改为 16。

    【讨论】:

    • 错误:清单合并失败:属性 application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) 来自 [com.android.support:support-compat:28.0.0] AndroidManifest.xml :22:18-91 也出现在 [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory)。建议:在 AndroidManifest.xml:5:5-29:19 的 元素中添加 'tools:replace="android:appComponentFactory"' 以覆盖。
    • 你不能混合使用 androidx 和 anroid.support 库!要么使用旧的 android.support 东西,要么完全切换到 androidx
    • 如何切换到androidx?
    【解决方案2】:
    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.aden.adenmarket"
            minSdkVersion 16
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        } }
    

    在 gradle 文件中将 minSDK 更改为 16 如果您有其他带有 gradles 的本地库,也请更改它们

    【讨论】:

    • 解析失败:com.android.support:appcompat-v7:28.0.3
    • 我复制并粘贴了您的代码并替换了它们...之前的错误已经消失,但随后出现此错误:无法解决:com.android.support:appcompat-v7:28.0.3 我不不知道怎么解决这个问题。
    • @DangerZone 将其更改为 v7:28.0.0
    【解决方案3】:

    更新项目 build.gradle

    buildscript {
        repositories {
            jcenter()
            mavenCentral()
            google()
            maven { url 'http://repo.maven.apache.org/maven2' }
            maven {
              url 'https://maven.fabric.io/public'
            }
        }
        dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.2.0'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
    
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    应用模块分级:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 28
        buildToolsVersion 28.0.3
        defaultConfig {
            applicationId "com.aden.adenmarket"
            minSdkVersion 19
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        implementation 'com.android.support:design:28.0.0'
        implementation 'com.android.support:support-v4:28.0.0'
        implementation 'com.google.firebase:firebase-core:17.0.0'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.google.firebase:firebase-auth:18.0.0'
    }
    apply plugin: 'com.google.gms.google-services'
    

    如果它显示在 lint 中,也更新其他依赖项。

    【讨论】:

    • 解析失败:com.android.support:appcompat-v7:28.0.3
    • 我已经更新了项目级别的build.gradle。试试看,然后告诉我。
    • 编辑了两个 gradle 文件。试着让我知道。
    【解决方案4】:
    猜你喜欢
    • 2011-11-07
    • 1970-01-01
    • 2015-05-01
    • 2021-07-21
    • 1970-01-01
    • 2019-02-23
    • 1970-01-01
    • 2020-10-01
    • 2022-01-12
    相关资源
    最近更新 更多