Exporting AAR. from an Complex Project

一个人想着一个人 提交于 2021-02-05 10:47:06

问题


I have a problem about exporting AAR from my project. My project has 3 modules that included as library into the project. One of that modules is android project that contains the actual project.

That means when you run the whole project in AVD, project opens the module as I mentioned before. And the other modules related and connected with the main module as a network and opencv library.

My problem is: When I want to create ONE AAR. file that includes all modules inside, the android project creates AAR. file by module that means three different AAR. file for 3 different module.

Because of that I cannot add my whole project's AAR. file to another project.

There is way of creating AAR. file of whole project that includes all modules inside like opencv module, network module, for all modules? My project build.gradle;

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    apply from: "$rootProject.projectDir/dependencyVersion.gradle"

    ext.kotlin_version = '1.4.10'
    repositories {
        google()
        jcenter()
        maven {url 'https://maven.fabric.io/public'}
        maven { url 'https://maven.google.com' }
        maven { url "https://plugins.gradle.org/m2/"}
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.17.0"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {url 'https://maven.fabric.io/public'}
        maven { url 'https://maven.google.com' }
        maven { url "https://plugins.gradle.org/m2/"}
    }
    apply plugin: "com.jfrog.artifactory"
    apply plugin: 'maven-publish'

}

artifactoryPublish.skip = true

task clean(type: Delete) {
    delete rootProject.buildDir
}

This is my build.gradle. of the library module. Lets call it module1 where i want to merge all other two library module(module2, module3) into this module1.

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'


version = rootProject.sdkVersionName
group = rootProject.mainLibraryGroup

android {
    compileSdkVersion rootProject.compileSdkVer

    defaultConfig {
        minSdkVersion rootProject.minSdkVer
        targetSdkVersion rootProject.targetSdkVer
        versionCode rootProject.sdkVersionCode
        versionName rootProject.sdkVersionName
//        versionCode 1
//        versionName "1.0.0(10)"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    dataBinding {
        enabled true
    }

    lintOptions {
        abortOnError false
    }


    externalNativeBuild {
        cmake {
            path file('CMakeLists.txt')
        }
    }
    sourceSets {
        main {
            // The libs directory contains prebuilt libraries that are used by the app's library defined in CMakeLists.txt
            // via an IMPORTED target.
            jniLibs.srcDirs = ['libs'] //'libs'
        }
    }

}

dependencies {
    
//    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(path: ':module2')
    implementation project(path: ':module3')

    implementation "androidx.legacy:legacy-support-v4:1.0.0"

    //getting dependencies from dependencies.gradle file
    implementation deps.crashlytics
    implementation "android.arch.lifecycle:extensions:$versions.arcLifecycle"
    implementation "com.github.bumptech.glide:glide:$versions.glide"
    implementation "androidx.appcompat:appcompat:$versions.appcompat"
    implementation "androidx.constraintlayout:constraintlayout:$versions.constraintLayout"
    implementation "com.google.code.gson:gson:$versions.gson"
    implementation "com.google.android.material:material:$versions.material"
    implementation "com.squareup.okhttp3:logging-interceptor:$versions.okHttp"
    implementation "androidx.exifinterface:exifinterface:1.3.0-alpha01"
    implementation "com.google.android.gms:play-services-location:$versions.playServices"
    implementation "com.google.android.gms:play-services-mlkit-text-recognition:$versions.playServices"

    implementation 'com.google.guava:guava:27.0.1-android'
    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'org.jmrtd:jmrtd:0.7.18'
    implementation 'net.sf.scuba:scuba-sc-android:0.0.20'
    implementation 'com.madgag.spongycastle:prov:1.58.0.0'

    implementation 'edu.ucar:jj2000:5.2'
    implementation 'com.github.mhshams:jnbis:1.1.0'

    implementation 'androidx.camera:camera-core:1.0.0-beta05'
    implementation 'androidx.camera:camera-camera2:1.0.0-beta05'

    implementation "com.airbnb.android:lottie:3.4.4"
    def camerax_version = "1.0.0-alpha01"
    implementation "androidx.camera:camera-core:${camerax_version}"
    implementation "androidx.camera:camera-camera2:${camerax_version}"
    implementation "androidx.core:core-ktx:1.3.2"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    //RX
    implementation "io.reactivex.rxjava2:rxandroid:$versions.rxandroid"
    implementation "io.reactivex.rxjava2:rxjava:$versions.rxjava"
    implementation 'org.jetbrains:annotations:15.0'


    //image Cropping



    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'




}
repositories {
    mavenCentral()
}


apply from: "$rootProject.projectDir/tools/artifactory/commonArtifactory.gradle"

I applied all of them. After that, i clicked the gradle in righ panel of Android Studi. And I selected the module1>other>assembleRelease. I gave me this error.

 DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.
Could not resolve io.reactivex.rxjava2:rxandroid:null

回答1:


You need a fat-aar (An aar that includes all the others locally). You can use something like kezong lib or cpdroid lib

Update:

Based on the snippet that you included in the question, I suggest to try the changes below:

In your root build-gradle file (I think that is the first snippet) you should add the below code:

dependencies {     
        classpath 'com.kezong:fat-aar:1.2.20'
}

In your library's build-gradle file you should add the

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.kezong.fat-aar'

and change the below dependencies section:

from

dependencies {
   implementation project(path: ':module2')
   implementation project(path: ':module3')
}

to

dependencies {
   releaseEmbed project(path: ':module2')
   releaseEmbed project(path: ':module3')

   debugImplementation project(path: ':module2')
   debugImplementation project(path: ':module3')
}


来源:https://stackoverflow.com/questions/65231132/exporting-aar-from-an-complex-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!