本篇內容介紹了“AndroidStudio項目適配AndroidX(Android9.0)的方法教程”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
成都創新互聯公司專注為客戶提供全方位的互聯網綜合服務,包含不限于成都網站設計、成都網站制作、孟州網絡推廣、微信小程序、孟州網絡營銷、孟州企業策劃、孟州品牌公關、搜索引擎seo、人物專訪、企業宣傳片、企業代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;成都創新互聯公司為所有大學生創業者提供孟州建站搭建服務,24小時服務熱線:18982081108,官方網址:m.newbst.com
說在前面:
老項目、大項目適配Android X 注意了,一定要謹慎、謹慎、再謹慎。項目中用到的第三方庫多的話會很麻煩,有些第三方庫還沒有適配Android X。
適配Android X的兩種情況:一種是老項目適配Android X ,另外一種是新項目要求適配Android 9.0
硬核要求
Android studio 版本升級到3.2.0 以上的版本,distributionUrl的版本升級為 4.10.1以上targetSdkVersion 28gradle 插件的版本升級為 3.2.0以上
classpath 'com.android.tools.build:gradle:3.2.0'
這里以AS 3.4為例
第一步:
新項目,這步可以跳過。
compileSdkVersion 28 defaultConfig { applicationId "gangqing.pu.xmxidaq" minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }
第二步:
// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.4.0' classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0' // NOTE: Do not place your application dependencies here; they belong // in the inpidual module build.gradle files }}allprojects { repositories { google() jcenter() maven { url "https://jitpack.io" } }}task clean(type: Delete) { delete rootProject.buildDir}
第三步:
在gradle.properties 中加入如下代碼,表示支持Android X
android.useAndroidX=trueandroid.enableJetifier=true
第四步:
Android Studio ----> Refactor----> Migrate to androidx,,一鍵轉為 androidX
第五步:
支持Java 1.8
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
第六步:
修改布局,比如:ConstraintLayout
<android.support.constraint.ConstraintLayout<androidx.constraintlayout.widget.ConstraintLayout
注意:如果是老項目適配AndroidX,沒有找到ConstraintLayout 的話,那么還需要在中添加如下代碼
dependencies { implementation 'androidx.constraintlayout:constraintlayout:1.1.3'}
第四步之后,<android.support.constraint.ConstraintLayout變為<androidx.constraintlayout.ConstraintLayout 這時你需要修改為<androidx.constraintlayout.widget.ConstraintLayout |
“AndroidStudio項目適配AndroidX(Android9.0)的方法教程”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注創新互聯網站,小編將為大家輸出更多高質量的實用文章!
新聞名稱:AndroidStudio項目適配AndroidX(Android9.0)的方法教程
當前路徑:http://m.newbst.com/article26/jespcg.html
成都網站建設公司_創新互聯,為您提供做網站、定制開發、云服務器、外貿網站建設、自適應網站、建站公司
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯