2017-10-21 166 views
0

我看到類似的問題,但未找到接受的答案。 問題 - 我有我自己的一些小函數的android庫。 我的圖書館使用他人 - f.e. Hawk(沒有sql數據庫)。 我的圖書館gradle文件:Android aar庫不包含依賴關係

apply plugin: 'com.android.library' 
buildscript { 
    repositories { 
     maven { url "https://www.jitpack.io" } 
    } 
} 
android { 
    compileSdkVersion 26 
    buildToolsVersion "26.0.1" 

    defaultConfig { 
     minSdkVersion 18 
     targetSdkVersion 26 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

    } 
    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'library.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:26.0.2' 
    compile 'com.github.orhanobut:hawk:1.23' 
    testCompile 'junit:junit:4.12' 
} 

圖書館工作正常。如果我在另一個項目中使用它作爲項目 - 它也可以工作。但是當我生成*.aar文件(與gradle - >assembleRelease)幷包括到單獨的項目 - 它失敗。項目只看到我的圖書館的類。 Hawk com.orhanobut.hawk包和ofc其他(如果我將使用)不可見。所以ClassNotFoundException來了。 如果我刪除

minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'library.pro' 

結果並沒有改變。 我試圖將下面一行添加到proguard的文件(library.pro)

-keep class com.orhanobut.hawk {public *;} 
-keep class com.orhanobut.hawk.* {public *;} 

結果是相同的。

所以我有兩個問題: 1 - 我該怎麼做才能讓我的主項目看到我的圖書館的第三方依賴關係? 2 - 是可以混淆我的圖書館的代碼(只有我的,而不是依賴)?

回答

1

應該怎麼做才能讓我的主要項目看我的媒體庫的第三方的依賴關係是什麼?

AAR文件不包含transitive依賴性並且不具有其描述由模塊所使用的依賴關係的POM文件。

這意味着,如果要導入使用flatDir你也必須指定項目依賴一個AAR文件。

您應該使用maven資源庫,私人或公共,以避免此問題。
在這種情況下,gradle這個下載使用POM文件這將包含依賴項列表中的依賴關係。

+0

奧奇,你能提供一個幫助鏈接嗎? – TooLazy

+0

@TooLazy這裏一個帖子:https://medium.com/prismapp/publishing-android-library-to-bintray-ba588184b690 –