android {
//...
signingConfigs {
debug {
keyAlias 'hyrelease'
keyPassword 'password'
storeFile file('HyTech.jks')
storePassword "password"
}
release {
keyAlias 'hyrelease'
keyPassword 'password'
storeFile file('HyTech.jks')
storePassword "password"
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
buildConfigField "boolean", "LOG_DEBUG", "true"
minifyEnabled false
zipAlignEnabled true
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
signingConfig signingConfigs.release
buildConfigField "boolean", "LOG_DEBUG", "false"
minifyEnabled true
zipAlignEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
//...
}
複製代碼
android {
//...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
//...
}
複製代碼
普通的在App模塊中的aar,若是在子模塊中的aar須要寫成下面的寫法android
android {
//...
repositories {
flatDir {
dirs 'libs'
dirs project(':QrCode').file('libs')
}
}
//...
}
複製代碼
android {
//...
//聲明維度:產品
flavorDimensions "ProductFeature"
productFlavors {
RobotA {//機器人A
dimension "ProductFeature"
resValue "string", "app_name", "機器人A"
applicationId 'com.xxx.a'
versionCode = 9
versionName = '1.3.1'
manifestPlaceholders = [updateApkPathFlag: applicationId,
app_icon_x : "@mipmap/ic_launcher"]
buildConfigField "String", "channel", "\"RobotA\""
}
RobotB {//機器人B
dimension "ProductFeature"
resValue "string", "app_name", "機器人B"
applicationId 'com.xxx.b'
versionCode = 4
versionName = '1.0.3'
manifestPlaceholders = [updateApkPathFlag: applicationId,
app_icon_x : "@mipmap/ic_launcher_common"]
buildConfigField "String", "channel", "\"RobotB\""
}
}
//...
}
複製代碼
android {
//...
defaultConfig {
//...
resConfigs "zh", "en"
}
//...
}
複製代碼
android {
//...
defaultConfig {
//...
ndk {
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
}
}
//...
}
複製代碼
buildTypes {
debug {
signingConfig signingConfigs.debug
buildConfigField "boolean", "LOG_DEBUG", "true"
minifyEnabled false
zipAlignEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "channel", "\"test\""
}
release {
signingConfig signingConfigs.release
buildConfigField "boolean", "LOG_DEBUG", "false"
minifyEnabled true
zipAlignEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.all {
def buildTypeName = ''
if (buildType.name.contains("debug"))
buildTypeName = 'debug-'
outputFileName = "${variant.productFlavors[0].name}-${buildTypeName}${xVersionName}-${xVersionCode}.apk"
}
}
}
}
複製代碼
這裏,還在 debug 模式中,把字符串 channel 改成了 test。api
Java:bash
/*IDs*/
String Wx_Pay_App_Id = BuildConfig.WX_Pay_AppId;
複製代碼
Manifest:微信
<!-- 微信支付 -->
<activity
android:name=".wxapi.WXPayEntryActivity"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="${WX_Pay_AppId}" />
</intent-filter>
</activity>
複製代碼
build.gradle:app
def WX_Pay_AppId = "xxx"
android {
//...
defaultConfig {
//...
manifestPlaceholders = [
//微信支付APPID
WX_Pay_AppId : WX_Pay_AppId,
]
}
//...
buildTypes {
debug {
//...
buildConfigField "String", "WX_Pay_AppId", WX_Pay_AppId
//...
}
release {
//...
buildConfigField "String", "WX_Pay_AppId", WX_Pay_AppId
//...
}
}
//...
}
複製代碼