### Build文件配置
每個Module都有一個build.gradle文件,App都需要到build.gradle中去配置。
build文件路徑示例:...\yuanfengBBC\app\build.gradle。其中“IMDemo”為項目根目錄,“app”為Module目錄名,一般默認為“app”。
* 打包簽名配置
Build文件中配置打包時需要的簽名文件“yuanfeng.jks”,yuanfeng.jks的文件路徑為...\ImDemo\app\yuanfeng.jks
~~~
signingConfigs {
release {
keyAlias '123456'
keyPassword '123456'
storeFile file('yuanfeng.jks')
storePassword '123456'
}
}
~~~
* 項目版本信息
版本配置一般在項目創建的時候會自動根據開發環境生成,一般不需要修改。
~~~
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.yuanfengbbc.shop"
minSdkVersion 16
targetSdkVersion 21
versionCode 2
versionName "3.1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
sourceSets {
main {
jniLibs.srcDirs = ['libs']
java.srcDirs = ['src/main/java']
}
}
}
~~~
compileSdkVersion:App基于SDK版本號;
buildToolsVersion:build工具包版本;
applicationId:App唯一標示,默認與包名packageName一致;
minSdkVersion:App支持運行最低Sdk版本號,即最低支持在Android系統什么版本下運行;
versionCode:App版本號,代表App升級了多少次,每次升級的時候數值+1;
versionName:App版本名字,顯示在應用商店和手機App應用信息位置。
* compiler導包
開發過程中,我們會集成第三方SDK,在這里需要compiler一下包的地址,例如集成支付,分享等功能。
~~~
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations' })
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.3.0'//版本隨意(非必須,引用可以解決無法預覽問題)
testCompile 'junit:junit:4.12'
//ImageLoader加載圖片
compile files('libs/universal-image-loader-1.9.5.jar')
compile 'com.github.lovetuzitong:MultiImageSelector:1.2'
compile 'top.zibin:Luban:1.1.2'
//okHttp
compile 'com.squareup.okhttp:okhttp-urlconnection:1.6.0'
//網絡請求
compile files('libs/httpmime-4.1.2.jar')
compile files('libs/httpclient-4.3.6.jar')
compile files('libs/httpcore-4.3.3.jar')
//下拉刷新
compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.3'
//支付寶
compile files('libs/alipaySingle-20170510.jar')
//BASE64Decoder
compile files('libs/sun.misc.BASE64Decoder.jar')
//友盟分享
compile files('libs/umeng_social_api.jar')
compile files('libs/SocialSDK_WeiXin_Full.jar')
compile files('libs/SocialSDK_Sina_Simplify.jar')
compile files('libs/mta-sdk-1.6.2.jar')
compile 'com.zhy:autolayout:1.4.5'
//OkHttp網絡請求框架
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.okio:okio:1.5.0'
compile 'com.zhy:okhttputils:2.0.0'
//fastJson框架
compile 'com.alibaba:fastjson:1.2.22'
compile 'com.google.code.gson:gson:2.6.2'
//banner輪播圖
compile 'cn.bingoogolapple:bga-banner:2.1.7@aar'
compile 'com.tencent.bugly:crashreport:latest.release'
compile 'com.tencent.bugly:nativecrashreport:latest.release'
compile 'com.bigkoo:convenientbanner:2.0.5'
//微信支付
compile 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+'
compile 'cn.finalteam.rxgalleryfinal:library:1.0.1'
//butterknife
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.jakewharton:butterknife:8.5.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
//EventBus事件
compile 'org.greenrobot:eventbus:3.0.0'
//標簽控件
compile 'com.github.donkingliang:LabelsView:1.2.0'
}
~~~
* 指定打包后應用名稱
可以設置打包后生成的文件名,默認設置為項目名+版本名稱
~~~
//指定打包后應用名稱
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = outputFile.name.replace(".apk", "遠豐商城_${defaultConfig.versionName}.apk")
outputFileName = fileName
}
}
}
~~~
* 打包報MissingTranslation
打包時有可能會出現MissingTranslation錯誤導致Build Failed!
~~~
lintOptions {
abortOnError false
checkReleaseBuilds false
// 防止在發布的時候出現因MissingTranslation導致Build Failed!
disable 'MissingTranslation'
}
~~~