多渠道打包相关

通用配置文件

apply plugin: 'com.android.application'

android {
    //签名信息,通过setting可以设置生成
    signingConfigs {
        releasesign {
            keyAlias 'alias'
            keyPassword '密码'
            storeFile file('F:/appsignepyen/forqudao.jks')
            storePassword '密码'
        }
    }
    //-----------------------
    //--无关渠道
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.foruse.qudao"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    //-------------
    //设置debugherelease版本分别是用的签名  可以有区别
    buildTypes {
       
debug {
    signingConfig signingConfigs.releasesign
}
release {
    signingConfig signingConfigs.releasesign
}
} //不同的渠道包信息 productFlavors { meizu {//下面这几个信息不配置默认使用工程的 minSdkVersion 15 targetSdkVersion 23 versionCode 1 signingConfig signingConfigs.releasesign //这个是必要的 versionName '1.0.0' manifestPlaceholders = [ UMENG_CHANNEL_VALUE: "meizu"] //配置友盟渠道信息 } //可以粘贴复制,或者通过settting设置 google { minSdkVersion 15 signingConfig signingConfigs.releasesign //携带签名信息 manifestPlaceholders = [ UMENG_CHANNEL_VALUE: "google"] //配置友盟渠道信息 } }
//
   
//    productFlavors {  //极简样式
//        wandoujia {}
//        baidu {}
//        c360 {}
//        uc {}
//        productFlavors.all { flavor ->
//            flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
//        }
//    }

  //----------------------------- // 设置输出apk的名字 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) } } } //------------------} // 无关渠道dependencies { }

<meta-data
    android:name="UMENG_CHANNEL"
    android:value="${UMENG_CHANNEL_VALUE}" />  //在清单文件添加这个

// "当前渠道  "+getMetaData(this, "UMENG_CHANNEL"));
  private static String getMetaData(Context context, String key) {
      try {
          ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
                  context.getPackageName(), PackageManager.GET_META_DATA);
          Object value = ai.metaData.get(key);
          if (value != null) {
              return value.toString();
          }
      } catch (Exception e) {
      }
      return null;
  }

们直接在dos命令定位到Demo4的项目目录(如果你用的是win7,可以直接先进入到项目目录,然后在空白处,先按住shift,再点右键选择"在此处打开命令窗口")

a: gradlew clean

b:gradlew assembleRelease    // 这是编译并打Release的包  在app--build目录下


可能出现

: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。

这个时候在build.gradle中添加如下配置:

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
        }
    }
}

c:gradlew assembleDebug   //这是编译并打Debug包

d:

如果我们想打包wandoujia渠道的release版本,执行如下命令就好了: 
gradle assembleWandoujiaRelease   //必须有这个字段,不区分大小写

如果我们只打wandoujia渠道版本,则: 
gradle assembleWandoujia //
此命令会生成wandoujia渠道的Release和Debug版本

设置sign  http://download.csdn.net/detail/u013134722/9848983

参考: https://my.oschina.net/aibenben/blog/370985

   http://blog.csdn.net/u013278099/article/details/50463577

发布了44 篇原创文章 · 获赞 20 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/u013134722/article/details/72626317