Gradle Library 패키지

2929 단어
apply plugin: 'com.android.library'


/*
*   :
*
* Android Studio:
* 1.make Project  aar 
* 2.aar    build/outputs/aar/
*
* Eclipse:
*
* 1.    gradlew makejar  jar
* 2.jar   build/libs/
*
* */

def releaseTime() {
    return new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC"))
}
android {
    compileSdkVersion 22



    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        //versionName "1.0"
        versionName "net-idcard-sdk-" + releaseTime()
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

     lintOptions {
          abortOnError false
      }


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


    libraryVariants.all{ variant->
        variant.outputs.all{
            def filename="${defaultConfig.versionName}.aar"
            outputFileName=filename
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:22.2.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}




task copyLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

task clearJar(type: Delete) {
    delete 'build/libs/cwsdk.jar'
    delete 'libs/cwsdk.jar'
}
def zipFile = file('build/intermediates/bundles/release/classes.jar')

//    
task makeJar(type: org.gradle.api.tasks.bundling.Jar) {

    from zipTree(zipFile)
    //from fileTree(dir: 'src/main',includes: ['assets/**', 'jniLibs/**','java/**'],excludes: [''])// assets    jar 

    //     jar 
    baseName "${android.defaultConfig.versionName}"    //     class  
    //from('build/intermediates/jniLibs/release/')
    //   jar      
    into('/')
    //             
    exclude('BuildConfig.class', 'R.class')
    //  R$     
    exclude { it.name.startsWith('R$'); }
}


// ----------      AAR (   AAR,   AAR,   AAR     ) ----------

task aarRelease(type: Copy) {

    //     
    println "----------> AAR Release Task Start  " + aarOutPath
    //delete aarOutPath

    //       AAR    
    for (path in modulePaths) {
        println "Delete -> " + path
        delete path
    }

    //     AAR  (    )
    dependsOn 'assembleRelease'

    //     AAR ARR    
    for (path in modulePaths) {
        //       
        println "-> Start of current copy  End of current copy  AAR Release Task End 

좋은 웹페이지 즐겨찾기