2014-12-28 88 views
1

包括我發表我的本地倉庫具有以下的build.gradle一個定製的Android庫:AAR的Android庫不gradle這個構建

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.0.0' 
    } 
} 

task wrapper(type: Wrapper) { 
    gradleVersion = '2.2.1' 
} 

apply plugin: "com.android.library" 
apply plugin: "maven-publish" 

group = "com.example" 
//name = "mylibrary" 
version = "0.0.1" 

repositories { 
    mavenCentral() 
    mavenLocal() 
} 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     versionCode 1 
     versionName project.version 

     minSdkVersion 14 
     targetSdkVersion 21 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile "org.slf4j:slf4j-api:1.7.5" 
} 

publishing { 
    publications { 
     android(MavenPublication) { 
      artifact bundleRelease 

      //FIXME manually add the dependencies as gradle doesn't find them in the default configuration 
      pom.withXml { 
       def dependenciesNode = asNode().appendNode('dependencies') 

       configurations.default.allDependencies.each { 
        def dependencyNode = dependenciesNode.appendNode('dependency') 
        dependencyNode.appendNode('groupId', it.group) 
        dependencyNode.appendNode('artifactId', it.name) 
        dependencyNode.appendNode('version', it.version) 
       } 
      } 
     } 
    } 
} 

在運行時./gradlew publishToMavenLocal文件~/.m2/repository/com/example/mylibrary/0.0.1/mylibrary-0.0.1.aar與右內容創建(包括classes.jar)和正確的在MyLibrary-0.0.1.pom:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.example</groupId> 
    <artifactId>mylibrary</artifactId> 
    <version>0.0.1</version> 
    <packaging>aar</packaging> 
    <dependencies> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.7.5</version> 
     </dependency> 
    </dependencies> 
</project> 

但是,當我在另一個項目中聲明對這個庫的依賴性爲compile "com.example:mylibrary:[email protected]",既沒有圖書館,也沒有它的依賴都包括,儘管它似乎被發現。​​產量

compile - Classpath for compiling the main sources. 
\--- com.example:mylibrary:0.0.1 

當運行的版本,因爲無論從它的依賴關係,從我的庫類,也不是類中發現的編譯失敗。

我正在使用Gradle 2.2.1與Android構建工具1.0.0和新的Maven發佈機制。

注意:由於庫中的類丟失,所以它不僅僅是傳遞依賴性的問題,因此this解決方案無法正常工作。 我想從maven中提取庫,所以在本地提供它就像here不是一個選項(它不會幫助傳遞依賴)。

+0

'@ aar'明確要求只獲取AAR並省略依賴關係。根據所提供的信息,我無法分辨AAR的問題。 –

+0

我需要aar本身及其所有的傳遞依賴,但似乎都不包括在內。 – NCode

+0

要獲得傳遞依賴性,您需要省略'@ aar'。如果你甚至沒有得到AAR的代碼,那麼構建或發佈的庫可能還有其他一些問題,但我不能從這裏告訴它是什麼。 –

回答

0

沒有足夠的信譽評論...

我沒有使用過的新的Maven的插件,但如果部署使用android-maven-plugin到bintray,你只需要回購添加到您的build.gradle(或者你可以讓他們在jcenter上託管它,你不需要做任何事情)。然後你就可以使用transitive = true

相關問題