android build.grade 脚本

打包配置java

执行命令  ./gradlew -Pmarket=app/config/markets.txt clean apkRelease   进行打包android

apply plugin: 'com.android.application'
apply plugin:'android-apt'
apply plugin: 'packer'
def AAVersion='3.2'

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.fifedu.preschool"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

    }

    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            resources.srcDirs = ['src/main/resources']
            aidl.srcDirs = ['src/main/aidl']
            renderscript.srcDirs = ['src/main']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
            jniLibs.srcDir 'src/main/jniLibs'
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    //执行lint检查,有任何的错误或者警告提示,都会终止构建,咱们能够将其关掉。
    lintOptions {
        abortOnError false
    }

    //签名
    signingConfigs {
        debug {
            storeFile file("/Users/weidingqiang/.android/debug.keystore")
        }
        release {
            //这样写就得把demo.jk文件放在项目目录
            storeFile file("/Users/weidingqiang/.android/key.jks")
            storePassword "123456"
            keyAlias "hello"
            keyPassword "123456"
        }
    }

    buildTypes {
        debug {
            // 显示Log
            buildConfigField "boolean", "LOG_DEBUG", "true"

            versionNameSuffix "-debug"
            minifyEnabled false
            zipAlignEnabled false
            shrinkResources false
            signingConfig signingConfigs.debug
        }

        release {
            // 不显示Log
            buildConfigField "boolean", "LOG_DEBUG", "false"
            //混淆
            minifyEnabled true
            //Zipalign优化
            zipAlignEnabled true

            multiDexEnabled true
            // 移除无用的resource文件
            shrinkResources true
            //前一部分表明系统默认的android程序的混淆文件,该文件已经包含了基本的混淆声明
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            //签名
            signingConfig signingConfigs.release
        }
    }
//    buildTypes {
//        release {
//            minifyEnabled true
//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//        }
//    }
}

dependencies {
   complie 'com.mcxiaoke.gradle:packer-helper:1.0.4' compile fileTree(dir:
'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1' apt "org.androidannotations:androidannotations:$AAVersion" compile "org.androidannotations:androidannotations-api:$AAVersion" compile 'com.mcxiaoke.volley:library:1.0.19' compile 'com.github.bumptech.glide:volley-integration:1.0.+' // compile 'com.github.bumptech.glide:glide:3.6.1' compile 'com.zhy:autolayout:1.3.6' compile 'de.greenrobot:eventbus:2.4.0' // compile files('libs/log4j-1.2.17.jar') // compile files('libs/android-logging-log4j-1.0.3.jar') // compile files('libs/AMap_2DMap_V2.8.0_20151231.jar') // compile files('libs/AMap_Location_v2.3.0_20160112.jar') // compile files('libs/AMap_Search_V2.8.0_20160105.jar') } apt { arguments { androidManifestFile variant.outputs[0].processResources.manifestFile resourcePackageName "com.fifedu.preschool" } }
packer {
archiveOutput = file(new File(project.rootProject.buildDir.path, "myapks"))
}
 

 二、默认打包git

执行命令  github

  • ./gradlew assembleDebug 编译并打Debug包api

  • ./gradlew assembleRelease 编译并打Release的包app

apply plugin: 'com.android.application'
apply plugin:'android-apt'
def AAVersion='3.2'

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.fifedu.preschool"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        // dex突破65535的限制
//        multiDexEnabled true
        // AndroidManifest.xml 里面UMENG_CHANNEL的value为 ${UMENG_CHANNEL_VALUE}
        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "channel_name"]
    }

    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            resources.srcDirs = ['src/main/resources']
            aidl.srcDirs = ['src/main/aidl']
            renderscript.srcDirs = ['src/main']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
            jniLibs.srcDir 'src/main/jniLibs'
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    //执行lint检查,有任何的错误或者警告提示,都会终止构建,咱们能够将其关掉。
    lintOptions {
        abortOnError false
    }

    //签名
    signingConfigs {
        debug {
            storeFile file("/Users/weidingqiang/.android/debug.keystore")
        }
        release {
            //这样写就得把demo.jk文件放在项目目录
            storeFile file("/Users/weidingqiang/.android/key.jks")
            storePassword "123456"
            keyAlias "hello"
            keyPassword "123456"
        }
    }

    buildTypes {
        debug {
            // 显示Log
            buildConfigField "boolean", "LOG_DEBUG", "true"

            versionNameSuffix "-debug"
            minifyEnabled false
            zipAlignEnabled false
            shrinkResources false
            signingConfig signingConfigs.debug
        }

        release {
            // 不显示Log
            buildConfigField "boolean", "LOG_DEBUG", "false"
            //混淆
            minifyEnabled true
            //Zipalign优化
            zipAlignEnabled true

            multiDexEnabled true
            // 移除无用的resource文件
            shrinkResources true
            //前一部分表明系统默认的android程序的混淆文件,该文件已经包含了基本的混淆声明
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            //签名
            signingConfig signingConfigs.release
        }
    }

//开启后 会报错 must be specified after an input jar, or it will be empty.
//不清楚为何

//渠道Flavors,配置不一样风格的app
    productFlavors {
        GooglePlay {}
//        xiaomi {}
//        umeng {}
//        _360 {}
//        baidu {}
//        wandoujia {}
    }
    //批量配置
    productFlavors.all { flavor ->
        flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.github.bumptech.glide:volley-integration:1.0.+'
    //    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.zhy:autolayout:1.3.6'
    compile 'de.greenrobot:eventbus:2.4.0'
//    compile files('libs/log4j-1.2.17.jar')
//    compile files('libs/android-logging-log4j-1.0.3.jar')
//    compile files('libs/AMap_2DMap_V2.8.0_20151231.jar')
//    compile files('libs/AMap_Location_v2.3.0_20160112.jar')
//    compile files('libs/AMap_Search_V2.8.0_20160105.jar')
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName "com.fifedu.preschool"
    }
}