Android 项目 利用Gradle 一键打包

1、在项目中如果有用到多渠道打包我们可以用Android Studio 的 Gradle来管理一键打包。
我的项目配置: 友盟统计 在AndroidManifest.xml里面:

        <!--友盟统计-->
        <meta-data
            android:name="UMENG_APPKEY"
            android:value="55e957ece0f55a412200064a"></meta-data>
        <meta-data
            android:name="UMENG_CHANNEL"
            android:value="${UMENG_CHANNEL_VALUE}" />

2、在项目build.gradle 中配置:贴上自己的Gradle 全部配置:

apply plugin: 'com.android.application'



buildscript {
    repositories {
        jcenter { url "http://jcenter.bintray.com/" }
//        mavenCentral()
//        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

allprojects {
    repositories {
        mavenCentral()
//        mavenLocal()
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.android.support:multidex:1.0.0'
    compile project(':ApacheHttpclient_4.3')
    compile project(':FacebookSDK')
    compile project(':google-play-services_lib')
    compile project(':ijkmediaplayer')
    compile project(':ijkmediaplayer-arm64-v8a')
    compile project(':ijkmediaplayer-x86')
    compile project(':ijkmediawidget')
    compile project(':PulltorefreshLibrary')
    compile project(':WeiboSDK')
    compile project(':Librarymodule')
    compile project(':PagerSlidingTab')
    //for 65k method numbers limit
    compile project(':PagerSlidingTab')
    //    compile files('libs/alipaySDK-20150818.jar')
    //    compile files('libs/mimicam.jar')
    //    compile files('libs/okhttp-2.5.0.jar')
    //    compile files('libs/mta-sdk-1.6.2.jar')
    //    compile files('libs/open_sdk_r5043.jar')
    //    compile files('libs/com.umeng.message.lib_v2.4.1.jar')
    //    compile files('libs/RennSDK-Android.jar')
    //    compile files('libs/libammsdk.jar')
    compile files('libs/umeng-analytics-game-v5.5.3.0.jar')
    compile files('libs/xUtils-2.6.14.jar')
    compile files('libs/okhttp-2.5.0.jar')
}

apply plugin: 'com.android.application'
android {

    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    lintOptions {
        abortOnError false
    }

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 22
        applicationId "tv.weilive.giraffe"
        // Enabling multidex support. for 65k method numbers limit
        multiDexEnabled = true;
    }

    signingConfigs {
        release {
            storeFile file("weilive.keystore")
            storePassword "12677484"
            keyAlias "weilive"
            keyPassword "12677484"
        }
    }

    //设置  debuggable
    buildTypes {
        release {
            debuggable false
            signingConfig signingConfigs.release
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            jni.srcDirs = []
            jniLibs.srcDirs = ['libs']
            java.srcDirs = ['src/main/java']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['assets']
            aidl.srcDirs = ['src/main/aidl']
        }
        release.setRoot('build-types/release')
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }

    //=======以下是一键打多渠道打包 

    productFlavors {

        liantong_inow_yoyo {}
//        baidu2_inow_yoyo {}
//        baidu3_inow_yoyo {}
//        baidu4_inow_yoyo {}
//        suoping1_inow_yoyo {}
//        suoping2_inow_yoyo {}
//        suoping3_inow_yoyo {}
//        suoping4_inow_yoyo {}
//        suoping5_inow_yoyo {}


        productFlavors.all { flavor ->
            flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
        }

    }


}

project.ext {
    compileSdkVersion = 22
    buildToolsVersion = "22.0.1"
}

3、在Android Studio 的Terminal 中输入gradlew assembleRelease。

注意:如果不能执行gradlew assembleRelease。命令,请检测自己是不是已经下载了gradle.properties
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值