官方參考
成都網(wǎng)站制作、成都做網(wǎng)站的開發(fā),更需要了解用戶,從用戶角度來建設(shè)網(wǎng)站,獲得較好的用戶體驗。成都創(chuàng)新互聯(lián)公司多年互聯(lián)網(wǎng)經(jīng)驗,見的多,溝通容易、能幫助客戶提出的運營建議。作為成都一家網(wǎng)絡(luò)公司,打造的就是網(wǎng)站建設(shè)產(chǎn)品直銷的概念。選擇成都創(chuàng)新互聯(lián)公司,不只是建站,我們把建站作為產(chǎn)品,不斷的更新、完善,讓每位來訪用戶感受到浩方產(chǎn)品的價值服務(wù)。https://developer.android.com/studio/build/gradle-tips.html
以下都是經(jīng)過實戰(zhàn)總結(jié)、多次調(diào)整的gradle配置方案,歡迎采用,提意見
applicationVariants.all { variant ->
variant.outputs.each { output ->
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
if ("debug" == variant.buildType.name) {
def apkFile = new File(
output.outputFile.getParent(),
"XXX_App_${variant.versionName}_${buildTime()}_debug.apk")
output.outputFile = apkFile
} else if ("release" == variant.buildType.name) {
def apkFile = new File(
output.outputFile.getParent(),
"XXX_App_${variant.versionName}_release.apk")
output.outputFile = apkFile
}
}
}
if (variant.buildType.name == "debug") {
variant.mergedFlavor.versionName = variant.mergedFlavor.versionName + "." + buildTime();
}
}
def buildTime() {
def date = new Date()
def formattedDate = date.format('yyyyMMdd')
return formattedDate
}
在build.gradle中改寫引用方式
compileSdkVersion rootProject.ext.android["compileSdkVersion"]
在config.gradle中配置如下
ext {
android = [
compileSdkVersion: 23,
buildToolsVersion: "25.0.0",
minSdkVersion : 15,
targetSdkVersion : 22,
minifyEnabled : false,
minifyFile : rootProject.file('proguard-rules.pro'),
]
version = [
"supportVersion" : "25.0.0"
]
dependencies = [
"support_v4": "com.android.support:support-v4:${version["supportVersion"]}",
"appcompat-v7" : "com.android.support:appcompat-v7:${version["supportVersion"]}",
"recycleview" : "com.android.support:recyclerview-v7:${version["supportVersion"]}",
"multidex" : "com.android.support:multidex:1.0.1",
"junit" : "junit:junit:4.12",
//Baidu location
"baidu" : "libs/BaiduLBS_Android.jar"
] }
manifestPlaceholders 可以在清單文件中配置好,格式如下
android:name="appid"android:value="12334"/>同時在build.gradle中引用
productFlavors {normal {applicationId "com.xxx"manifestPlaceholders = [xxx: "0", appid: "xxx" , host:"xxx"];}productone {applicationId "com.xxx"manifestPlaceholders = [xxx: "0", appid: "xxx" , host:"xxx"];}producttwo {applicationId "com.xxx"manifestPlaceholders = [xxx: "0", appid: "xxx" , host:"xxx"];}}配置不同product的資源和jni來源
sourceSets{normal {jniLibs.srcDirs = ['src/normalIn/jniLibsIn/']assets.srcDirs = ['src/normalIn/assetsIn']}productone {jniLibs.srcDirs = ['src/normalIn/jniLibsIn/']assets.srcDirs = ['src/normalIn/assetsIn']}}代碼中調(diào)用方法:
try {ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);if (info != null && info.metaData != null) {meta = info.metaData.getInt("appid");}} catch (PackageManager.NameNotFoundException e) {e.printStackTrace();}
四 flavor版本判斷
// build.gradle in application moduleandroid {productFlavors {googlePlay {}wandoujia {}}}if (getGradle().getStartParameter().getTaskRequests().toString().contains("GooglePlay")) {// Google Play 版本才應(yīng)用該插件apply plugin: 'com.google.gms.google-services'}另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
文章標(biāo)題:超實用!打包、配置項目必備的Gradle實戰(zhàn)技巧!-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://weahome.cn/article/djeehi.html