android - AAR 缺少我的依赖项

标签 android aar

我创建了一个新项目,其中仅包含一个库模块。

android studio

这是我的 build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 
             'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'org.altbeacon:android-beacon-library:2+@aar'
}

如果我构建这个项目,它会生成一个名为 app-debug.aaraar 文件,大小为 45kb。我想知道为什么我需要包含主项目的所有依赖项,因为如果我仅包含 app-debug.aar 的依赖项,它会抛出 ClassNotFoundException

为什么我需要这样做?

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile ('org.altbeacon:android-beacon-library:2+@aar')
    compile (name:'app-debug', ext:'aar')
}

我能否找到一种方法,不需要在主项目 (apk) 上包含 altbeacon 等依赖项,而只使用 app-debug.aar 依赖项?

提前致谢。

最佳答案

在您的应用程序项目中尝试一下:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile (name:'app-debug', ext:'aar') {
       transitive = true
    }
}

关于android - AAR 缺少我的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29520839/

相关文章:

android - 如何删除撰写 View 上的阴影?

android - NestedScrolling with NestedScrollView, RecyclerView (Horizo​​ntal), inside a CoordinatorLayout

android - 如何垂直对齐不同高度的 3 个 View

android - React Native 构建不嵌入包文件

android - 如何将proguard应用于android中的AAR库?

java - 有没有更快的方法从 Sqlite 查询中遍历行?

java - Android - 循环遍历 strings.xml 文件

java - 安卓版本 : Classes of a JAR file inside a AAR package are not recognized

android - 如何显式地在另一个模块中启动一个 Activity

android - 如何发布具有远程依赖项 (gradle) 的 Android 库 (aar)?