1. gradle工程如果有远程依赖,则生成aar后,默认不会包含这些远程依赖。所以如果主工程引用了若干aar,应该检查aar对应的原工程是否有远程依赖,如果有的话,都应该在主工程中添加。否则编译会报NoClassDefineException。以github上的usb carema驱动为例,引用其aar的同时应包含对应远程依赖:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:26.+'
compile(name: 'libuvccamera-release', ext: 'aar')
compile(name: 'usbCameraCommon-release', ext: 'aar')
compile "com.android.support:support-annotations:${supportLibVersion}"
compile("com.serenegiant:common:${commonLibVersion}") {
exclude module: 'support-v4'
}
}
repositories {
jcenter()
flatDir {
dirs('libs')
}
}
2. 在子工程中引用了若干aar,在编译时,主工程报错:找不到对应的aar。解决的办法如下:
第一种,在主工程的libs下添加对应的aar。比如子工程中引用了lib-release.aar,在主工程中的libs目录也放一份,并配置gradle。
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:26.+'
compile(name: 'lib-release', ext: 'aar')
}
repositories {
jcenter()
flatDir {
dirs('libs')
}
}
第二种,在主工程build.gradle中配置子工程放置aar的路径。xxx为子工程的名字。
repositories {
jcenter()
flatDir {
...
dirs project(':xxx').file('libs')
}
}
第三种,在最外层Project下的build.gradle中配置:
allprojects {
repositories {
jcenter()
flatDir {
...
dirs project(':xxx').file('libs')
}
}
}