国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

淺談Android Studio 3.0 的一些小變化

2019-10-22 18:24:35
字體:
來源:轉載
供稿:網友

前言

一大早還在北京擁擠的地鐵里,我的CTO閆哥在微信里給我發了一條信息:Android Studio 3.0發布了。

為什么會這么關注Android Studio 3.0 的版本發布呢?主要是因為公司即將開發的新app準備使用Kotlin語言,而Android Studio 3.0 已經把Kotlin的語言支持內置進去了,這樣就省去了很多的麻煩,如果你還沒接觸過Kotlin語言,可以去百度一下 他們的官網,如果你現在使用的Java語言,那么你真是太幸運了,因為Kotlin對于你來說,將會非常簡單,例如像我這樣的,兩三天就可以幾乎應付大部分的開發了。

這里就不對Kotlin語言做過多的描述了,今天的重點,是我升級到Android Studio 3.0 以后的故事。

正文

來到公司打開電腦,升級Android Studio到3.0版本,編譯目前的工程。哎呀呀我擦擦,為什么報了好多的錯?別著急,我們慢慢解決這些問題。

Android,Studio,3.0變化,3.0

Android Studio的自帶Gradle版本是4.1,插件版本是3.0.0,所以如果你使用的是老版本,就會出現一些小的兼容問題,我們看看報了哪些錯誤呢:

問題1

Error:(72, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=appDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

outputFile是只讀屬性,不可以對他進行修改

看一下我的gradle里面的代碼:

// 定義生成的apk的名稱def apkName;buildTypes { release {  ...  // 定義release版本生成的apk的名字  apkName = "xxx" + VERSION_NAME + "_release.apk"; } debug {  ...  // 定義debug版本生成的apk的名字  apkName = "ugirls_" + VERSION_NAME + "_debug.apk"; }}// 修改apk build的名字android.applicationVariants.all { variant -> variant.outputs.each { output ->  def outputFile = output.outputFile  if (outputFile != null && outputFile.name.endsWith('.apk')) {    //這里使用之前定義apk文件名稱    output.outputFile = new File(outputFile.parent, apkName)  } }}

這段代碼的功能是修改Build命令生成的apk的名稱,因為outputFile變成只讀屬性,所以報錯。

修改后:

// 之前代碼保持不變// 修改apk build的名字android.applicationVariants.all { variant -> variant.outputs.all {  if (outputFileName.endsWith('.apk')) {   //這里使用之前定義apk文件名稱   outputFileName = apkName  } }}

把each修改為all,然后通過outputFileName修改生成的apk的名稱。

如果你提示沒有找到all方法或者是未找到outputFileName,你可以先把這個功能注釋掉,等其他問題都解決了,再打開就可以解決這個問題了。

問題2

Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

所有的flavor屬性應當屬于同一個命名空間

看著問題似乎有點深奧,其實就是需要我們為flavors設置一個版本,統一使用相同版本的flavors。

defaultConfig { targetSdkVersion:*** minSdkVersion :*** versionCode:*** versionName :*** //為flavor設置一個版本,命名是隨意的 flavorDimensions "versionCode"}

問題3

Android,Studio,3.0變化,3.0

有些庫不能被正常引用,例如我使用的multidex,在上面的截圖中已經提示我們如何解決這個問題

buildscript { repositories {  ...  // 添加google庫的依賴  google() } dependencies {  ... }}

問題4

Error:(2638) error: style attribute '@android:attr/windowEnterAnimation' not found.

提示我們找不到@android:attr/windowEnterAnimation,因為已經不支持@開頭使用android自帶的屬性,我們只要把@符號刪掉就可以了。

修改前:

<style name="ToastStyle" parent="android:Animation">  <item name="@android:windowEnterAnimation">@anim/push_fade_in</item>  <item name="@android:windowExitAnimation">@anim/push_fade_out</item></style>

修改后:

<style name="ToastStyle" parent="android:Animation">  <item name="android:windowEnterAnimation">@anim/push_fade_in</item>  <item name="android:windowExitAnimation">@anim/push_fade_out</item></style>

問題5

Error:Execution failed for task ':app:javaPreCompileAppDebug'.
Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.
- butterknife-6.1.0.jar (com.jakewharton:butterknife:6.1.0)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

好多的錯誤日志啊,其實最關鍵的只有前兩行:

使用注解編譯庫,需要顯示的聲明,而我正在使用的butterknife是含有注解編譯功能的,但是并沒有聲明。

解決辦法:

android { defaultConfig { // 聲明需要使用注解功能  javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }  ... }}

其他的變化

通過剛才的修改,我的工程已經運行起來了,但是發現了Android Studio 3.0 的幾個小變化。

變化1

Warning:One of the plugins you are using supports Java 8 language features. To try the support built into the Android plugin, remove the following from your build.gradle:
apply plugin: 'me.tatarka.retrolambda'

從警告上看,希望我移除這個插件,于是我到官網上查看了一下信息:

If Android Studio detects that your project is using Jack, Retrolambda, or DexGuard, the IDE uses Java 8 support provided by those tools instead.

如果Android Studio發現你的工程中使用Jack ,Retrolambda 或DexGuard,編輯器會使用Java8支持,替換這個工具。
因為我使用me.tatarka.retrolambda第三方框架,所以就出現了這個,我們只要刪除相關的配置就可以了。

變化2

提示有更高版本你的第三方框架:

Android,Studio,3.0變化,3.0

上面的截圖顯示,gson有更高的版本2.8.3,提示我升級gson。這就省去了我們去github上查看是否版本更新的時間,非常的方便。

總結

這就是我今天遇到的問題及解決方案,如果之前有更多問題再補充。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 革吉县| 调兵山市| 永和县| 木兰县| 库尔勒市| 马公市| 南川市| 元氏县| 武胜县| 临夏县| 明溪县| 阳新县| 兴义市| 盐城市| 开平市| 郴州市| 泰宁县| 宝清县| 栾城县| 岗巴县| 临沂市| 岗巴县| 罗城| 正定县| 焦作市| 哈密市| 齐河县| 中宁县| 丰原市| 东乌珠穆沁旗| 靖州| 五常市| 阳城县| 塔河县| 克东县| 易门县| 双江| 婺源县| 绵阳市| 玉田县| 天津市|