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並重建項目