更新android studio gradle插件会破坏旧的API版本

0x6upsns  于 2022-12-09  发布在  Android
关注(0)|答案(1)|浏览(133)

对于依赖项更新,我必须将我的android studio gradle插件更新到7.3.1或更高版本。
我已更新

classpath 'com.android.tools.build:gradle:7.0.4' -> 
classpath 'com.android.tools.build:gradle:7.3.1'

distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip ->
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip

在不更改任何其他代码的情况下,执行此操作后,应用程序在Android API版本24上开始崩溃,原因是

uncaughtException
    java.lang.NoClassDefFoundError: java.time.Instant
        at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
        at java.lang.Class.getDexCacheType(Class.java:2551)
        at java.lang.reflect.Method.getReturnType(Method.java:150)
        at java.lang.Class.getDeclaredMethods(Class.java:1811)
        at java.io.ObjectStreamClass.computeDefaultSUID(ObjectStreamClass.java:1684)
        at java.io.ObjectStreamClass.-wrap8(ObjectStreamClass.java)
        at java.io.ObjectStreamClass$1.run(ObjectStreamClass.java:239)
        at java.io.ObjectStreamClass$1.run(ObjectStreamClass.java:238)
        at java.security.AccessController.doPrivileged(AccessController.java:41)
        at java.io.ObjectStreamClass.getSerialVersionUID(ObjectStreamClass.java:236)
        at java.io.ObjectStreamClass.writeNonProxy(ObjectStreamClass.java:711)
        at java.io.ObjectOutputStream.writeClassDescriptor(ObjectOutputStream.java:680)
        at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1322)
        at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1271)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1467)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1218)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1584)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1549)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1472)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1218)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1584)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1549)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1472)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1218)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1584)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1549)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1472)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1218)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
        at android.os.Parcel.writeSerializable(Parcel.java:1521)
        at android.os.Parcel.writeValue(Parcel.java:1474)
        at android.os.Parcel.writeArrayMapInternal(Parcel.java:723)
        at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408)
        at android.os.Bundle.writeToParcel(Bundle.java:1133)
        at android.os.Parcel.writeBundle(Parcel.java:763)
        at android.content.Intent.writeToParcel(Intent.java:8655)
        at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3052)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)
        at android.app.Activity.startActivityForResult(Activity.java:4224)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:2)
        at androidx.core.app.a.i(ActivityCompat.java:1)
        at androidx.activity.ComponentActivity$b.f(ComponentActivity.java:166)
        at androidx.activity.result.ActivityResultRegistry$a.b(ActivityResultRegistry.java:35)
        at androidx.activity.result.ActivityResultLauncher.a(ActivityResultLauncher.java:2)

在time.javaAGP更新后,对像www.example.com这样的API V26库的去糖似乎不能正常工作。作为参考,我打开了coreLibraryDesugaringEnabled

compileOptions {

    coreLibraryDesugaringEnabled true
    sourceCompatibility = javaVersion
    targetCompatibility = javaVersion
}

我在

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

进一步更新也不能解决这个问题。有什么建议可以解决这个问题吗?

m2xkgtsf

m2xkgtsf1#

您的意思是进一步升级desugaring库或进一步升级Android gradle插件不起作用吗?如果您是指gradle插件,那么我建议尝试将desugaring库升级到1.2.0,这可能会有所帮助。
文档中说1.2.0版本的脱糖库需要min7.3.1 android gradle插件,所以更新的脱糖库版本可能会有所帮助。

相关问题