tzutalin / dlib-android-app

:dragon: Android app to demo dlib-android(https://github.com/tzutalin/dlib-android). Use the prebuilt shared-lib built from dlib-android
Apache License 2.0
678 stars 246 forks source link

What's purpose of generating aar? #61

Open liuyibox opened 4 years ago

liuyibox commented 4 years ago

Please correct me if I am wrong. The code below in the dlib build.gradle seems to generate aar. Why we need aar? I removed this part and the app seems to be working. Also, if possible, could you go through the code below briefly such that I can get more understanding of this build.gradle file;


apply plugin: 'com.jakewharton.hugo'

// call regular ndk-build(.cmd) script from app directory
def GetNDKDir()  {
    def localProperties = new Properties()

    def NDK_SEARCH_VARS = ['ANDROID_NDK_HOME', 'ANDROID_NDK_ROOT', 'NDKROOT', 'NDKHOME']
    def ndk_path = null

    def lim = (Os.isFamily(Os.FAMILY_WINDOWS)) ? '\\' : '/'

    // Search Local.Properties file
    try {
        localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
        def ndkDir = localProperties.getProperty('ndk.dir')
        ndk_path = ndkDir != null ? ndkDir + lim : null;
    } catch (java.io.FileNotFoundException e) {
        println 'local.properties file not found'
    }

    // Search env var
    if (ndk_path == null){
        for (String var : NDK_SEARCH_VARS) {
            def v = System.getenv(var)

            if (v != null) {
                ndk_path = v + lim
                println "found in System Environment *$var = " + ndk_path
                break
            }
        }
    } else {
        println 'found in local.properties *NDK_PATH = ' + ndk_path
    }

    if (ndk_path == null) {
        println 'No NDK_PATH found'
        ndk_path = ''
    }
    return ndk_path
}

def NDKCommand() {
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        return GetNDKDir() + "ndk-build.cmd"
    } else {
        return GetNDKDir() + "ndk-build"
    }
}

apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

def siteUrl = 'https://github.com/tzutalin/dlib-android-app'      // Homepage URL of the library
def gitUrl = 'https://github.com/tzutalin/dlib-android-app.git'   // Git repository URL

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                name 'An Android library to wrap dlib library'
                url siteUrl
                // Set your license
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id 'tzutalin'
                        name 'tzutalin'
                        email 'tzu.ta.lin@gmail.com'
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl

                }
            }
        }
    }
}

task generateSourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier 'sources'
}

task generateJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath()
            .join(File.pathSeparator))
    classpath += configurations.javadocDeps
}

task generateJavadocsJar(type: Jar) {
    from generateJavadocs.destinationDir
    classifier 'javadoc'
}
generateJavadocsJar.dependsOn generateJavadocs

artifacts {
    archives generateJavadocsJar
    archives generateSourcesJar
}

Properties properties = new Properties()
if(project.rootProject.file('local.properties').isFile()) {
    properties.load(project.rootProject.file('local.properties').newDataInputStream())

    bintray {
        user = properties.getProperty("bintray.user")
        key = properties.getProperty("bintray.apikey")

        configurations = ['archives']
        pkg {
            repo = "maven"
            name = "dlib-android-app"
            version {
                name = "${rootProject.ext.releaseVersionName}"
                desc = 'An Android library to wrap dlib library'
                released  = new Date()
                vcsTag = "${rootProject.ext.releaseVersionName}"
            }

            websiteUrl = siteUrl
            vcsUrl = gitUrl
            licenses = ["Apache-2.0"]
            publish = true
        }
        configurations = ['archives']
    }
}