Android Studio 使用另一个 AAR 文件和里面的 jar 创建 AAR

标签 android android-library aar android-studio-2.1

我正在使用另一个 aar 和 jar 文件依赖项创建 AAR 文件。我已成功创建 .aar 发布文件。

然后,我将新的 AAR 文件导入到示例项目中。该项目运行良好。当访问 aar 和 jar 类时,它显示 NoClassDefFound 错误。

注意:首先我想知道,到目前为止,AAR 是否可能包含在另一个 AAR 中。谁能帮我解决这个新问题?

我也提到了这个链接 Create an AAR with multiple AARs/JARs .它说传递=真。但是,不明白在哪里使用该标志。在第三方使用应用程序或在 AAR 项目依赖项中创建 AAR 时。

提前致谢。

我的迷你项目 Gradle 文件:

迷你项目,仅转换为.AAR 文件。然后,这个文件只会使用另一个 NewProject

迷你项目Build.gradle文件

/*
This would be enabled for development purpose and to debug and check the same
*/

apply plugin: 'com.android.application'

/*
This would be enabled for exporting as aar file
apply plugin: 'com.android.library'
*/

//apply plugin: 'com.android.library'

android {

    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
    defaultConfig {

        /*
        This application id would be used for development purpose and to debug and check the same.
        This would be commented when exporting as library
        */
        applicationId 'com.pss.pssplayer'
        minSdkVersion 18
        targetSdkVersion 23
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }

    aaptOptions {
        cruncherEnabled = false
    }

    buildTypes {

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
 'proguard-rules.pro'

        }
    }

    productFlavors {
    }
}

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')

    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:23.1.1'

    compile 'com.android.support:support-v4:23.1.1'

    compile files('libs/ksoap2-android-assembly-3.2.0-jar-with-dependencies.jar')

    compile files('libs/secure.jar')

    compile(project(':getSubProject')) {

        transitive = true

    }// this getSubProject also contains one classes jar
}

最佳答案

当您在依赖项中引用 aar 和 jar 时,您可以使用对第一个的引用来编译新的 aar。

但它们没有嵌入到您的 aar 中。相反,使用“big aar”的应用程序也首先需要对两者的依赖。

为此,您可以将所有 aar 部署到存储库中,例如 maven 告诉 maven “大 aar”取决于前两个。 (-> pom.xml)

在您的应用程序 build.gradle 文件中,您可以使用 transitive=true 仅在“big aar”上添加依赖项,以告诉系统查看依赖项的依赖项。

编辑:

您至少可以合并 jar 。看看这些答案:

gradle - how do I build a jar with a lib dir with other jars in it?

Can Gradle jar multiple projects into one jar?

合并 aar 比较困难,因为您必须合并所有资源、 list 等...

关于Android Studio 使用另一个 AAR 文件和里面的 jar 创建 AAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40405465/

相关文章:

java - 使用 Intent 避免 FAILED BINDER TRANSACTION 错误

java - 如何从 Facebook 图表获取信息

android - 忽略 TortoiseSVN 中的 android 库 bin 文件?

android - java.lang.IllegalStateException : Could not initialize plugin: MockMaker 错误

android - 通过数据绑定(bind)创建和使用 AAR

java - 在.aar文件Android中添加gradle依赖项(build.gradle)

java - Android 从 url 播放 mp3

java - 如何在 alamkanak 周 View 中添加事件

android - 无法从 aar 访问类

android - 如何访问android主项目中模块Jar的类文件