build: upgrade build.gradle to run in Android Studio panda 4
This commit is contained in:
129
app/build.gradle
129
app/build.gradle
@@ -5,23 +5,11 @@ static def appName() {
|
||||
}
|
||||
|
||||
static def releaseTime() {
|
||||
return new Date().format("yyyyMMdd-HHmmss", TimeZone.getDefault())
|
||||
return new Date().format("yyyyMMdd_HHmmss", TimeZone.getDefault())
|
||||
}
|
||||
|
||||
android {
|
||||
// gradle.projectsEvaluated {
|
||||
// tasks.withType(JavaCompile) {
|
||||
// Set<File> fileSet = options.bootstrapClasspath.getFiles()
|
||||
// List<File> newFileList = new ArrayList<>();
|
||||
// //JAVA语法,可连续调用,输入参数建议为相对路径
|
||||
// newFileList.add(new File("libs/framework.jar"))
|
||||
// //最后将原始参数添加
|
||||
// newFileList.addAll(fileSet)
|
||||
// options.bootstrapClasspath = files(
|
||||
// newFileList.toArray()
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
namespace "com.fuying.sn"
|
||||
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.3"
|
||||
@@ -39,25 +27,24 @@ android {
|
||||
// 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
includeCompileClasspath true
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
checkReleaseBuilds false
|
||||
// Or, if you prefer, you can continue to check for errors in release builds,
|
||||
// but continue the build even when errors are found:
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
dataBinding {
|
||||
enabled true
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
dataBinding true
|
||||
buildConfig true
|
||||
aidl true
|
||||
}
|
||||
|
||||
//多版本
|
||||
@@ -460,14 +447,6 @@ android {
|
||||
zipAlignEnabled true
|
||||
minifyEnabled false
|
||||
signingConfig signingConfigs.mtk
|
||||
applicationVariants.all { variant ->
|
||||
variant.outputs.each { output ->
|
||||
if (outputFile != null) {
|
||||
def fileName = "${appName()}_${variant.versionCode}_V${variant.versionName}_${releaseTime()}_${buildType.name}.apk"
|
||||
output.outputFileName = fileName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
release {
|
||||
@@ -480,28 +459,28 @@ android {
|
||||
//混淆
|
||||
minifyEnabled false
|
||||
//前一部分代表系统默认的android程序的混淆文件,该文件已经包含了基本的混淆声明,后一个文件是自己的定义混淆文件
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
//签名
|
||||
signingConfig signingConfigs.mtk
|
||||
// 将release版本的包名重命名,加上版本及日期
|
||||
applicationVariants.all { variant ->
|
||||
variant.outputs.each { output ->
|
||||
def outputFile = ""
|
||||
if (outputFile != null) {
|
||||
def fileName = "${appName()}_${variant.versionCode}_V${variant.versionName}_${releaseTime()}_${buildType.name}.apk"
|
||||
output.outputFileName = new File(outputFile, fileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
checkReleaseBuilds false
|
||||
// Or, if you prefer, you can continue to check for errors in release builds,
|
||||
// but continue the build even when errors are found:
|
||||
abortOnError false
|
||||
// Add application variant configuration here instead
|
||||
applicationVariants.all { variant ->
|
||||
variant.outputs.each { output ->
|
||||
def buildType = variant.buildType.name
|
||||
def fileName = ""
|
||||
|
||||
if (buildType.contains("debug")) {
|
||||
fileName = "${appName()}_V${defaultConfig.versionName}_${releaseTime()}.apk"
|
||||
} else {
|
||||
fileName = "${appName()}_${variant.versionCode}_V${variant.versionName}_${releaseTime()}_${buildType}.apk"
|
||||
}
|
||||
|
||||
output.outputFileName = fileName
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -581,23 +560,33 @@ dependencies {
|
||||
implementation 'com.github.getActivity:Toaster:12.6'
|
||||
}
|
||||
|
||||
preBuild {
|
||||
doLast {
|
||||
def imlFile = file(project.name + ".iml")
|
||||
println 'Change ' + project.name + '.iml order'
|
||||
try {
|
||||
def parsedXml = (new XmlParser()).parse(imlFile)
|
||||
def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
|
||||
parsedXml.component[1].remove(jdkNode)
|
||||
def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform"
|
||||
println 'what' + sdkString
|
||||
new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])
|
||||
groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
|
||||
} catch (FileNotFoundException e) {
|
||||
// nop, iml not found
|
||||
println "no iml found"
|
||||
}
|
||||
// 在 dependencies 之后添加
|
||||
project.afterEvaluate {
|
||||
android.applicationVariants.all { variant ->
|
||||
variant.javaCompileProvider.get().options.bootstrapClasspath = files(
|
||||
file('libs/framework.jar'),
|
||||
android.getBootClasspath()
|
||||
)
|
||||
}
|
||||
//https://www.pianshen.com/article/93481144911/
|
||||
//使用系统编译后的framework.jar
|
||||
}
|
||||
|
||||
//preBuild {
|
||||
// doLast {
|
||||
// def imlFile = file(project.name + ".iml")
|
||||
// println 'Change ' + project.name + '.iml order'
|
||||
// try {
|
||||
// def parsedXml = (new XmlParser()).parse(imlFile)
|
||||
// def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
|
||||
// parsedXml.component[1].remove(jdkNode)
|
||||
// def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform"
|
||||
// println 'what' + sdkString
|
||||
// new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])
|
||||
// groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
|
||||
// } catch (FileNotFoundException e) {
|
||||
// // nop, iml not found
|
||||
// println "no iml found"
|
||||
// }
|
||||
// }
|
||||
// //https://www.pianshen.com/article/93481144911/
|
||||
// //使用系统编译后的framework.jar
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user