Android aar库不包含依赖项 [英] Android aar library doesn't contain dependencies
问题描述
问题 - 我有我自己的一些小函数的android库。
我的图书馆使用他人 - f.e. Hawk(没有sql数据库)。
我的图书馆gradle文件:
apply plugin:'com.android.library'
buildscript {
存储库{
maven {urlhttps://www.jitpack.io}
}
}
android {
compileSdkVersion 26
buildToolsVersion26.0.1
defaultConfig {
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName1.0
testInstrumentationRunnerandroid。 support.test.runner.AndroidJUnitRunner
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt') ,'library.pro'
}
}
}
依赖项{
编译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
proguardFiles getDefaultProguardFile('proguard-android.txt'),'' library.pro'
结果不会改变。
我尝试将以下代码行添加到proguard文件(library.pro)中:
$ b $ pre $ -keep class com.orhanobut。 hawk {public *;}
-keep class com.orhanobut.hawk。* {public *;}
结果是一样的。
所以我有两个问题:
1 - 我该怎么做才能让我的主项目看到我的图书馆的第三方依赖呢?
2 - 是可以混淆我的库代码(只有我的,而不是依赖关系)?
我应该如何让我的主项目看到我的图书馆的第三方依赖关系? aar 文件不包含传递依赖项,并且没有描述这意味着,如果您要使用
flatDir
存储库导入aar文件 您必须在您的项目中指定相关性。
您应该使用 maven存储库以避免此问题。
在这种情况下,gradle使用包含依赖项列表的pom文件下载依赖项。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 (withgradle
->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. SoClassNotFoundException
comes. If i removeminifyEnabled 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)?
解决方案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.这篇关于Android aar库不包含依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!