android - Gradle - 无法使用 gradle 依赖项在 Android Studio 中导入 viewpagerindicator

标签 android gradle android-viewpager viewpagerindicator android-gradle-plugin

所以我正在尝试使用 actionbarsherlock 和 viewpagerindicator,但出于某种原因,viewpagerindicator 库由于某种原因没有被导入。有人知道吗?

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

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

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.viewpagerindicator:library:2.4.0'
}

dependencies {
    compile project(':libraries:facebook')
}

此导入错误“无法解析符号 viewpageindicator

import com.viewpagerindicator.TabPageIndicator;

这些是我的“消息 gradle 任务”

Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\android-sdk\build-tools\19.0.1\aapt.exe package -f --no-crunch -I C:\android-sdk\platforms\android-19\android.jar -M C:\myAppName\app\build\manifests\debug\AndroidManifest.xml -S C:\myAppName\app\build\res\all\debug -A C:\myAppName\app\build\assets\debug -m -J C:\myAppName\app\build\source\r\debug -F C:\myAppName\app\build\libs\app-debug.ap_ --debug-mode --custom-package com.myAppName.app --output-text-symbols C:\myAppName\app\build\symbols\debug
Error Code:
    1
Output:
    C:\myAppName\app\build\res\all\debug\values\values.xml:911: error: Error: No resource found that matches the given name: attr 'vpiTabPageIndicatorStyle'.
    C:\myAppName\app\build\res\all\debug\values\values.xml:914: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.TabPageIndicator'.
    C:\myAppName\app\build\res\all\debug\values\values.xml:934: error: Error: No resource found that matches the given name: attr 'fadeDelay'.
    C:\myAppName\app\build\res\all\debug\values\values.xml:933: error: Error: No resource found that matches the given name: attr 'fadeLength'.
    C:\myAppName\app\build\res\all\debug\values\values.xml:931: error: Error: No resource found that matches the given name: attr 'selectedColor'.


C:\myAppName\app\src\main\res\values\styles.xml
    No resource found that matches the given name: attr 'vpiTabPageIndicatorStyle'.
    Error retrieving parent for item: No resource found that matches the given name 'Widget.TabPageIndicator'.
    No resource found that matches the given name: attr 'fadeDelay'.
    No resource found that matches the given name: attr 'fadeLength'.
    No resource found that matches the given name: attr 'selectedColor'.

最佳答案

不能通过

导入ViewPagerIndicator
compile 'com.viewpagerindicator:library:2.4.0'

因为 Maven Artifact 只是 Java 库的一个 jar,但 VPI 依赖于 jar 中没有的 Android 资源。

具有 AAR 打包的 Maven Artifact 确实有资源并且可以工作,但 VPI 不是这样打包的。它有 apklib 打包,但 Android Gradle 插件不支持。

您需要下载源代码并将其设置为 android-library 模块。

你没有具体说明你运行的是什么版本的 Android Studio,但我敢打赌你的导入不起作用的问题是因为你运行的是早于 0.4.3 的版本;从那时起,该区域的错误已得到修复。

关于android - Gradle - 无法使用 gradle 依赖项在 Android Studio 中导入 viewpagerindicator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21716526/

相关文章:

android - Android Studio:从构建中排除gradle任务

java - 如何在单击抽屉导航项目时显示 viewpager 的选项卡而不重叠?

android - 使用 Sliding tabLayout 在单击选项卡时切换选项卡不起作用

jenkins - Gradle,Jacoco,Jenkins-如何让Jenkins发布报告?

java - 检查是否在gradle中正确添加了依赖项

java - 窗口回调 onMenuOpened 和 onPanelClosed 用于随工具栏膨胀的菜单

android - Retrofit 返回具有空成员的对象

android - 为什么我的代码显示此错误(URI 未注册(设置|项目设置||模式和 DTD)?

android - 如何从android位图中找到像素数组中像素的xy坐标

android - Play 商店在应用内购买产品最高限额