【问题标题】:Gradle dependencies in Android StudioAndroid Studio 中的 Gradle 依赖项
【发布时间】:2019-09-22 04:33:34
【问题描述】:

android studio 中的 gradle 文件出错。

  apply plugin: 'com.android.application'

应用插件:'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.mih.demo2"
        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'
        }
    }
}

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.google.firebase:firebase-core:16.0.4'
    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'
}

实现“com.android.support:appcompat-v7:28.0.0”时出错

指导我在 android studio 中解决此错误。我搜索了很多,但找不到解决方案。

【问题讨论】:

  • 请提供准确的错误信息!顺便说一句,您是否尝试将目标/编译 SDK 版本增加到 28?
  • 我做到了,但没有解决
  • 分享错误信息截图。
  • 请添加您收到的整个错误,并回复@AlexMamo

标签: android android-studio firebase-realtime-database


【解决方案1】:

将这些标志放在你的 gradle.properties 中:

android.useAndroidX=true
android.enableJetifier=true

然后对 compileSdkVersion 和 targetSdkVersion 使用 SDK 版本 28:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.mih.demo2"
        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'
        }
    }
}

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.google.firebase:firebase-core:17.2.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'
}

效果很好!

【讨论】:

  • 您应该将目标和编译 SDK 版本增加到 28。然后将这些标志添加到 gradle.properties,然后同步您的 gradle。我再次测试它,它适用于你的 gradle。如果没有,请添加更多带有代码的 cmets。 @MIH
  • 先生,我做到了,但它显示一条消息“无法解析 ':app@debug/compileClasspath' 的依赖项:无法解析外部依赖项 com.android.support:appcompat-v7:28.0.0因为没有定义存储库。”
  • 检查一下,它是一个带有你的 gradle 的示例项目。它工作正常s2.picofile.com/file/8373101150/test.rar.html@MIH
  • 当然,当我从 gradle.properties 中删除这两行 android.useAndroidX=true android.enableJetifier=true 时,我有同样的错误。将这两行添加到 gradle.properties 文件中,将解决问题。请再次检查。 @MIH
猜你喜欢
  • 2015-01-25
  • 2014-04-03
  • 2021-02-10
  • 1970-01-01
  • 2015-09-16
  • 2015-10-14
  • 1970-01-01
  • 2014-08-18
  • 1970-01-01
相关资源
最近更新 更多