AndroidStudio Gradle配置大全!開發必備!

1. 配置簽名

signingConfigs{
        debug{
            storeFile file("/xxx.keystore")
            storePassword ""
            keyAlias ""
            keyPassword ""
        }
        release{
            storeFile file("/xxx.keystore")
            storePassword ""
            keyAlias ""
            keyPassword ""
        }
 }

注意 :signingConfigs代碼塊一定要寫在buildTypes前面,否則會報下面這種錯: Could not find property ‘debugConfig’ on SigningConfig Container.

2.配置構建時生成apk的名稱

AndroidStudio 3.0 之前版本

android{
	android.applicationVariants.all { variant ->
	variant.outputs.each { output ->
	def file = output.outputFile
	if (file.name.endsWith(".apk")){
			output.outputFile = new File(file.parent, file.name.replace(file.name, "XXX"+"-V"+android.defaultConfig.versionCode + ".apk"))
	}
	}
}

AndroidStudio 3.0之後版本

android{
	android.applicationVariants.all { variant ->
	variant.outputs.all { output ->
		def fileName = "XXX-V"+"${variant.versionCode}-${variant.versionName}.apk"
	outputFileName = fileName
	}
	}
}

3.配置AndroidStudio兼容中文目錄

在gradle.properties 中 設置:

com.android.build.gradle.overridePathCheck=true

4.配置支持Lamba表達式

android{
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

5.使用 httpClient

android{
	useLibrary'org.apache.http.legacy'
}

未完續待

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章