Gradle 无法解析 Android Studio 中的库

Gradle failed to resolve library in Android Studio

我想在 Android Studio 中包含一个库,但它显示如下错误:

"Failed to resolve:com.lemonlab:expandable-button-menu:1.0.0"

如何解决这个问题?

    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 21
        buildToolsVersion '21.1.2'

        defaultConfig {
            applicationId "ayowes.com.newecampus"
            minSdkVersion 15
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-ptimize.txt'), 'proguard-rules.txt'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:21.0.3'
        compile 'com.google.android.gms:play-services:6.5.87'
        compile 'com.lemonlab:expandable-button-menu:1.0.0'
        compile files('libs/pinchzoom.jar')
    }

为了能够使用 lib 项目,您需要将其包含在应用程序的 settings.gradle 添加:

include '..:ExpandableButtonMenu:library'

然后在您的 build.gradle 添加:

compile project(':..:ExpandableButtonMenu:library') 

将 ExpandableButtonMenu 项目与您自己的项目(同一文件夹)放在一起[=13​​=]

查看此How to build an android library with Android Studio and gradle?了解更多详情。

嗯,是 co.lemonlabs,你的 build.gradle 有错别字:

compile 'co.lemonlabs:expandable-button-menu:1.0.0'

来源:https://github.com/lemonlabs/ExpandableButtonMenu#including-in-your-project

检查您的 gradle 是否离线。首选项-ProjectSettings-Gradle。 如果您尝试在离线时添加库,您会看到该错误。另外,试试 Build-Clean,它可能会为您提供更多细节。

你去文件->设置->Gradle 查看 "Offline work" 收件箱,如果已选中,请取消选中并尝试再次同步 我有同样的问题,我试试这个,问题解决了。祝你好运!

我遇到了同样的问题,首先想到的是存储库。所以我检查了整个项目的 build.gradle 文件并添加了以下代码,然后将 gradle 与项目同步,问题就解决了!

allprojects {
    repositories {
        jcenter()
    }
}

试试这个

  1. 清理项目
  2. 使缓存无效并重启工作室
  3. 检查android SDK路径是否正确
  4. 检查你的资源文件是否有错误
repositories {
    mavenCentral()
}

我在 build.gradle 中添加了这个,它起作用了。

有时您可能只需要在项目级别 build.gradle 文件的 allprojects 块中添加 maven { url "https://jitpack.io" }

示例:

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

通过使用“http://jcenter.bintray.com/”而不是“https://jcenter.bintray.com/”解决。

repositories {
    jcenter( { url "http://jcenter.bintray.com/" } )
}

我遇到了同样的问题,我在build.gradle

中添加了以下几行
allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }

        maven {
            url 'http://dl.bintray.com/dev-fingerlinks/maven'
        }
        mavenCentral()
    }
}

对我来说,以下步骤很有帮助。

这似乎是 Android Studio 3.4/3.5 的错误,它是 "fixed" 通过禁用:

文件 → 设置 → 实验 → Gradle → 仅同步活动变体

如果添加存储库不起作用,请检查您的 settings.gradle 是否包含:

    repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)