一個做iOS開發(fā)的為什么要做Android適配?
Android兄弟離職一段時間了,公司的三個項目還未對Android新版本進行適配,在AndroidQ上運行會閃退。同屬我司移動端,這個任務(wù)自然就交給我先處理了。
適配筆記
修改gradle版本為3.4.1或更高版本
在項目的build.gradle/allprojects/repositories中添加
maven { url 'https://maven.google.com'}
build.gradle的compileSdkVersion、targetSdkVersion、buildToolsVersion的配置,都設(shè)置為29
當(dāng)前項目的 gradle.properties添加
android.useAndroidX=true
android.enableJetifier=true
遇到錯誤及解決方法
Cannot set the value of read-only property ‘outputFile’ for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=appchinaDebug, filters=[], versionCode=1, versionName=1.0.0}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = “xxx-${defaultConfig.versionName}-${variant.productFlavors[0].name}.apk”
}
ERROR: Cannot choose between the following variants of project :viewlib:
1.在project的build.gradle中刪除
classpath ‘com.neenbedankt.gradle.plugins:android-apt:x.x’
2.在module的build.gradle中刪除
apply plugin: ‘a(chǎn)ndroid-apt’
3.將module的build.gradle文件中的dependency
apt ‘com.jakewharton:butterknife-compiler:x.x.x’改為
annotationProcessor ‘com.jakewharton:butterknife-compiler:x.x.x’ }
ERROR: All flavors must now belong to a named flavor dimension
在versionName后邊加上flavorDimensions “versionCode”
Could not get unknown property ‘bootClasspath’ for object of type
去掉apply plugin: ‘me.tatarka.retrolambda’和classpath ‘me.tatarka:gradle-retrolambda:x.x.x’
Error inflating class me.imid.swipebacklayout.lib.SwipeBackLayout
升級swipebacklayout版本
程序包android.support.annotation不存在
implementation ‘a(chǎn)ndroidx.annotation:annotation:1.1.0’
在代碼中將相關(guān)引用改為
import androidx.annotation.xxx;
SpringAnimation動畫
implementation ‘a(chǎn)ndroidx.dynamicanimation:dynamicanimation:1.0.0’
import androidx.dynamicanimation.animation.SpringAnimation;
The given artifact contains a string literal with a package reference ‘a(chǎn)ndroid.support.v4.content’ that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.
dependencies {
implementation ‘com.jakewharton:butterknife:10.0.0’
annotationProcessor ‘com.jakewharton:butterknife-compiler:10.0.0’
}
ContactFragment無法轉(zhuǎn)換為Fragment
將代碼中g(shù)etSupportFragmentManager()方法改為android.app.Fragment對應(yīng)的getFragmentManager()
Didn’t find class “androidx.constraintlayout.ConstraintLayout” on path
implementation ‘a(chǎn)ndroidx.constraintlayout:constraintlayout:1.1.3’
用androidx.constraintlayout.widget.ConstraintLayout替換androidx.constraintlayout.ConstraintLayout
Error inflating class android.support.v7.widget.CardView
將android.support.v7.widget.CardView替換成androidx.cardview.widget.CardView
使用swipebacklayout在AndroidQ中有殘影

if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.Q) {
setSwipeBackEnable(false);
}
glide加載網(wǎng)絡(luò)圖片,在9.0以上機器不顯示圖片
在AndroidManifest.xml文件里, application字段里 加入 android:usesCleartextTraffic="true"