亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

淺析Android Studio 3.0 升級(jí)各種坑(推薦)

 更新時(shí)間:2017年11月06日 14:22:25   投稿:mrr  
本文是小編給大家收藏整理的關(guān)于Android Studio 3.0 升級(jí)后遇到的一些坑,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧

點(diǎn)擊 Check for Updates 增量更新:

下載完成,會(huì)提示更新 您將 Gradle 更新至 4.1:

這里建議您對(duì)老項(xiàng)目先暫時(shí)點(diǎn)擊 Don't remind me on this project,以防有坑。當(dāng)然我不入地獄誰入地獄,我點(diǎn) Update,于是問題來了,一直處于下載中,不過,莫擔(dān)心,我下載好了,公眾號(hào)聊天界面回復(fù)「 gradle-4.1-all 」,下載 gradle-4.1-all.zip 文件,放到:

重啟 Android Studio。

gradle 目錄:

Mac系統(tǒng)默認(rèn):/Users/(用戶名)/.gradle

Windows系統(tǒng)默認(rèn):C:\Users(用戶名).gradle

修改舊項(xiàng)目

首先我們新建項(xiàng)目,看看發(fā)生了哪些變化。

1、app/build.gradle

buildToolsVersion:這里沒有構(gòu)建工具的版本 buildToolsVersion 屬性了,Android Studio 3.0 默認(rèn)情況下,插件會(huì)自動(dòng)為您使用的 Android 插件版本使用最低要求的構(gòu)建工具版本;

implementation:由以前的 compile 改成了 implementation。老版本的構(gòu)建關(guān)鍵字 compile 被廢棄了,而是改成了這兩個(gè):api:同 compile 作用一樣,即認(rèn)為本 module 將會(huì)泄露其依賴的 module 的內(nèi)容;

implementation:本 module 不會(huì)通過自身的接口向外部暴露其依賴 module 的內(nèi)容。

2、項(xiàng)目 build.gradle

google():Android Studio 3.0 現(xiàn)在默認(rèn)使用 Google 的 Maven 存儲(chǔ)庫,而不是依賴于 Android SDK Manager 來獲取 Android 支持庫,Google Play 服務(wù),F(xiàn)irebase 和其他依賴項(xiàng)的更新;

build.gradle:指定的是Gradle插件的版本,由之前的 2.3.3 改成了 3.0.0。

3、gradle-wrapper.properties

gradle-wrapper.properties 中配置的是的 Gradle 的版本。

可以對(duì)老項(xiàng)目就以上幾點(diǎn)進(jìn)行修改。

butterknife

如果您在 lib 里使用了 butterknife,會(huì)遇到以下錯(cuò)誤:


網(wǎng)上說將 apply plugin: ‘com.jakewharton.butterknife' 注掉,是能解決問題,但是對(duì)于 lib 里使用了 butterknife 依舊報(bào) R2 找不到,還得放開 apply plugin: ‘com.jakewharton.butterknife',最后我只能退而求其次,將 build.gradle 中 3.0.0 改成之前的 2.3.3,解決。

打包自定義 APK 文件名

打包時(shí),要是自定義輸出 APK 文件名可以這樣做:

buildTypes {
  release {
    minifyEnabledfalse
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    applicationVariants.all { variant ->
      if (variant.buildType.name == 'release') {
        variant.outputs.each { output ->
          def outputFile = output.outputFile
          if (outputFile !=null && outputFile.name.endsWith('.apk')) {
            def fileName = "Sample_v${defaultConfig.versionName}_${releaseTime()}_${variant.flavorName}.apk"
            output.outputFile = new File(outputFile.parent, fileName)
          }
        }
      }
    }
  }
}

使用 Gradle Plugin 3.0.0 時(shí)報(bào)錯(cuò):

Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=release, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl. Open File

需要修改 each() 和 outputFile() 方法為 all() 和 outputFileName:

buildTypes {
  release {
    minifyEnabledfalse
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    applicationVariants.all { variant ->
      if (variant.buildType.name == 'release') {
        variant.outputs.all { output ->
          def outputFile = output.outputFile
          if (outputFile !=null && outputFile.name.endsWith('.apk')) {
            def fileName = "Sample_v${defaultConfig.versionName}_${releaseTime()}_${variant.flavorName}.apk"
            output.outputFileName = new File(outputFile.parent, fileName)
          }
        }
      }
    }
  }
}

補(bǔ)充

build.gradle 和 gradle-wrapper.properties 區(qū)別,了解更多: https://developer.android.com/studio/releases/gradle-plugin.html

最后

目前遇到這些坑,歡迎一起吐槽您在升級(jí)開發(fā)遇到的坑,這次升級(jí)又折騰了很久。另外如果需要gradle-4.1-all.zip 文件,公眾號(hào)「吳小龍同學(xué)」聊天界面回復(fù)「 gradle-4.1-all 」獲取。

PS:下面給大家補(bǔ)充介紹android studio升級(jí)到3.0的各種坑。

項(xiàng)目的build.gradle(不是module):

解決方案:

關(guān)掉AAPT2即可

在Project/gradle.properties中添加 android.enableAapt2=false

總結(jié)

以上所述是小編給大家介紹的淺析Android Studio 3.0 升級(jí)各種坑(推薦),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論