3

所以我尝试使用actionbarsherlock和viewpagerindicator,出于某种原因,viewpagerindicator库由于某种原因无法导入。任何人有任何想法?Gradle - 无法在Android Studio中使用gradle依赖项导入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:[email protected]' 
    compile 'com.viewpagerindicator:library:2.4.0' 
} 

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

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

import com.viewpagerindicator.TabPageIndicator; 

这是我的 “消息摇篮任务”

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'. 
+0

什么版本的Android Studio?你是什​​么意思“不进口”? –

+0

@ScottBarta,我只是用确切的错误更新了我的问题。 –

回答

4

无法通过

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

因为Maven工件只是Java库的一个罐子,但VPI依赖于不在jar中的Android资源。

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

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

你并没有具体说明你正在运行的Android Studio版本,但我敢打赌,你导入的问题不起作用是因为你运行的是早于0.4的事实。 3;自那时起,该领域的bug已经得到修复。

+0

感谢您的解释。我没有意识到这一点。更新到0.4.3以上的版本会帮助我导入库还是需要将它作为java库导入? –

+0

不,您仍然必须在Gradle中将VPI设置为android库模块。 0.4.3只修正了新添加的依赖关系仍然无法显示导入权限和语法高亮显示的错误,即使该项目可以正常工作。 –

+0

谢谢。我最终不是通过依赖添加库,而是通过将它添加到库文件夹。 –

4

可以使用this instruction导入AAR:

在你的build.gradle包括http://dl.bintray.com/populov/maven作为仓库priorior到mavenCentral:

repositories { 
    maven { url "http://dl.bintray.com/populov/maven" } 
    mavenCentral() 
} 

在使用你的依赖和往常一样:

dependencies { 
    compile 'com.viewpagerindicator:library:[email protected]' 
} 
+0

我尝试在另一个子项目中做我在android工作室,但我得到一个错误Widget.TabIndicator等风格没有找到。任何想法我可能做错了什么? –

3

如果您有repositories define,只需添加到@ serge的答案d在allprojects标记中,您需要将其添加到此处。

allprojects { 
    repositories { 
     maven { url "http://dl.bintray.com/populov/maven" } 
     mavenCentral() 
    } 
} 
0

我的根的build.gradle是:

// Top-level build file where you can add configuration options common to all sub-projects/modules. 
 

 
buildscript { 
 
    repositories { 
 
     maven { url "http://dl.bintray.com/populov/maven" } 
 
     mavenCentral() 
 
     jcenter() 
 

 
    } 
 
    dependencies { 
 
     classpath 'com.android.tools.build:gradle:0.12.2' 
 

 
     // NOTE: Do not place your application dependencies here; they belong 
 
     // in the individual module build.gradle files 
 
    } 
 
} 
 

 
allprojects { 
 
    repositories { 
 
     maven { url "http://dl.bintray.com/populov/maven" } 
 
     mavenCentral() 
 
     jcenter() 
 

 
    } 
 
}

和依赖是:编译 'com.viewpagerindicator:图书馆:[email protected]'

它的作品像炸弹:-)

+0

我试过这个....它不能给出任何错误,但我无法导入任何类。哪里不对? –

1

我使用

compile 'com.mcxiaoke.viewpagerindicator:library:[email protected]' 

这对我很有用。

并确保重新同步gradle并重建项目