风声云起之androidx
2019-12-27 本文已影响0人
CarlosLynn
前言
最近代码中依赖版本更新后,需要兼容'androidx.appcompat
从引发了些兼容suppot包的问题.
探索
操作一
我们将依赖更新至implementation 'androidx.appcompat:appcompat:1.1.0'
运行后报错
Manifest merger failed :
Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory)
from [com.android.support:support-compat:28.0.0]
AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.1.0]
AndroidManifest.xml:24:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.
操作二
根据报错信息我们配置AndroidManifest.xml
我们增加tools:replace="android:appComponentFactory"
<application
tools:replace="android:appComponentFactory"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.zxn.mvpdemo.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
在运行后报错
java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
at com.android.builder.core.AndroidBuilder.mergeManifestsForApplication(AndroidBuilder.java:556)
at com.android.build.gradle.tasks.ProcessApplicationManifest.doFullTaskAction(ProcessApplicationManifest.java:198)
操作三
我们继续在清单文件中配置:
android:appComponentFactory=""
再次运行后报错
Static interface methods are only supported starting with Android N (--min-api 24): void butterknife.Unbinder.lambda$static$0()
操作四
我们在app中build.gradle中android 节点下配置
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
结果如下
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
再次运行后报错
Program type already present: androidx.versionedparcelable.CustomVersionedParcelable
操作五
我们进行如下操作
- 1.选择工程右键→Refactor→Migrate to Androidx...
- 2.选中所有需要重命名的目录,执行Do Refactor
再次运行后报错
12/27 12:40:37: Launching 'app' on HUAWEI EML-AL00.
Installation did not succeed.
The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
Installation failed due to: 'null'
操作六
我们删除编译后的缓存
程序发布成功