《第一行代码》第三版关于kotlin-android-extensions插件的替换和viewbinding踩的坑

起猛了,看见写《第一行代码》的作者在线破防 点我看郭霖大佬在线破防 ,《第一行代码》第三版全文大面积引用了kotlin-android-extensions插件,但是我实际引入的时候发现android studio已经没有默认引入了,于是我只能上csdn找原因,结果就看到了郭霖大佬在线破防
在这里插入图片描述
并且在文中还给出了一个新的解决方案,用谷歌推荐的viwebinding来做出替代,结果在引用的时候发现一大片报错
在这里插入图片描述
一查(这里没有看郭霖大佬的博文)发现需要引入插件
在这里插入图片描述
好家伙,那就引入吧,结果问题又来了,构建时又报错
在这里插入图片描述
结果这个时候才开始查原因,哦是因为viewbinding在后面的版本被整合到buildFeatures 选项中(ps:这点郭霖大佬一开始就写了,但是我没注意看)站内解决方案
郭霖大佬写的
因此我们要记住,改动的时候要在app中的gradle增加

android {
    ...
    buildFeatures {
        viewBinding true
    }
}

安卓报错Could not resolve all files for configuration ':gst_doctor:debugRuntimeClasspath'. > Failed to transform kotlin-android-extensions-1.8.20.jar (org.jetbrains.kotlin:kotlin-android-extensions:1.8.20) to match attributes {artifactType=enumerated-runtime-classes, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}. > Execution failed for JetifyTransform: C:\Users\admin\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-android-extensions\1.8.20\6f25b7cf95167fbf487125a71758de4c0aa15da2\kotlin-android-extensions-1.8.20.jar. > Failed to transform 'C:\Users\admin\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-android-extensions\1.8.20\6f25b7cf95167fbf487125a71758de4c0aa15da2\kotlin-android-extensions-1.8.20.jar' using Jetifier. Reason: AmbiguousStringJetifierException, message: The given artifact contains a string literal with a package reference 'android.support.v4' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.. (Run with --stacktrace for more details.) This is a known exception, and Jetifier won't be able to jetify this library. Suggestions: - If you believe this library doesn't need to be jetified (e.g., if it already supports AndroidX, or if it doesn't use support libraries/AndroidX at all), add android.jetifier.blacklist = {comma-separated list of regular expressions (or simply names) of the libraries that you don't want to be jetified} to the gradle.properties file. - If you believe this library needs to be jetified (e.g., if it uses old support libraries and breaks your app if it isn't jetified), contact the library's authors to update this library to support AndroidX and use the supported version once it is released.
最新发布
04-01
failed The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin. :app:mergeDebugResources :app:mapDebugSourceSetPaths :app:checkDebugAarMetadata :app:processDebugMainManifest :app:javaPreCompileDebug :app:mergeDebugAssets :app:checkDebugDuplicateClasses :app:mergeDebugNativeLibs :app:dataBindingMergeDependencyArtifactsDebug :JetpackMvvm:compileDebugKotlin :JetpackMvvm:bundleLibRuntimeToJarDebug org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'. org.gradle.api.internal.artifacts.transform.TransformException: Failed to transform agentweb-4.1.3.aar (com.just.agentweb:agentweb:4.1.3) to match attributes {artifactType=android-res, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}. org.gradle.internal.resolve.ArtifactNotFoundException: Could not find agentweb-4.1.3.aar (com.just.agentweb:agentweb:4.1.3). org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'. org.gradle.api.internal.artifacts.transform.TransformException: Failed to transform agentweb-4.1.3.aar (com.just.agentweb:agentweb:4.1.3) to match attributes {artifactType=android-res, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}. org.gradle.internal.resolve.ArtifactNotFoundException: Could not find agentweb-4.1.3.aar (com.just.agentweb:agentweb:4.1.3). org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspa
03-14
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值