我已经看到了不同开发人员发布的问题(Android Studio combine 2 .aar into one和其他),但我还没有看到一个明确的响应,使我能够创建一个包含一个或多个AAR或JAR的AAR(我可以使用JAR,因为我不需要共享任何资源;只需要共享类)。下面是我的库项目的app.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.code.gson:gson:2.1'
compile ('libs/eventbus.jar')
compile project(':core-release')
compile project(':midware-release')
}同样,这个应用程序是一个库项目,它需要另外两个库项目('core-release','midware-release'),虽然我能够生成一个可以在我的应用程序中使用的AAR文件,但该应用程序无法找到依赖的库项目的类,所以我不得不将这两个库项目的AAR添加到我的应用程序中。
下面是app.gradle应用程序项目(没有手动添加JAR),它无法找到依赖项目的类:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.app.sample"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile files('libs/eventbus.jar')
compile project(':sdk3-debug')
}我认为库项目的AAR文件没有拉入依赖项目(AAR或JAR),因此应用程序无法找到这些类。
我读过有关传递依赖的文章,但我找不到一个对我的情况有帮助的示例实现。
发布于 2015-12-28 08:04:05
这应该可以解决您的问题:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile files('libs/eventbus.jar')
compile project(':sdk3-debug') { transitive = true }
}在true中包含transitive标志。
发布于 2018-01-25 17:04:24
我还没有看到一个明确的响应,可以让我创建一个包含一个或多个AAR或AAR的AAR。
是的,我认为这是因为这个话题并不局限于AAR或JAR,而是Maven如何管理依赖。
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
虽然我能够生成一个可以在我的应用程序中使用的AAR文件,但该应用程序无法找到依赖的库项目的类,所以我必须将这两个库项目的AAR添加到我的应用程序中。
包含您的依赖项不是您的AAR责任,您的POM文件应该包含有关依赖项的信息。
https://maven.apache.org/pom.html
我认为库项目的AAR文件没有拉入依赖项目(AAR或JAR),因此应用程序无法找到这些类。
正确,您仍然需要在应用程序中包含库依赖项。
我假设你希望你的库可以被应用程序使用,而不需要指定你的库依赖core-release和midware-release。我在这里做了一个完整的解释,android studio generate aar with dependency,但这是你需要做的:
Maven repository
core-release和midware-release4.0.0...okhttp OkHttp com.example core-release com.example midware-release ...
-Durl="https://mavenUserName:mavenPassword@nexus.example.com/repository/maven-releases/"部署:deploy-file\ -DgroupId=com.example \ -DartifactId=your-library \ -Dversion=1.0.1 \ -Dpackaging=aar \-Dfile=your-LIBRAR.aar\ -DpomFile=path-to-your-pom.xml \ -DgeneratePom=true \ -DupdateReleaseInfo=true \ mvn
然后你的应用程序就可以使用你的库了。Gradle会自动下载你的库传递依赖。
发布于 2016-01-20 05:28:15
我遵循斯坦·库尔德齐尔的建议解决了这个问题:stackoverflow.com/questions/30052058/multiple-aar-files,以下是我为找到解决方案所采取的步骤:
我创建了一个AAR,并发布到了本地的maven仓库
手动将库项目2上的依赖项添加到应用程序项目中-以便您的应用程序具有两个库的依赖项行。根据您的具体情况,这可能是一个可行的解决方案,也可能不是。
希望这对其他可能遇到类似问题的人有所帮助。
https://stackoverflow.com/questions/34445399
复制相似问题