美文网首页
风声云起之androidx

风声云起之androidx

作者: CarlosLynn | 来源:发表于2019-12-27 13:08 被阅读0次

前言

最近代码中依赖版本更新后,需要兼容'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'

操作六

我们删除编译后的缓存
程序发布成功

兼容androidx需要做如何下操作五才是关键之举.

相关文章

  • 风声云起之androidx

    前言 最近代码中依赖版本更新后,需要兼容'androidx.appcompat从引发了些兼容suppot包的问题....

  • Jetpack插件化学习之AndroidX--Android项目

    Jetpack插件化学习之AndroidX--Android项目升级到AndroidX 注:文章内容翻译自官方文档...

  • 所谓爱的108种颜色(055)

    望之,云之上 触之,风之间 谈笑风声,且看 风起云涌 终是了, 风归去,云消散 但曾相见,又岂是了了

  • 你听风声,我看云起

    两个人在一起最好的状态是什么样的?我想每个人都有每个人的答案吧。我们都会按照自己心中的那个答案去寻找和相处,...

  • 且听风声起

    我需要人陪,而你刚好愿意陪我。 这已经是世界上最了不起的默契。 我庆幸相逢一场,今夜的酒喝光,也只为你一个人醉。 ...

  • 风声既起

    风声既起

  • 风声又起

    突然间发现疫情又风起云涌。 封控高风险小区29个,中风险6个。整个一个星星之火可以燎原之势。 今天晚上本来有菲律宾...

  • 每日对联练习

    山高先得月 水远欲连天【莫之】 云卷千峰色 花开半岭香【莫之】 云晴当槛碧 烟远笼峰青【莫之】 日影飞花殿 风声落...

  • Android 2018大事记

    Android P发布 AndroidX 5月9号发布AndroidX。AndroidX,用来替换Support库...

  • ComponentActivity

    androidx.activity.ComponentActivityextends androidx.core....

网友评论

      本文标题:风声云起之androidx

      本文链接:https://www.haomeiwen.com/subject/tzfdoctx.html