【问题标题】:How to add appcompat in gradle?如何在 gradle 中添加 appcompat?
【发布时间】:2020-10-11 06:14:09
【问题描述】:
Could not find com.android.support:appcompat-v7:24.2.1.
Searched in the following locations:
  - https://jcenter.bintray.com/com/android/support/appcompat-v7/24.2.1/appcompat-v7-24.2.1.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
    project :app

这里是build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "24.0.3"
    useLibrary  'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.rts.dcmote.dcmote"
        minSdkVersion 15
        targetSdkVersion 30
        versionCode 2
        versionName "1.1"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:24.2.1'

}

【问题讨论】:

  • appcompat好像没有这个特定版本,你需要这个版本还是appcompat的任何版本都可以?
  • @LiuWenbin_NO. appcompat-v7:24.2.1 存在,但您必须添加 google() 存储库。

标签: android android-layout android-support-library androidx


【解决方案1】:

更新(2020 年 6 月): 对于 Android Studio >=4.2.0,项目根目录下的 build.gradle 会是这样的:

buildscript {
    repositories {
            google()
            mavenCentral()
        }
...

【讨论】:

    【解决方案2】:

    注意:随着支持库 28.0.0 的发布,android.support-packaged 库已被弃用,取而代之的是打包为 androidx 的单独版本的 Jetpack 库。 Jetpack 库的初始 1.0.0 版本提供了与支持库 28.0.0 相同的功能,并为迁移到新的 androidx 打包提供了一个起点。

    现有的 android.support-packaged 库将继续工作;但是,它们将不会收到 28.0.0 之后的任何更新,并且不会与新的 Jetpack 库兼容。历史工件(那些版本为 27 及更早版本,并打包为 android.support)仍可在 Google Maven 上使用。所有新工件都将打包为 androidx,并且需要从 android.support 迁移到 androidx。 您可以在此处查看其余文档 Google Developer

    你可以用这个, 在此处查看最新版本Google Developer

    implementation 'androidx.appcompat:appcompat:1.3.0'
    

    【讨论】:

      【解决方案3】:

      依赖:

      implementation 'com.android.support:appcompat-v7:24.2.1'
      

      很旧,但它存在。
      签入您的顶级 build.gradle repositories 块。您必须添加 google() 存储库。

      allprojects {
          repositories {
              google()
              jcenter()
          }
      }
      

      无论如何考虑:

      • 使用最新版本的支持库28.0.0代替24.2.1
      • migrate to androidx 库,因为支持库已被弃用。在这种情况下使用(在这种情况下,您还需要google() repo)
          implementation 'androidx.appcompat:appcompat:1.1.0'
      

      【讨论】:

        【解决方案4】:

        看来您使用的是旧版本的 appCompat。

        您可以使用 Refactor 迁移所有代码 -> 迁移到 AndroidX

        【讨论】:

          【解决方案5】:

          建议您使用Android X迁移到最新的支持库,您尝试使用的版本是不再维护的旧版appcompat,试试这个

          implementation 'androidx.appcompat:appcompat:1.1.0'

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2013-08-04
            • 1970-01-01
            • 1970-01-01
            • 2023-03-03
            • 2017-08-17
            • 1970-01-01
            • 1970-01-01
            • 2014-02-13
            相关资源
            最近更新 更多