2016-01-20 183 views
1

我在Android Studio中實現了一個名爲「proximity」的庫項目,並生成了一個「.aar」。這個aar我已經添加到一個新的測試項目作爲一個模塊,如下所述:https://stackoverflow.com/a/24894387/2791503 此外,我將模塊作爲與傳遞標誌的依賴關係,因爲它已經在這裏提出:https://stackoverflow.com/a/25730092/2791503 這可能是gradle File for新TestProject:AAR傳遞依賴關係Google位置服務

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    compile(project(':proximity')) { 
    transitive=true 
} 

不過,當我啓動應用程序,它告訴我,它無法找到一類谷歌的位置API,這是我的庫模塊的依賴。

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/GoogleApiClient$Builder;

如何強制gradle包含我的庫模塊的傳遞依賴關係?

編輯: 原來這裏是庫項目的gradle這個構建文件:

dependencies { 
    //integration tests 
    androidTestCompile 'com.android.support.test:runner:0.4.1' 
    // Set this dependency to use JUnit 4 rules 
    androidTestCompile 'com.android.support.test:rules:0.4.1' 
    // Set this dependency to build and run Espresso tests 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
    // Set this dependency to build and run UI Automator tests 
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator- v18:2.1.2' 
    androidTestCompile 'com.android.support:support-annotations:23.1.1' 

    //local unit testing 
    testCompile 'junit:junit:4.1' 

    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    //estimote sdk 
    compile 'com.estimote:sdk:[email protected]' 
    //google location api(GPS) 
    compile 'com.google.android.gms:play-services-location:8.4.0' 
    //Google Guave Java Util 
    compile 'com.google.guava:guava:18.0' 
    //custom BeSpoon library for android 
    compile project(':bespoonlibrary') 
} 

這是gradle這個build文件的外觀導入庫作爲一個模塊引用AAR後:

configurations.create("default") 
artifacts.add("default", file('app-release.aar')) 
+1

本地android庫項目通常會自動提供它們的依賴關係。 –

+0

聽起來合乎邏輯,但不幸的是,這對我不起作用 –

+0

您是如何定義鄰近庫的依賴關係的? –

回答

0

所以我找到了一個適合我的解決方案,但這仍然不是我所希望的......所以讓我知道是否有人有更好的解決方案。 無論如何,這可能有助於某人: 我有兩個庫,一個外部庫,庫項目本身和一個內部libaray這是外部庫的依賴。此外,每個庫都有自己的依賴關係,例如內部庫引用google-location-service。我試過gradlew assemble,它生成外部庫的* .aar文件。但是所有這些都是外部庫,但沒有內部庫和所有其他依賴關係。這個討論說目前還沒有辦法處理這個問題: How to export AAR including its dependencies?

沒有任何意義使用這個aar沒有所有的依賴......所以我不得不尋找另一種方式。在包含外部庫的Android TestProject中,單擊「File->Import Module->"Select the external library"->Finish」,包含內部庫在內的所有依賴關係。