Android AAR

AndroidStudio依赖aar

2019-03-08  本文已影响0人  duoduo7628

依赖aar很简单,加入代码:

repositories{

    flatDir{

        dirs 'libs'
    }
}
app-release.aar放到libs目录下,加入代码:
dependencies {

    implementation (name:'app-release',ext:'aar')
}

在module如上依赖就会产生问题,所以按照如下方法

allprojects中 加入flatDir,然后再去项目中引用即可。

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
        flatDir {
            dirs project(':base_lib').file('libs')  //base_lib为引入aar文件的module名
        }
    }

    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs.add('-Xbootclasspath/p:base_lib/libs/framework.jar')
        }
    }
}

完整依赖appcompat-v7示例

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.noahedu.testtouch"
        minSdkVersion 22
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories{

    flatDir{

        dirs 'libs'
    }
}

dependencies {

    implementation (name:'app-release',ext:'aar')
    implementation(name: 'appcompat-v7-25.3.1', ext: 'aar')
    //support v4
    implementation files('libs/support-annotations-25.3.1.jar')
    implementation files('libs/support-compat-25.3.1.jar')
    implementation files('libs/support-core-ui-25.3.1.jar')
    implementation files('libs/support-fragment-25.3.1.jar')
    implementation files('libs/support-media-compat-25.3.1.jar')
    implementation files('libs/support-core-utils-25.3.1.jar')
    //support v7
    implementation files('libs/support-vector-drawable-25.3.1.jar')
    implementation files('libs/support-animated-vector-drawable-25.3.1.jar')
}
需要注意:
上一篇下一篇

猜你喜欢

热点阅读