无法在gradle(Android Studio)中添加依赖项

4

我正在尝试将这个依赖项 https://github.com/hoang8f/android-flat-button 添加到我的Android Studio项目中,但我遇到了问题。

 Error:(26, 13) Failed to resolve: info.hoang8f:fbutton:1.0.5

我能轻松添加 Google Play 服务的依赖,没有任何问题。

以下是我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.planner"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'info.hoang8f:fbutton:1.0.5'
}

尝试的解决方案:1)Gradle处于在线模式而非离线模式。2)清理并构建/重建项目。3)更改为


repositories {
    mavenCentral()
}

在我的根gradle文件中

4.)工具->android->与gradle文件同步项目

仍然没有成功使其起作用。

P.S.:尽管这不影响问题,但我在尝试通过gradle添加解析sdk时遇到了同样的问题,因此我独立地添加了jar文件。


我在我的 build.gradle 中添加了 compile 'info.hoang8f:fbutton:1.0.5',并且它正常工作,你可以尝试 Build-> Rebuild project - tianyu
正如我在问题中所述,我已经清理/重建了项目,我的旧项目运行良好,只有新项目出现了这个问题。 - penta
愚蠢的问题,但我还是需要问一下。这个库真的有必要吗?我认为你可以自己做一个扁平按钮,就像这里所示:https://dev59.com/VF8d5IYBdhLWcg3w3FZk - piotrek1543
这不仅仅是关于“这个”库,当我尝试添加另一个库时,它可能会对我产生影响。 - penta
5个回答

1

添加

repositories { mavenCentral() }

包括 Android 标签

    android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.example.planner"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
repositories {
    mavenCentral()
   }}

1
请尝试这样做。将fbutton-1.0.5.aar文件添加到您的lib文件夹中。
repositories {
        flatDir {
            dirs 'libs'
        }
    }

将aar文件添加到依赖项中。
dependencies {
    compile(name:'ARFile', ext:'aar')
}

不行,这个不起作用,它会给出错误:(49)在包“com.example.planner”中找不到属性“buttonColor”的资源标识符 错误:(49)在包“com.example.planner”中找不到属性“shadowColor”的资源标识符 错误:(49)在包“com.example.planner”中找不到属性“shadowEnabled”的资源标识符 错误:(49)在包“com.example.planner”中找不到属性“shadowHeight”的资源标识符 错误:(49)在包“com.example.planner”中找不到属性“cornerRadius”的资源标识符。 - penta
请检查此链接:https://dev59.com/u2025IYBdhLWcg3wwYv4 - Photon Point

1

您是否注意到demo项目的build.gradle文件长什么样子了呢? https://github.com/hoang8f/android-flat-button/blob/master/demo/build.gradle

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.1.0'

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 2
        versionName "1.1"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    } }

dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
    compile 'com.larswerkman:HoloColorPicker:1.4'
    compile fileTree(dir: 'libs', include: ['*.jar']) //    compile project(':library')
    compile 'info.hoang8f:fbutton:1.0.5'
 }

检查一下你的 Gradle 文件是否有遗漏或者放错了东西

编辑:我把你的整个 build.gradle 文件放到我的新项目中,它能正常工作。

如果重新构建没有帮助,请创建一个新的干净项目并将此 build.gradle 放入其中。告诉我这是否在新项目中起作用。

编辑2:

在你的项目中有两个 build.gradle,把第二个改成

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.google.gms:google-services:1.5.0-beta2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

一切似乎都很好,您的链接无效。 - penta
不好意思,它仍然无法工作,我认为我的 Gradle 存在问题,而不是项目本身,我尝试创建一个新项目,但仍然遇到同样的问题。 - penta
是的,这可能是一个Gradle问题。请检查您的第二个build.gradle文件。 - piotrek1543

0

我遇到了同样的问题。 清除缓存并重新启动你的Android Studio,然后同步Gradle。


0

我克隆了该项目并使用“demo”模块来测试这个库。你所需要的库已经成功下载,这是预期的,因为它存在于maven仓库中。

我唯一注意到的问题可能是你会在gradle中遇到问题,因为有一个runProguard命令不再被使用。 所以你可以将其删除或更改为minifyEnabled false。

这样做后,演示项目就可以成功组装了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接