Android Studio使用另一个AAR文件和jar内部创建AAR

har*_*nan 8 android android-library aar android-studio-2.1

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

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

注意:首先我想知道,截至目前,另一个AAR中的AAR是否可行.任何人都可以帮助我摆脱这个新事物的问题吗?

我提到这个链接也创建了一个包含多个AAR/JAR的AAR.它说传递=真.但是,不明白,在哪里使用那个标志.在第三方使用Application或在AAR项目依赖项中创建AAR.

谢谢提前.

我的迷你项目Gradle文件:

Mini Project,只转换为.AAR文件.那么,这个文件只会使用另一个NewProject

Mini Project 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
}
Run Code Online (Sandbox Code Playgroud)

Bip*_*ipi 5

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

但是它们没有嵌入您的aar中。取而代之的是,使用“ big aar”的应用程序还需要首先依赖于两者。

为此,您可以将所有aar部署在像maven这样的存储库中,告诉maven“大aar”首先取决于两者。(-> pom.xml)

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

编辑

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

gradle-如何构建一个带有lib dir以及其他jar的jar?

Gradle可以将多个项目合并到一个jar中吗?

合并aar更加困难,因为您必须合并所有资源,清单等。

  • 可以在没有 maven 的情况下在其他 aar 中包含一个 aar 吗? (2认同)

Nic*_*nze 0

使用android-fat-aar gradle 插件,超级有用!