Android aar library doesn't contain dependencies

你说的曾经没有我的故事 提交于 2019-12-23 13:27:23

问题


i saw similar questions, but not found accepted answers. Problem - i have my own android library with some tiny functions. My library uses others - f.e. Hawk (no sql database). My library gradle file:

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'
}

Library works fine. And if i use it as project inside another project - it work too. But when i generate *.aar file (with gradle -> assembleRelease) and include into separate project - it fails. Project see ONLY MY library's class. Hawk com.orhanobut.hawk package and ofc others (if i will use then) are not visible. So ClassNotFoundException comes. If i remove

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

the result doesnt change. I tried to add the following line into proguard file (library.pro)

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

Result is the same.

So i have two question: 1 - what should i do to make my main project see my library's third party dependencies? 2 - is is possible to obfuscate my library's code (only mine, not dependencies)?


回答1:


what should i do to make my main project see my library's third party dependencies?

The aar file doesn't contain the transitive dependencies and doesn't have a pom file which describes the dependencies used by the module.

It means that, if you are importing a aar file using a flatDir repository you have to specify the dependencies also in your project.

You should use a maven repository, private or public, to avoid the issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.



来源:https://stackoverflow.com/questions/46865803/android-aar-library-doesnt-contain-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!