我看到了类似的问题,但没有找到可接受的答案。
问题 - 我有自己的带有一些小功能的 android 库。
我的图书馆使用其他人 - f.e. Hawk(无 sql 数据库)。
我的库 gradle 文件:
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 )并包含到单独的项目中时 - 它失败了。项目只能看到我图书馆的类(class)。 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 - 是否可以混淆我的库的代码(只有我的,而不是依赖项)?
Best Answer-推荐答案 strong>
what should i do to make my main project see my library's third party dependencies?
aar 文件不包含 transitive依赖项,并且没有描述模块使用的依赖项的 pom 文件。
这意味着,如果您使用 flatDir 存储库导入 aar 文件您还必须在项目中指定依赖项。
您应该使用 maven 存储库(私有(private)或公共(public))来避免此问题。
在这种情况下,gradle 使用 pom 文件下载依赖项,该文件将包含依赖项列表。
关于java - Android aar 库不包含依赖项,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/46865803/
|