升级Room引发的惨案!!

kotlin升级

在升级kotlin的时候,直接升级到大版本的kotlin(比如1.7以上),直接报错,只是报错不知道原因。
koltin Release details
后来把koltin版本改成1.6.0,报如下的错,我们才知道gradle是需要先升级的

所以 升级kotlin版本有问题,可以换一个别的kotlin版本试试

gradle升级也是一堆坑,我一开始想升级到比较新的版本7.3.3
Android Gradle 插件版本说明

可以在 Android Studio 的 File > Project Structure > Project 菜单中指定插件版本

但是,升级到最新版本报各种错,而且语法也变了。

7.3.3是gradle的版本,是gradle-wrapper中配置的,7.2.1是gradle的插件版本,这两个得匹配才行,在上面的文章中有对应说明。
gradle插件是配置在这儿的
后来妥协了,只要6.1.1以上就行
gradle是6.3,gradle插件是4.0.1

kotlin 1.6.0 会在kaptGenerateStubDebugKolin卡住

不知道为什么,把kotlin版本换成了1.6.10正常了

gradle 升级过程中有个报错

gradle是6.3,gradle插件是4.0.1

没有这个问题

Caused by: java.lang.RuntimeException: Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :modules:module_push project caused this error: /Users/zhongyili/work/AndroidStudioProjects/sohuvideo_gradle/modules/module_push/libs/vivo_pushSDK_v3.0.0.4_484.aar, /Users/zhongyili/work/AndroidStudioProjects/sohuvideo_gradle/modules/module_push/libs/com.heytap.msp.aar
        at com.android.build.gradle.tasks.BundleAar.getHasLocalAarDeps(BundleAar.kt:61)
        at jdk.internal.reflect.GeneratedMethodAccessor603.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.api.internal.tasks.properties.bean.AbstractNestedRuntimeBeanNode$BeanPropertyValue$1$1.create(AbstractNestedRuntimeBeanNode.java:79)
        at org.gradle.internal.deprecation.DeprecationLogger.whileDisabled(DeprecationLogger.java:225)
        at org.gradle.api.internal.tasks.properties.bean.AbstractNestedRuntimeBeanNode$BeanPropertyValue$1.get(AbstractNestedRuntimeBeanNode.java:75)
        at com.google.common.base.Suppliers$NonSerializableMemoizingSupplier.get(Suppliers.java:167)
        at org.gradle.api.internal.tasks.properties.bean.AbstractNestedRuntimeBeanNode$BeanPropertyValue.call(AbstractNestedRuntimeBeanNode.java:145)
        at org.gradle.api.internal.tasks.properties.AbstractValidatingProperty.validate(AbstractValidatingProperty.java:39)
        at org.gradle.api.internal.tasks.properties.DefaultTaskProperties.validate(DefaultTaskProperties.java:193)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.validate(ExecuteActionsTaskExecuter.java:505)
        at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:50)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.lambda$execute$2(SkipEmptyWorkStep.java:78)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:78)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:34)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:39)
        at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:40)
        at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:28)
        at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:192)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:184)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:114)
        at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
        ... 116 more

这个意思是,library被打成aar包,里面放的aar包不会被打进最终的aar包里面,这个应该是gradle版本不同导致的,之前没升级gradle之前没事。
修改办法,在library中如下修改

-    implementation files('libs/vivo_pushSDK_v3.0.0.4_484.aar')
-    implementation files('libs/com.heytap.msp.aar')
+
+    compileOnly(name: 'vivo_pushSDK_v3.0.0.4_484', ext: 'aar')
+    compileOnly(name: 'com.heytap.msp', ext: 'aar')

把编译方式从implementation变成compileOnly

在工程的build.gradle文件中加入如下代码:

allprojects {
    repositories {
        
        flatDir { dirs '../frameworks/baseAarInfoLib/libs', '../baseAarInfoLib/libs', '../modules/module_push/libs' }
    }
}

其实就是把library中的libs文件夹作为aar包的加载源。

在application module的build.gradle文件中加入如下代码:

    api(name: 'vivo_pushSDK_v3.0.0.4_484', ext: 'aar')
    api(name: 'com.heytap.msp', ext: 'aar')

room升级到2.5.0

升级koltin原因就是升级了room,导致了gradle也升级

通过Android studio build 结果编译的时候一直报错,也看不出什么错
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

得通过下面的命令编译,能看到错误信息

./gradlew assembleDebug --stacktrace
Caused by: java.lang.IllegalArgumentException: Modifiers [PRIVATE] are not allowed on Kotlin parameters. Allowed modifiers: [VARARG, NOINLINE, CROSSINLINE]
        at com.squareup.kotlinpoet.ParameterSpec.(ParameterSpec.kt:41)
        at com.squareup.kotlinpoet.ParameterSpec.(ParameterSpec.kt:29)
        at com.squareup.kotlinpoet.ParameterSpec$Builder.build(ParameterSpec.kt:157)
        at com.squareup.kotlinpoet.FunSpec$Builder.addParameter(FunSpec.kt:500)
        at permissions.dispatcher.processor.impl.kotlin.KotlinBaseProcessorUnit.createPermissionRequestClass(KotlinBaseProcessorUnit.kt:452)
        at permissions.dispatcher.processor.impl.kotlin.KotlinBaseProcessorUnit.createPermissionRequestClasses(KotlinBaseProcessorUnit.kt:415)
        at permissions.dispatcher.processor.impl.kotlin.KotlinBaseProcessorUnit.createFile(KotlinBaseProcessorUnit.kt:43)
        at permissions.dispatcher.processor.impl.kotlin.KotlinBaseProcessorUnit.createFile(KotlinBaseProcessorUnit.kt:17)
        at permissions.dispatcher.processor.PermissionsProcessor.processKotlin(PermissionsProcessor.kt:68)
        at permissions.dispatcher.processor.PermissionsProcessor.process(PermissionsProcessor.kt:58)
        at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt:90)
        at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:188)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:980)
        ... 38 more

通过如下命令能知道依赖关系

 ./gradlew :sohuVideoMobile:dependencies > /Users/zhongyili/Downloads/depen6
kapt
+--- androidx.room:room-compiler:2.5.0
|    +--- androidx.room:room-common:2.5.0
|    |    +--- androidx.annotation:annotation:1.3.0
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20
|    |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20
|    |         |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.7.20
|    |         |    \--- org.jetbrains:annotations:13.0
|    |         \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20
|    |              \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 (*)
|    +--- androidx.room:room-compiler-processing:2.5.0
|    |    +--- com.google.auto:auto-common:0.11
|    |    |    \--- com.google.guava:guava:29.0-jre -> 31.1-jre
|    |    |         +--- com.google.guava:failureaccess:1.0.1
|    |    |         +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|    |    |         +--- com.google.code.findbugs:jsr305:3.0.2
|    |    |         +--- org.checkerframework:checker-qual:3.12.0
|    |    |         +--- com.google.errorprone:error_prone_annotations:2.11.0
|    |    |         \--- com.google.j2objc:j2objc-annotations:1.3
|    |    +--- com.google.auto.value:auto-value-annotations:1.6.3
|    |    +--- com.google.devtools.ksp:symbol-processing-api:1.7.20-1.0.6
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 (*)
|    |    +--- com.google.guava:guava:31.1-jre (*)
|    |    +--- com.intellij:annotations:12.0
|    |    +--- com.squareup:javapoet:1.13.0
|    |    +--- com.squareup:kotlinpoet:1.12.0
|    |    |    +--- org.jetbrains.kotlin:kotlin-reflect:1.7.0
|    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.0 -> 1.7.20 (*)
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.0 -> 1.7.20 (*)
|    |    +--- com.squareup:kotlinpoet-javapoet:1.12.0
|    |    |    +--- com.squareup:kotlinpoet:1.12.0 (*)
|    |    |    +--- com.squareup:javapoet:1.13.0
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.0 -> 1.7.20 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20 (*)
|    |    \--- org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0
|    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.0 -> 1.7.20 (*)
|    +--- androidx.room:room-migration:2.5.0
|    |    +--- androidx.room:room-common:2.5.0 (*)
|    |    +--- com.google.code.gson:gson:2.9.0
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 (*)
|    +--- com.google.auto:auto-common:0.11 (*)
|    +--- com.google.auto.value:auto-value-annotations:1.6.3
|    +--- com.google.devtools.ksp:symbol-processing-api:1.7.20-1.0.6 (*)
|    +--- com.intellij:annotations:12.0
|    +--- com.squareup:javapoet:1.13.0
|    +--- com.squareup:kotlinpoet:1.12.0 (*)
|    +--- com.squareup:kotlinpoet-javapoet:1.12.0 (*)
|    +--- commons-codec:commons-codec:1.15
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 (*)
|    +--- org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0 (*)
|    \--- org.xerial:sqlite-jdbc:3.36.0
+--- com.alibaba:arouter-compiler:1.5.1
|    +--- com.alibaba:arouter-annotation:1.0.6
|    +--- com.squareup:javapoet:1.8.0 -> 1.13.0
|    +--- org.apache.commons:commons-lang3:3.5
|    +--- org.apache.commons:commons-collections4:4.1
|    \--- com.alibaba:fastjson:1.2.48
\--- com.github.permissions-dispatcher:permissionsdispatcher-processor:4.9.2
     +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
     +--- org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0 -> 0.5.0 (*)
     +--- com.squareup:javapoet:1.9.0 -> 1.13.0
     +--- com.squareup:kotlinpoet:1.3.0 -> 1.12.0 (*)
     +--- com.github.permissions-dispatcher:permissionsdispatcher-annotation:4.9.2
     \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.20 -> 1.7.20 (*)

这个不好搞,我把permissionsdispatcher升级到最新版本还是报这个错。我研究了一下com.squareup:kotlinpoet:1.12.0 是androidx.room:room-compiler:2.5.0引用的,这样会把permissionsdispatcher引用的kotlinpoet版本也会从1.3.0变成1.12.0

,然后就报上面的错了。即便,我强制让kotlinpoet是1.3.0版本,room2.5.0又报错了,它得用kotlinpoet1.12.0版本。这两个库使用kotlinpoet的版本有冲突

permissionsdispatcher升级折腾了几小时,包名进行了改变

妈蛋,解决不了了

可能是room版本太新,降低到2.4.3

把room版本降低到2.4.3,library aar包的问题和permissionsdispatcher的问题都没有了。

最终的配置是:
gradle是6.3,gradle插件是4.0.1,kotlin 1.6.10,room 2.4.3

太难了,折腾了我三四天

你可能感兴趣的:(Android,android,android,studio,gradle)