Android aar 库不包含依赖项 [英] Android aar library doesn't contain dependencies
问题描述
我看到了类似的问题,但没有找到公认的答案.问题 - 我有自己的带有一些小功能的 android 库.我的图书馆使用其他人 - f.e.Hawk(没有 sql 数据库).我的图书馆 gradle 文件:
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'
}
库工作正常.如果我将它用作另一个项目中的项目 - 它也可以工作.但是当我生成 *.aar
文件(使用 gradle
-> assembleRelease
)并包含到单独的项目中时 - 它失败了.项目仅查看我的图书馆的课程.Hawk com.orhanobut.hawk 包和其他一些(如果我会使用的话)是不可见的.于是 ClassNotFoundException
来了.如果我删除
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'
结果没有改变.我尝试将以下行添加到 proguard 文件 (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 *;}
结果是一样的.
所以我有两个问题:1 - 我应该怎么做才能让我的主项目看到我的库的第三方依赖项?2 - 是否可以混淆我的库代码(只有我的,不是依赖项)?
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)?
推荐答案
我应该怎么做才能让我的主项目看到我的库的第三方依赖项?
what should i do to make my main project see my library's third party dependencies?
aar 文件不包含 transitive 依赖项,并且没有描述模块使用的依赖项的 pom 文件.
The aar file doesn't contain the transitive dependencies and doesn't have a pom file which describes the dependencies used by the module.
这意味着,如果您使用 flatDir
存储库导入 aar 文件您还必须在项目中指定依赖项.
It means that, if you are importing a aar file using a flatDir
repository you have to specify the dependencies also in your project.
您应该使用 maven 存储库,无论是私有的还是公共的,以避免出现此问题.
在这种情况下,gradle 使用包含依赖项列表的 pom 文件下载依赖项.
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.
这篇关于Android aar 库不包含依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!