网站手机版如何制作,国内seo服务商,网站建设有什么出路,wordpress 主题排名目录 1.添加productFlavors的配置buildConfigFieldmanifestPlaceholdersresValue 2.设置apk文件的名称#xff0c;便于识别3.添加vasdolly、添加gradle脚本#xff08;windows#xff09; 作用#xff1a;一次性可以打多个apk包#xff0c;名字、包名、logo等可以不相同。… 目录 1.添加productFlavors的配置buildConfigFieldmanifestPlaceholdersresValue 2.设置apk文件的名称便于识别3.添加vasdolly、添加gradle脚本windows 作用一次性可以打多个apk包名字、包名、logo等可以不相同。解决了每次发版都要手动修改代码的问题,例如名字、logo等。
配置build.gradleapp
1.添加productFlavors的配置
android{.....
//设置风味的维度flavorDimensions [release]//productFlavors中有两套配置huawei、oppo。productFlavors {huawei {versionCode 8versionName 1.7.33dimension releaseapplicationId test.test.abcresValue string, file_provider_name_personal, applicationId .providermanifestPlaceholders [apkName: 语文,apkIcon: drawable/yuwen]ndk {abiFilters arm64-v8a//armeabi-v7a , arm64-v8a}buildConfigField int, COMPANY, 1}oppo {versionCode 7versionName 1.6.30dimension releaseapplicationId test.test.abcresValue string, file_provider_name_personal, applicationId .providermanifestPlaceholders [apkName: 数学,apkIcon: drawable/yuwen]ndk {abiFilters arm64-v8a//armeabi-v7a , arm64-v8a}buildConfigField int, COMPANY, 4}}
}buildConfigField int, COMPANY, 1buildConfigField
buildConfigField申明了一个常量方便在代码中进行使用。
BuildConfig文件
public final class BuildConfig {public static final int COMPANY 1;
}使用buildConfigField
public class MyApplication extends Application {Overridepublic void onCreate() {Constant.URL_PROTOCOLUSE http://xxx.xxx.cn/api/pro.jsp?company BuildConfig.COMPANY apptype getString(R.string.app_name);}
}manifestPlaceholders
设置在manifest中数据 manifestPlaceholders [apkName: 数学,apkIcon: drawable/yuwen]applicationandroid:name.MainApplicationandroid:allowBackupfalseandroid:icon${apkIcon}android:label${apkName}/applicationresValue
声明一个在Strings.xml中的字符串。
resValue string, file_provider_name_personal, applicationId .provider声明后会自动生成。
?xml version1.0 encodingutf-8?
resources!-- Automatically generated file. DO NOT MODIFY --string namefile_provider_name_personal translatablefalsetest.test.abc/string/resources2.设置apk文件的名称便于识别 static def releaseTime() {SimpleDateFormat formatter new SimpleDateFormat(yyyy-MM-dd);return formatter.format(new Date())
}
android {....applicationVariants.all { variant -variant.outputs.all { output -def outputFile output.outputFiledef fileNameif (outputFile ! null outputFile.name.endsWith(.apk)) {if (variant.buildType.name.equals(release)) {//如果是release包fileName ${productFlavors.name}-${buildType.name}-${productFlavors.versionName}- ${productFlavors.versionCode}-${releaseTime()}.apk} else if (variant.buildType.name.equals(debug)) {//如果是debug包fileName ${productFlavors.name}-${buildType.name}-${productFlavors.versionName}- ${productFlavors.versionCode}.apk}outputFileName fileName}}}
}打出的apk名字-包类型-版本名称-版本号 一次性打多个包使用assemble assemble执行完毕后在app/build/outputs/apk中寻找。大致样子如下
3.添加vasdolly、添加gradle脚本windows
vasdolly使用 https://github.com/Tencent/VasDolly
在build.gradle(app)文件中加入如下
Properties properties new Properties()
properties.load(project.rootProject.file(local.properties).newDataInputStream())
def sdkDir properties.getProperty(sdk.dir)
def buildToolsVersion 33.0.1//工具版本
def consolidatePath ./build/consolidate/
def storePwd //keystore文件密码
def alias //keystore文件alias
def keyPwd //keystore文件密码def jksPath C:\\Users\\xxx\\Desktop\\资料\\app.keystore//keystore文件路径
/*** 优化加签名*/
task batchSign {doLast {File consolidateDir new File(project.buildDir, consolidate/)consolidateDir.eachFile { apkFile -def unsignedFileName apkFile.getName()def lastchar unsignedFileName.indexOf(.apk)def fileName unsignedFileName.substring(0, lastchar)def zipalignedFileName ${fileName}_zipaligned.apkdef signedFileName ${fileName}_signed.apkdef buildToolsPath ${sdkDir}\\build-tools\\${buildToolsVersion}def command ${buildToolsPath}\\zipalign -f -p 4 ${consolidatePath}${unsignedFileName} ${consolidatePath}${zipalignedFileName} del ${project.buildDir}\\consolidate\\${unsignedFileName} ${buildToolsPath}\\apksigner sign --ks ${jksPath} --ks-pass pass:${storePwd} --ks-key-alias ${alias} --key-pass pass:${keyPwd} --out ${consolidatePath}${signedFileName} ${consolidatePath}${zipalignedFileName} del ${project.buildDir}\\consolidate\\${zipalignedFileName} del ${project.buildDir}\\consolidate\\${fileName}_signed.apk.idsigprintln(command)exec {ExecSpec execSpec -executable cmdargs /c, command}}}
}/*
将apk优化和签名后添加渠道
打渠道包*/
task makeChannel {def publishPath ./build/publish/doLast {def channels ./channels.txt //vasdolly的相关文件File consolidateDir new File(project.buildDir, consolidate/)consolidateDir.eachFile { apkFile -def command java -jar D:\\android\\gitdown\\VasDolly.jar put -c ${channels} ${apkFile.getAbsolutePath()} ${publishPath}try {exec {commandLine cmd, /c, command}} catch (Exception e) {e.printStackTrace()}}}
}task bundleAndChannel {dependsOn(batchSign)dependsOn(makeChannel)
}编译之后面在gradle中就会出现bundleAndChannel 准备加固、签名、渠道
在app/build/目录下创建consolidate和publish文件。 将360加固后的apk复制到app/build/consolidate文件中。 双击bundleAndChannel 等待编辑就可以了。