Android Studio自從更新3.0,gradle更新3.1.3之后,build.gradle文件中outputfile就不可用了,會(huì)報(bào)錯(cuò),既Cannot set the value of read-only property 'outputFile' for object of type com.android.build.gradle.internal.api.LibraryVariantOutputImpl.
創(chuàng)新互聯(lián)建站是一家集網(wǎng)站建設(shè),新田企業(yè)網(wǎng)站建設(shè),新田品牌網(wǎng)站建設(shè),網(wǎng)站定制,新田網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,新田網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
所以如果要打包aar,使用自定義路徑和文件名稱,需要使用新的方法。
如果使用:
apply plugin: 'com.android.library'
就是打包aar。
以下是具體的代碼,可以直接使用。直接放在build.gradle文件最外面即可使用
android.libraryVariants.all { variant ->
????variant.outputs.all {
????????// 自定義輸出路徑
// variant.getPackageApplication().outputDirectory = new File("C:\\1")
????????// 自定義文件名{示例:AppName-Flavor-debug-v1.0.0_201807301409}
????????outputFileName = "test.aar"
????}
}
//掛接自定義task到構(gòu)建過(guò)程中
this.project.afterEvaluate { project ->
// ???獲得build task
????def buildTask = project.tasks.getByName('build')
????if (buildTask == null) {
????????throw GradleException('the build task is not found')
????}
????buildTask.doLast {
????????copyTask.execute()
????}
}
//自定義copyApk task
task copyTask {
????doLast {
????????def fileName = "test.aar"
// ???????拷貝文件的始發(fā)地
? ??function(){ //交易品種?http://www.fx61.com/faq/muniu/447.html
????????def sourceFile = "/build/outputs/aar/" + fileName
// ???????指定文件拷貝的目的地
????????def destationFile = new File("C:\\1 ")
????????try {
// ???????????判斷文件夾是否存在
????????????if (!destationFile.exists()) {
????????????????destationFile.mkdir()
????????????}
????????????//拷貝
????????????copy {
????????????????from sourceFile
????????????????into destationFile
????????????????rename {
????????????????????fileName
????????????????}
????????????}
????????} catch (Exception e) {
????????????e.printStackTrace()
????????}
????}
}
上面build之后就在c:\1目錄下面去查找對(duì)應(yīng)的aar即可
當(dāng)然如果使用
apply plugin: 'com.android.application'
就更簡(jiǎn)單了,直接在最外圍放以下代碼即可
android.applicationVariants.all { variant ->
????variant.outputs.all {
????????// 自定義輸出路徑
????????variant.getPackageApplication().outputDirectory = new File("C:\\1")
????????// 自定義文件名{示例:AppName-Flavor-debug-v1.0.0_201807301409}
????????outputFileName = "test.aar"
????}
}
分享名稱:AndroidStudio3.0以后outputfile不能用更改
當(dāng)前網(wǎng)址:http://muchs.cn/article48/gheihp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、動(dòng)態(tài)網(wǎng)站、Google、微信公眾號(hào)、網(wǎng)站建設(shè)、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)